Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Control Processes with Queueable Apex from (module - Asynchronous Apex)
- -------------------------------------------------
- SOURCE CODE1: AddPrimaryContact
- 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;
- }} }
- -------------------------------------------------
- SOURCE CODE2: AddPrimaryContactTest
- @isTest
- public class AddPrimaryContactTest {
- @isTest static void TestList()
- {
- List<Account> Teste = new List <Account>();
- for(Integer i=0;i<50;i++)
- {
- Teste.add(new Account(BillingState = 'CA', name = 'Test'+i));
- }
- for(Integer j=0;j<50;j++)
- {
- Teste.add(new Account(BillingState = 'NY', name = 'Test'+j));
- }
- insert Teste;
- Contact co = new Contact();
- co.FirstName='demo';
- co.LastName ='demo';
- insert co;
- String state = 'CA';
- AddPrimaryContact apc = new AddPrimaryContact(co, state);
- Test.startTest();
- System.enqueueJob(apc);
- Test.stopTest();
- } }
Add Comment
Please, Sign In to add comment