Skip to main content
Yeturu Srikanth (bigworks) a posé une question dans #Apex
code 

public class AddPrimaryContact implements Queueable {

    

    private Contact s;

    private String State;

    

    public AddPrimaryContact(Contact s, String State) {

        this.s = s;

        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> con = new List<Contact>();

          for(Account acc: ListAccount)

          {

          

          Contact cont = s.clone(false,false,false,false);

               cont.AccountId =  acc.id;

                 con.add( cont );

          

          }

        insert con;

   

    }

}

what to wrire here in anonymous block ..?

AddPrimaryContact obi = new AddPrimaryContact(s,usa);

Database.executeBatch(obj);

 
3 réponses
  1. 21 mai 2020, 15:14
    yes, you need to also create the contact and the state, for example

    System.enqueueJob(new AddPrimaryContact(new Contact(LastName='test'),'usa'));

    if it helps please like or mark as correct, it may help others
0/9000