You need to sign in to do that
Don't have an account?
kaushik Sabapathy
difference between contact c and List<contact>
Hi
Im a new to salesforce. i have some questions regarding single sobject and list of sobject.
in the below code it uses contact cont = c. clone is it for a single contact ??
And what clone method actually does for the below code
public class AddPrimaryContact implements Queueable
{
private Contact c;
private String state;
public AddPrimaryContact(Contact c, String state)
{
this.c = c;
this.state = state;
}
public void execute(QueueableContext context)
{
List<Account> ListAccount = [SELECT ID, Name ,(Select id,FirstName,LastName from contacts ) FROM ACCOUNT WHERE BillingState = :state LIMIT 200];
List<Contact> lstContact = new List<Contact>();
for (Account acc:ListAccount)
{
Contact cont = c.clone(false,false,false,false);
cont.AccountId = acc.id;
lstContact.add( cont );
}
if(lstContact.size() >0 )
{
insert lstContact;
}
}
}
Im a new to salesforce. i have some questions regarding single sobject and list of sobject.
in the below code it uses contact cont = c. clone is it for a single contact ??
And what clone method actually does for the below code
public class AddPrimaryContact implements Queueable
{
private Contact c;
private String state;
public AddPrimaryContact(Contact c, String state)
{
this.c = c;
this.state = state;
}
public void execute(QueueableContext context)
{
List<Account> ListAccount = [SELECT ID, Name ,(Select id,FirstName,LastName from contacts ) FROM ACCOUNT WHERE BillingState = :state LIMIT 200];
List<Contact> lstContact = new List<Contact>();
for (Account acc:ListAccount)
{
Contact cont = c.clone(false,false,false,false);
cont.AccountId = acc.id;
lstContact.add( cont );
}
if(lstContact.size() >0 )
{
insert lstContact;
}
}
}
Your code will work for single contact.
In this code new contact record will be created with totally different sfdc Id .
No related objects will be copied neither autonumber or timesstamps field will be copied.
For more information check: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm#apex_System_SObject_clone
Let me know if this helos you.