- Install all of the classes here
- Adjust the tests if you need to.
- Deploy to production
- Use the apex schedule to schedule the CampaignMemberTouch job.
Last active
December 16, 2015 17:09
-
-
Save kevinohara80/5467922 to your computer and use it in GitHub Desktop.
Schedulable batch trigger invoke class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class CampaignMemberTouch implements Schedulable{ | |
global void execute(SchedulableContext SC) { | |
// kick off the batch with a size of 2 for the batch size | |
InvokeTriggerBatch.invoke('SELECT Id FROM CampaignMember', 5); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class InvokeUpdateTriggerBatch implements Database.Batchable<sObject> { | |
private String query; | |
global InvokeUpdateTriggerBatch(String query) { | |
this.query = query; | |
} | |
global Database.QueryLocator start(Database.BatchableContext BC){ | |
return Database.getQueryLocator(this.query); | |
} | |
global void execute(Database.BatchableContext BC, List<sObject> scope){ | |
update scope; | |
} | |
global void finish(Database.BatchableContext BC){ | |
System.debug('Batch Process Complete'); | |
} | |
// utility static method to kick off a batch in one line. | |
global static String invoke(String query, Integer batchSize) { | |
InvokeUpdateTriggerBatch batch = new InvokeUpdateTriggerBatch(query); | |
return Database.executeBatch(batch, batchSize); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
private class InvokeUpdateTriggerBatch_Test { | |
static testmethod void testBatch() { | |
List<Lead> leads = new List<Lead>(); | |
for(Integer i=0; i<100; i++) { | |
// adjust this test if you have additional validation | |
// rules or other things that might make this fail. | |
Lead l = new Lead(); | |
l.FirstName = 'Test' + String.valueof(i); | |
l.LastName = 'Test' + String.valueof(i); | |
l.Email = 'test' + String.valueof(i) + '@test.com'; | |
l.Company = 'Blah Company'; | |
leads.add(l); | |
} | |
insert leads; | |
Test.startTest(); | |
String batchId = InvokeUpdateTriggerBatch.invoke('SELECT Id FROM Lead'); | |
Test.stopTest(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment