Skip to content

Instantly share code, notes, and snippets.

@goravseth
Last active March 31, 2017 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goravseth/657621611e5d4d5b2190016ccb14ed80 to your computer and use it in GitHub Desktop.
Save goravseth/657621611e5d4d5b2190016ccb14ed80 to your computer and use it in GitHub Desktop.
/*
will create campaign member records for all contacts and all campaigns
campaign member status will split between sent and responded
this is to for creating test records in developer orgs
it will fail with large numbers of records
*/
List<campaign> cl = new list<campaign>([select id from campaign);
List<contact> conlist = new list <contact>([select id from contact]);
List<campaignMember> cmlist = new list <campaignMember>();
integer counter = 1;
for (Campaign cam : cl){
for (Contact c : conlist){
campaignmember cm = new campaignmember();
cm.contactId = c.id;
cm.campaignId = cam.id;
IF(math.mod(counter,2) == 0){
cm.status = 'responded';
}
ELSE(cm.status='sent');
cmlist.add(cm);
counter += 1;
}
}
insert cmlist;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment