-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobjectCreate.cls
60 lines (55 loc) · 1.63 KB
/
objectCreate.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public class objectCreate {
public static void test()
{
List<Account> accList = new List<Account>();
for(Integer i=0;i<5;i++)
{
Account acc = new Account();
acc.Name = 'Test account'+i;
acc.Phone = '123456789';
accList.add(acc);
}
System.debug('accList'+accList);
//govern limit
if(!accList.isEmpty()){
//(accList.size() > 0)
Insert accList;
}
}
//insert
public static void addContact(){
List<Account> accountList = new List<Account>();
accountList = [select Id,Name from Account where Name Like '%Test Account%' LIMIT 5];
//refrence
List<Contact> conList = new List<Contact>();
for(Account acc: accountList){
Contact con = new Contact();
con.LastName = 'test contact';
con.AccountId = acc.Id;
conList.add(con);
}
if(!accountList.isEmpty()){
Insert conList;
}
}
//update
public static void updateAcc(){
List<Account> accountList = new List<Account>();
accountList = [select Id,Name from Account where Name Like '%test%'];
for(Account acc: accountList){
acc.Name = 'Alpha.'+ acc.Name;
}
if(!accountList.isEmpty())
{
Update accountList;
}
}
//delete
public static void deleteAcc(){
Account acc = new Account();
acc = [Select Id, Name From Account Where Name Like '%a%' LIMIT 5];
if( acc.Id != null){
Delete acc;
}
}
}