function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vila Shah 16Vila Shah 16 

How to write a Test Class for code - Capture Campaign Member History ( https://help.salesforce.com/articleView?id=000182237&type=1)

How to write a Test Class for Capture Campaign Member History code - link: ( https://help.salesforce.com/articleView?id=000182237&type=1) to bring trigger from Sandbox to production?
Best Answer chosen by Vila Shah 16
Raj VakatiRaj Vakati
try this 
 
@isTest
private class CampaignMemberInsertTest {
   private static testMethod void testUpdateCM() {
     

    Test.startTest();
    Account acct = new Account (Name = 'Acme, Inc.');
    insert acct;
    system.debug('Inserted Account, ID: ' + acct.id);

    Contact con = new Contact(
                      FirstName = 'Robin',
                      LastName = 'Koehler',
                      AccountId = acct.Id
                      );
    insert con;   
	
	
	Contact con1 = new Contact(
                      FirstName = 'Robin',
                      LastName = 'Koehler',
                      AccountId = acct.Id
                      );
    insert con1;  
    
    Campaign camp = new Campaign(
                        Name = 'Test',
                        IsActive = TRUE
                        );            
    insert camp;
	
	
	 Campaign camp1 = new Campaign(
                        Name = 'Test',
                        IsActive = TRUE
                        );            
    insert camp1;
 
    CampaignMember member = new CampaignMember(
        ContactId = con.Id,
        Status = 'sent',
        CampaignId = camp.Id
        ); 
    insert member; 
   

    CampaignMember member1 = new CampaignMember(
        ContactId = con1.Id,
        Status = 'sent',
        CampaignId = camp1.Id
        ); 
    insert member1; 
   member1.Status = 'responded';
   update member1 ; 
   
   member.Status = 'responded';
   update member ; 
   
   delete mebmer ;
   
Test.stopTest();           
 
    }
}

 

All Answers

Raj VakatiRaj Vakati
try this 
 
@isTest
private class CampaignMemberInsertTest {
   private static testMethod void testUpdateCM() {
     

    Test.startTest();
    Account acct = new Account (Name = 'Acme, Inc.');
    insert acct;
    system.debug('Inserted Account, ID: ' + acct.id);

    Contact con = new Contact(
                      FirstName = 'Robin',
                      LastName = 'Koehler',
                      AccountId = acct.Id
                      );
    insert con;   
	
	
	Contact con1 = new Contact(
                      FirstName = 'Robin',
                      LastName = 'Koehler',
                      AccountId = acct.Id
                      );
    insert con1;  
    
    Campaign camp = new Campaign(
                        Name = 'Test',
                        IsActive = TRUE
                        );            
    insert camp;
	
	
	 Campaign camp1 = new Campaign(
                        Name = 'Test',
                        IsActive = TRUE
                        );            
    insert camp1;
 
    CampaignMember member = new CampaignMember(
        ContactId = con.Id,
        Status = 'sent',
        CampaignId = camp.Id
        ); 
    insert member; 
   

    CampaignMember member1 = new CampaignMember(
        ContactId = con1.Id,
        Status = 'sent',
        CampaignId = camp1.Id
        ); 
    insert member1; 
   member1.Status = 'responded';
   update member1 ; 
   
   member.Status = 'responded';
   update member ; 
   
   delete mebmer ;
   
Test.stopTest();           
 
    }
}

 
This was selected as the best answer
Vila Shah 16Vila Shah 16
Thank you so much for quick response. I have added test class and bring it over to production. It is still showing

Code Coverage Failure Your organization's code coverage is 73%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
Code Coverage Failure Your organization's code coverage is 73%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
ActivationQuestionTrigger
RFxProposalRequestcStats
ActivationPrepTrigger

Those triggers are already created before. I haven't touch them. Let me know what I should do?
Raj VakatiRaj Vakati
While deploying use RunOnlySpecific test class and give the CampaignMemberInsertTest  test class and try so that it will not run all the  test classes 
Vila Shah 16Vila Shah 16
Thanks a lot...It worked! Amazing ...Great help.
Vila Shah 16Vila Shah 16
Can you help me with other question? How to filter Certain user while couting Days since Last Activity - https://help.salesforce.com/articleView?id=000213223&type=1
 
Raj VakatiRaj Vakati
what is your requirement ?
Vila Shah 16Vila Shah 16
This formula is counting days since last activity but we have some emails going from pardot recording in salesfroce so those task created by Pardot User should not count in Days since Last activity
 
Vila Shah 16Vila Shah 16
Hi,
we got problem regarding "HistoryTrack" trigger
We’re running into errors on both the Pardot and Salesforce side of things with regards to campaigns. I’m trying to bulk edit some campaign members in the campaign to “Email Sent” status and getting this error:
User-added image
 And on Pardot, we’re repeatedly seeing this sync error:
 System.ListException: Object: CampaignMember, execution of BeforeUpdate caused by List index out of bounds
 
Any thoughts?
Vila Shah 16Vila Shah 16
Hi, are you able to help for the issue above?
 
Raj VakatiRaj Vakati
Can you give me the History Tracking trigger ?? that
Vila Shah 16Vila Shah 16
I copy and paste the code for histroy tracking tigger from this link - https://help.salesforce.com/articleView?id=000182237&type=1
 
Vila Shah 16Vila Shah 16
it is working fine locally in salesforce but when campaign member status is chaing through pardot sync...data is not sycing and throwing error
 
Vila Shah 16Vila Shah 16
Any update? Error is in line 38                                           c.CampaignId__c=CampHisId[i];        
Vila Shah 16Vila Shah 16
Hi, Are you able to help me to solve this? our sync is holding from pardot to salesfroce because of this issue. It; very urgent and all your help is greatly appreciated
Raj VakatiRaj Vakati
Does Paradot SYnc user is having permission for this field CampaignId__c??
Vila Shah 16Vila Shah 16
Thanks for your help, I opened up CampaignID__c field to pardot user profile but still it's not working. Any other suggestion please?

 
Vila Shah 16Vila Shah 16
Should I deactive trigger or any other suggestion?
Vila Shah 16Vila Shah 16
 This prospect has a sync error: Object: CampaignMember, execution of BeforeUpdate caused by List index out of bounds - On pardot side it is showing this error message
Raj VakatiRaj Vakati
can you by pass this trigger for Pardot user  ?? 


Create a check box field on the user ( by pass trigger ) 
And check that check box to pardot integation user 

if the chheckbox is checked skip the trigger
 
Vila Shah 16Vila Shah 16
But we want to also update the Campaing History from pardot user as well
Vila Shah 16Vila Shah 16
If there is no other way then we can go with the option you suggested...I have created check box then what's next?
 
Vila Shah 16Vila Shah 16
We definately would like to capture the histroy from Pardot User...its not going work by skipping Pardot user ...Let me know if anything we can do to fix this error -  This prospect has a sync error: Object: CampaignMember, execution of BeforeUpdate caused by List index out of bounds
Vila Shah 16Vila Shah 16
Any suggestions? please let me know...Thank you so much for all your support so far
 
Vila Shah 16Vila Shah 16
Hi,
Is there any help can you provide on the error above? It's still not working and I can't able to bypass pardot user. Any other suggestion please
Vila Shah 16Vila Shah 16
Hi there,
Is there any solution y ou can suggest? or should i Deactivate trigger? Can you please help
Raj VakatiRaj Vakati
You can by pass the this trigger for Pardot User..  Do you think its not possiable ? 


Create a check box field on the user ( by pass trigger ) 
And check that check box to pardot integation user 
Vila Shah 16Vila Shah 16
No that is not an option. We need to track Pardot user activity as well
Vila Shah 16Vila Shah 16
Is there any other option?
Vila Shah 16Vila Shah 16

Hi,
we got problem regarding "HistoryTrack" trigger
We’re running into errors on both the Pardot and Salesforce side of things with regards to campaigns. I’m trying to bulk edit some campaign members in the campaign to “Email Sent” status and getting this error:

 And on Pardot, we’re repeatedly seeing this sync error:
 System.ListException: Object: CampaignMember, execution of BeforeUpdate caused by List index out of bounds
 
Can you suggest something else or only option to deactive trigger? any help is appreciated
Vila Shah 16Vila Shah 16
Hi,
Is there any help you can provide?