I have created a trigger on campaign member. Trigger gets 66% code coverage in sandbox and 0% in production. I know there's a million threads on this but none have solved my dilemma. Here is my trigger code:
trigger campaignMemberTrigger on CampaignMember (after insert, before update){
private static boolean firstRun = true;
cmpnMemberTriggerHandler handler = new cmpnMemberTriggerHandler();
try{
if(firstRun){
firstRun = false;
handler.execute();
}
}catch(exception e){
system.debug('Error during campaignMemberTrigger: '+e.getMessage());
for(campaignMember mem :(List<CampaignMember>)Trigger.new){
mem.addError('Unable to process transaction, please try again or contact your administrator if you need assistance ');
}
}
}
Here is my test code:
@isTest
public class campaignMemberTriggerTests {
public static testMethod void unsyncWithMarketoTest(){
//create test data
Campaign cm = new campaign(name = 'Pardot - Q317 - Marketplace Outbound Drip Campaign');
insert cm;
Lead ld = new Lead(status = 'Open', leadSource = 'Marketplace Upsell', lastName = 'Nila', state = 'IN', numberOfEmployees = 300, company = 'wois', email = 'adamnila@hobolala.com');
insert ld;
//that we have our test lead and campaign, we will create a new campaign member and see if the lead updates
CampaignMember cmm = new campaignMember(campaignId = cm.id, leadid = ld.id);
//time for our test
test.startTest();
insert cmm;
test.stopTest();
//verify that our code ran
system.assertEquals(1, [SELECT count() FROM Lead WHERE dont_sync_with_marketo__c = true]);
system.assertEquals(1, [SELECT count() FROM CampaignMember]);
}
public static testMethod void unsyncWithMarketoNegTest(){
List<Lead> lds = new List<Lead>();
Lead ld = new Lead(company = 'Failure');
lds.add(ld);
cmpMemDontSyncWithMarketo dsm = new cmpMemDontSyncWithMarketo();
dsm.unsyncFromMarketo(lds);
}
}
I cannot run all tests in production currently(long story, I just got here and it's a mess inside) so I need this class to succeed but I can't see any reason inserting a campaign member wouldn't run the trigger?