New answers tagged

0

Does the batch job rolls back the DML operations of a chunk if an error is encountered? Yes. If an unhandled exception occurs, all work done in the execute method will be rolled back. This is the same behavior you'd see in a trigger, future method, queueable, etc. Never allow an exception to be thrown to the top unless you want to abort the transaction ...


0

Salesforce lets you check record access via apex. Some good discussion is here but do check source docs as well Can I find out if the current user has access to a record without querying?


1

I would do something like this: { List<Messaging.SingleEmailMessage> allMails = new List<Messaging.SingleEmailMessage>(); Set<Id> accountIdSet = new Set<Id>(); for(Account obj : updateAsDuplicate){ obj.Duplicate__c = true; accountIdSet.add(obj.Id); for(String oldStr : hasExternalIdOldSet){ ...


0

sendEmail in a loop is a sin. //Prepare a list of all your emails and invoke sendEmail once List<Messaging.SingleEmailMessage> messages= new List<Messaging.SingleEmailMessage>(); for(...) { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); // Set mail parameters messages.add(mail); } Messaging.sendEmail(messages); I ...


1

The issue is that, with a large enough batch size, you will exceed the SOQL query limit because you are executing a query inside of a for-loop inside execute(): for (Patch_Panel__c p : param2) { PatchPanelTriggerClass.deleteDuplicates(p.Name); List<Interface__c> records = [ SELECT Name, Id, Status__c, Port_No__c, Rack__c, ...


4

You should not be calling the deleteDuplicates method from within the for loop. for (Patch_Panel__c p : param2) { PatchPanelTriggerClass.deleteDuplicates(p.Name); // Class.PatchPanelTriggerClassTestBatch.execute: line 19, column 1 I suggest you either change the calling code or else accept the collection in deleteDuplicates and modify the SOQL to use ...


2

You can't have the line update D365Obj_Data[0]; before the callout. That opens a transaction that then will preclude you (as you saw) from making the callout. What you do is simply hold the values in memory, and only do the DML after the line HttpResponse res1 = http1.send(req1);, ideally outside the try-catch, so you can save the changes regardless of ...


Top 50 recent answers are included