Advanced Apex Programming in Salesforce by Appleman Dan
Author:Appleman, Dan [Appleman, Dan]
Language: eng
Format: epub
Publisher: Desaware Publishing
Published: 2018-09-14T16:00:00+00:00
if(textChangedIds.size()>0)
newAsyncRequests.add(new AsyncRequest__c(
AsyncType__c = 'Translate Work Order',
Params__c = string.Join(textChangedIds,',')));
insert newAsyncRequests;
}
The handleTrigger5 function iterates over the work orders, looking at all work orders on insert, and those where the Description has changed on update. It builds a list of the IDs of the work orders that need to be translated, and then joins them into a comma separated string. It breaks up the request into groups of 100, which is the current callout limit. You can’t use the Limits.getLimitCallouts method here because it would return zero (it being a trigger context). Finally, the function creates the necessary AsyncRequest__c objects with an AsyncType__c value of “Translate Work Order”, and inserts them.
The insertion of the AsyncRequest__c objects is detected by a new trigger called OnAsyncRequestInsert, that is defined as follows:
trigger OnAsyncRequestInsert on AsyncRequest__c (after insert)
{
if(Limits.getLimitQueueableJobs() –
Limits.getQueueableJobs() > 0)
try
{
GoingAsync4.enqueueGoingAsync4(null);
} catch(Exception ex)
{
// Ignore for now
}
}
The enqueueGoingAsync4 method is a utility function that actually enqueues the job – you’ll see why we do it that way shortly. This may seem like a lot of effort to queue up a request to process a set of WorkOrder objects to translate. The GoingAsync4 class, that implements the queueable interface, doesn’t get any easier.
The execute method begins with a query for a single AsyncRequest__c object.
public void execute(QueueableContext context)
{
// On/off switch
if(!AppCustomSetting.appEnabled) return;
List<AsyncRequest__c> requests;
try
{
requests = [Select ID, AsyncType__c, Params__c
from AsyncRequest__c
where Error__c = false And
CreatedById = :UserInfo.getUserId()
Limit 1 for update];
}
catch(Exception ex) { return; }
if(requests.size()==0 ) return;
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7775)
Grails in Action by Glen Smith Peter Ledbrook(7693)
Configuring Windows Server Hybrid Advanced Services Exam Ref AZ-801 by Chris Gill(6507)
Azure Containers Explained by Wesley Haakman & Richard Hooper(6486)
Running Windows Containers on AWS by Marcio Morales(6009)
Kotlin in Action by Dmitry Jemerov(5061)
Microsoft 365 Identity and Services Exam Guide MS-100 by Aaron Guilmette(4878)
Combating Crime on the Dark Web by Nearchos Nearchou(4466)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4412)
Microsoft Cybersecurity Architect Exam Ref SC-100 by Dwayne Natwick(4271)
The Ruby Workshop by Akshat Paul Peter Philips Dániel Szabó and Cheyne Wallace(4136)
The Age of Surveillance Capitalism by Shoshana Zuboff(3943)
Python for Security and Networking - Third Edition by José Manuel Ortega(3692)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3503)
The Ultimate Docker Container Book by Schenker Gabriel N.;(3372)
Mastering Python for Networking and Security by José Manuel Ortega(3343)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3327)
Blockchain Basics by Daniel Drescher(3292)
Learn Wireshark by Lisa Bock(3194)
