Skip to content

Instantly share code, notes, and snippets.

@jvolkov
Created June 14, 2022 23:05
Show Gist options
  • Save jvolkov/55a7654c46521ec0ee4cb377c3beee5c to your computer and use it in GitHub Desktop.
Save jvolkov/55a7654c46521ec0ee4cb377c3beee5c to your computer and use it in GitHub Desktop.
create salesforce campaign member statuses
// change the campaign id and status to the correct values
Campaign campaign = [SELECT Id FROM Campaign WHERE Id = 'ENTER THE CAMPAIGN ID' LIMIT 1];
List<CampaignMemberStatus> newStatusesToInsert = new List<CampaignMemberStatus>();
List<String> statuses = new List<String>{'Ideal User', 'MQL', 'Assigned', 'Touched', 'Disqualified', 'Clicked', 'Demoed', 'Opportunity', 'Won'};
for (String status: statuses) {
system.debug(status);
CampaignMemberStatus newStatus = new CampaignMemberStatus ();
newStatus.Label = status;
newStatus.CampaignId = campaign.Id;
newStatus.HasResponded = true;
newStatusesToInsert.add(newStatus);
}
Database.SaveResult[] results = Database.insert(newStatusesToInsert, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment