1

I'm dealing with the CampaignMember standard object, and a custom object called Binding__c. I need to create a new Binding__c record for each CampaignMember record, and there might be 25K of those -- so I'm setting up Batch Apex to handle it.

The initial query in the start() method will be on the CampaignMember object.

The execute method will create a new Binding__c record with the CampaignMemberId, then insert the record.

My question is, in the class declaration, do I use the SObject I'm querying and iterating through, or the SObject I'm creating and inserting?

global class BindingBatchCreate implements Database.Batchable<CampaignMember> {

or

global class BindingBatchCreate implements Database.Batchable<Binding__c> {

I think it should be the CampaignMember, as this is what I'm iterating.

For the corresponding BindingBatchUpdate and BindingBatchDelete, I'll be iterating the Binding__c, so that's obvious.

2

You iterate over the object returned by your query. If you have a QueryLocator which iterates CampaignMember, you build a Database.Batchable<CampaignMember>.

| improve this answer | |
1

It would be records(Iterable) or query-locator for sObject you are returning from start method. In you case it will implements Database.Batchable<CampaignMember> {

Or if you wanna go more generic go with

implements Database.Batchable<sObject> {

Src: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm

| improve this answer | |
  • thanks. I'm on that doc page. I confused myself because for my other two batch classes (to update and delete the Binding__c) the iterable is Binding__c. – PatMcClellan__c Feb 18 '19 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.