You are currently viewing Salesforce Developer Interview Questions Part14 – Scheduled Apex Continue

Salesforce Developer Interview Questions Part14 – Scheduled Apex Continue

Salesforce Developer Interview Questions – Asynchronous Apex – Scheduled Apex Continue

Scheduled Apex Continue

144. Can you write some examples of how to use the expressions or CORN_EXP?

Answer

ExpressionDescription
0 0 13 * * ?Class runs every day at 1 PM
0 0 22 ? * 6LClass runs the last Friday of every month at 10 PM.
0 0 10 ? * MON-FRIClass runs Monday through Friday at 10 AM.
0 0 20 * * ? 2010Class runs every day at 8 PM during the year 2010.

145. Which all types of classes or asynchronous processes we can schedule?

Answer

We can schedule all of them like

  1. Batch Apex – We can call a batch class from scheduled apex
  2. Future method – We can call future method from scheduled apex
  3. Queueable apex – we can call a queueable apex from scheduled apex.

146. Among Batch apex, Future method and Queueable apex , which one can cause issues if we schedule them?

Answer

If we call future methods from scheduled apex then it can cause some issues.

Because the future method does not guarantee its execution on time. So, tracking is not possible as we lose transaction control as scheduled apex gets over as soon as it fires the future method.

There is a limit to the number of future calls based on the number of licenses of our org.

147. Can you update the class or any classes referenced in a scheduled job?

Answer

If there are one or more active scheduled jobs for an apex class, we cannot update the class or any classes referenced by the apex class though the salesforce user interface (like updating the apex class within the salesforce UI).

However, you can update the class in the sandbox and deploy the class in production with active scheduled job by using metadata API

148. What is the maximum number of jobs that can be scheduled at a given time?

Answer

We can only have 100 scheduled apex jobs at a time.

149. How to count the number of scheduled jobs ?

Answer

SELECT COUNT() FROM CronTrigger where CronJobDetails.JobType = ‘7’

Here CronJobDetails.JobType = ‘7’ represents scheduled apex

150. Does scheduled apex support Callout?

Answer

No, Scheduled apex does not support synchronous web service callouts.

151. If callout is not supported in scheduled apex then what is the alternate way to callout from scheduled apex?

Answer

There are two ways to callout from scheduled apex. We should make asynchronous callouts

  1. Using future method : user future method with callout like @future(callout=true) and call this method from scheduled apex.
  2. Create a batch apex with callouts (callouts are supported in batch apex) and create a scheduled apex which executes the batch job.

152. Can you tell me about some best practices for scheduled apex?

Answer

  • If we are planning to schedule a class from a trigger. We must be able to guarantee that the triggers won’t add more scheduled classes than the limit.
  • Though it’s possible to do additional processing in the execute method, we recommend that all processing take place in a separate class.
  • Synchronous web service callouts are not supported from scheduled apex, to make asynchronous callouts use @feature or Batch apex.

This Post Has One Comment

  1. Sheela N

    Thanks sir for initiating this blog. This has helped me in clearing my doubts and has helped me in understanding concepts

Leave a Reply