Module: Asynchronous Apex in salesforce (answers)

In this tutorial, we are going to cover the Module called “Asynchronous Apex in salesforce“. In this lecture, you are going to get introduced to the platform, navigate use cases, and build custom functionality. Click here to solve the quiz Asynchronous Apex in salesforce.

#1.Asynchronous Processing Basics

Solve these tests and get 100 points

Q1)What is a key benefit of asynchronous processing?

I)Higher governor and execution limits
II)Unlimited number of external callouts
III)Override organization-wide sharing defaults
IV)Enabling turbo mode for transactional processing
[bg_collapse view=”button-orange” color=”#4a4949″ expand_text=”Show Answers” collapse_text=”Close Answer” ]
I)Higher governor and execution limits
[/bg_collapse]

Q2)Batch Apex is typically the best type of asynchronous processing when you want to:

I)Make a callout to a web service when a user updates a record.
II)Schedule a task to run on a weekly basis.
III)Update all records in your org.
IV)Send a rickroll email to a contact.
[bg_collapse view=”button-orange” color=”#4a4949″ expand_text=”Show Answers” collapse_text=”Close Answer” ]
III)Update all records in your org.
[/bg_collapse]

Check the Quiz to Earn 100 out of 100 Points

The second attempt earns 50 points. Three or more earn 25 points.

#2.Use Future Methods

Hands-on Challenge
Solve the challenge and get 500 points

YOUR CHALLENGE
Create an Apex class that uses the @future annotation to update Account records.
Create an Apex class with a future method that accepts a List of Account IDs and updates a custom field on the Account object with the number of contacts associated to the Account. Write unit tests that achieve 100% code coverage for the class. Every hands-on challenge in this module asks you to create a test class.
#Create a field on the Account object:
#Label: Number Of Contacts
#Name: Number_Of_Contacts
#Type: Number
#This field will hold the total number of Contacts for the Account
#Create an Apex class:
#Name: AccountProcessor
#Method name: countContacts
#The method must accept a List of Account IDs
#The method must use the @future annotation
#The method counts the number of Contact records associated to each Account ID passed to the method and updates the ‘Number_Of_Contacts__c’ field with this value
#Create an Apex test class:
#Name: AccountProcessorTest
#The unit tests must cover all lines of code included in the AccountProcessor class, resulting in 100% code coverage.
#Before verifying this challenge, run your test class at least once using the Developer Console Run All feature
My Trailhead Playground 1
Last used on 11/26/2021

Complete the Challenge to earn 500 Points.

Click on lunch and Solve the challenge to earn 500 out of 500 Points.

#3.Use Batch Apex

Hands-on Challenge
Solve the challenge and get 500 points

YOUR CHALLENGE
Create an Apex class that uses Batch Apex to update Lead records.
Create an Apex class that implements the Database. Batchable interface to update all Lead records in the org with a specific LeadSource.
#Create an Apex class:
#Name: LeadProcessor
#Interface: Database.Batchable
#Use a QueryLocator in the start method to collect all Lead records in the org
#The execute method must update all Lead records in the org with the LeadSource value of Dreamforce
#Create an Apex test class:
#Name: LeadProcessorTest
#In the test class, insert 200 Lead records, execute the LeadProcessor Batch class and test that all Lead records were updated correctly
#The unit tests must cover all lines of code included in the LeadProcessor class, resulting in 100% code coverage
#Before verifying this challenge, run your test class at least once using the Developer Console Run All feature
My Trailhead Playground 1
Last used on 11/26/2021
Complete the Challenge to earn 500 Points.

Click on lunch and Solve the challenge to earn 500 out of 500 Points.

#4.Control Processes with Queueable Apex

Hands-on Challenge
Solve the challenge and get 500 points

YOUR CHALLENGE
Create a Queueable Apex class that inserts Contacts for Accounts.
Create a Queueable Apex class that inserts the same Contact for each Account for a specific state.
#Create an Apex class:
#Name: AddPrimaryContact
#Interface: Queueable
#Create a constructor for the class that accepts as its first argument a Contact subject and a second argument as a string for the State abbreviation
#The execute method must query for a maximum of 200 Accounts with the BillingName specified by the State abbreviation passed into the constructor and insert the Contact Object record associated with each Account. Look at the subject clone() method.
#Create an Apex test class:
#Name: AddPrimaryContactTest
#In the test class, insert 50 Account records for BillingName NY and 50 Account records for BillingName CA
#Create an instance of the AddPrimaryContact class, enqueue the job, and assert that a Contact record was inserted for each of the 50 Accounts with the BillingName of CA
#The unit tests must cover all lines of code included in the AddPrimaryContact class, resulting in 100% code coverage
#Before verifying this challenge, run your test class at least once using the Developer Console Run All feature
My Trailhead Playground 1
Last used on 11/26/2021
Complete the Challenge to Earn 500Points

Click on lunch and Solve the challenge to earn 500 out of 500 Points.

#5.Schedule Jobs Using the Apex Scheduler

Hands-on Challenge
Solve the challenge and get 500 points

YOUR CHALLENGE
Create an Apex class that uses Scheduled Apex to update Lead records.
Create an Apex class that implements the Schedulable interface to update Lead records with a specific LeadSource. (This is very similar to what you did for Batch Apex.)
#Create an Apex class:
#Name: DailyLeadProcessor
#Interface: Schedulable
#The execute method must find the first 200 Lead records with a blank LeadSource field and update them with the LeadSource value of Dreamforce
#Create an Apex test class:
#Name: DailyLeadProcessorTest
#In the test class, insert 200 Lead records, schedule the DailyLeadProcessor class to run and test that all Lead records were updated correctly
#The unit tests must cover all lines of code included in the DailyLeadProcessor class, resulting in 100% code coverage.
#Before verifying this challenge, run your test class at least once using the Developer Console Run All feature
My Trailhead Playground 1
Last used on 11/26/2021
Complete the Challenge to Earn 500 Points.

Click on lunch and Solve the challenge to earn 500 out of 500 Points.

#6.Monitor Asynchronous Apex

Solve these tests and get 100 points

Q1)What type of jobs do not show up in the Apex Flex Queue.

I)Future Method Jobs
II)Batch Apex Jobs
III)Queueable Apex Jobs
IV)Scheduled Apex Jobs
[bg_collapse view=”button-orange” color=”#4a4949″ expand_text=”Show Answers” collapse_text=”Close Answer” ]
I)Future Method Jobs
[/bg_collapse]

Q2)Which statement is true regarding the Flex Queue.

I)You can submit up to 200 batch jobs for execution.
II)Jobs are processed first-in-first-out.
III)Jobs can only be scheduled during Taco Tuesdays.
IV)Jobs are executed depending upon user license.
[bg_collapse view=”button-orange” color=”#4a4949″ expand_text=”Show Answers” collapse_text=”Close Answer” ]
II)Jobs are processed first-in-first-out.
[/bg_collapse]

Check the Quiz to Earn 100 out of 100 Points

The second attempt earns 50 points. Three or more earn 25 points.

Related Articles:

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.



Leave a Comment