-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInsertContact.cls
30 lines (25 loc) · 958 Bytes
/
InsertContact.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
//Create 10 Contacts with different Account(LookUp) values(Relationship) with no same 2 account in them.
public class InsertContact {
public static void InsertCon(){
List<Account> accList = new List<Account>();
accList = [select id, name from Account LIMIT 20];
list<Contact> listconn = new list<Contact>();
Integer k=0;
for(integer i=1;i<10;++i){
k=k+1;
Contact con = new Contact();
con.LastName = accList.get(k).Name;
con.AccountId = accList.get(k).Id;
listconn.add(con);
}
Insert listconn;
System.debug(listconn);
}
//using sobject demo
public static void insertAcc(){
SObject accountrec = (SObject) Type.forName('Account').newInstance();
accountrec.put('Name', 'Sample Sobject');
accountrec.put('Phone', '123456789');
insert accountrec;
}
}