You need to sign in to do that
Don't have an account?

Controlling Processes with Queueable Apex
The solution to this trailhead challenge is inside of the reading of the trailhead material, and the challenge references the LeadProcessor class from the Database.Batchable trailhead challenge which does not apply to this challenge.
Let us know if this will help you
Thanks
Amit Chaudhary
1) https://developer.salesforce.com/forums/ForumsMain?id=906F0000000DBndIAG
Please let us know if this will help you
Used your code. Worked perfectly. Thanks mate!
Hi David Steele,
Please let us know if above solution will helped you or you need more help
@Amit
Thank you for your help. That definitely got me on the right track.
I don't see any assertions in your test class, though. As per the instructions, we must "assert that a Contact record was inserted for each of the 50 Accounts with the BillingState of 'CA'."
My understanding is that count() is only counting the accounts what fit the WHERE condition but there's nothing about the number of contacts with one related to one of these accounts?
Please check the following solution. It works!!!!!I passed the challenge with 100% code coverage and Assert statement passed!!!!!!!!
Class: AddPrimaryContact
public class AddPrimaryContact implements Queueable{
private Contact c;
private String state;
public AddPrimaryContact(Contact contact, String state){
this.c = contact;
this.state = state;
}
public void execute(QueueableContext context){
List<Account> accounts = [Select ID, Name From Account WHERE BillingState =:state LIMIT 200];
List<Contact> contacts = new List<Contact>();
for(Account account: accounts){
Contact con = c.clone(false, false,false, false);
con.AccountId = account.Id;
contacts.add(con);
}
if(contacts.size()>0){
insert contacts;
}
}
}
Test Class: AddPrimaryContactTest
@isTest
public class AddPrimaryContactTest {
static testmethod void testQueueable(){
List<Account> testAccounts = new List<Account>();
for(Integer i=0; i<50; i++){
testAccounts.add(new Account(BillingState = 'NY', name = 'QueueTest ' + i));
}
for(Integer j=0; j<50; j++){
testAccounts.add(new Account(BillingState = 'CA', name = 'QueueTest ' + j));
}
insert testAccounts;
Contact con = new Contact(FirstName = 'Queueable', LastName = 'Apex');
insert con;
AddPrimaryContact primContact = new AddPrimaryContact(con, 'CA');
Test.startTest();
System.enqueueJob(primContact);
Test.stopTest();
System.assertEquals(50, [SELECT count() FROM Contact WHERE accountId IN (Select id from Account WHERE BillingState ='CA')]);
}
}