Can You iterate over multiple queries in batch apex?

Can You iterate over multiple queries in batch apex?

That’s not how Batch Apex works. You can iterate over exactly one query in a Batch Apex job. Because you are mutating three different objects in three different ways, the options of batch chaining and use of Dynamic SOQL don’t really apply here.

How to differentiate between two objects in batch apex?

But it seems to be trowing an error when casting the scope variable to casearticle (Since scope consists of both case records and casearticle records ). Could you please let me know how to differentiate between 2 object records before casting them to respective objects.

How to update a custom field in apex?

In this case, I have a custom object (Customobj__c) that has a trigger on it to update a case with fields from that custom object based on a field that they both have in common. One of the fields I want to update is a multi-select picklist, too (Event_Types__c).

When to update custom objects in apex trigger?

First, it is normally better to update other objects in an “after” trigger. If this runs in the before insert, the OBJ.ID will be null. Also, the way this is currently written, you will only get the last updated/inserted custom object to work correctly. You’ll need to “bulkify” this to work for the whole list of custom objects.

How to create multiple batch classes in Salesforce?

Because you are mutating three different objects in three different ways, the options of batch chaining and use of Dynamic SOQL don’t really apply here. You’ll simply need to build three different batch classes. You can run these classes in parallel, or have each one chain into the next in its finish () method.

Can you query multiple objects in one batch?

Hi Shweta , Looking for the same business requirement ..? yes Vamsi, I have similar requirement where I have to Query multiple objects in a single batch. Those objects are not related. I was cecking this example but getting same error.