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
Sravya Sadhu 4Sravya Sadhu 4 

Test class

rigger CMfromContact on CampaignMember (before insert) {
         
         List <CampaignMember> c=trigger.new;
      // CampaignMember C= trigger.new[0];
              List<Campaign> a= new List<Campaign>();
              List<Contact> o;
       //If (C.CampaignId!=Null && C.ContactId!=Null){
              IF(C[0].CampaignId<>Null && C[0].ContactId<> Null){
                 o=[SELECT Id,LeadSource FROM Contact WHERE Id =:C[0].ContactId LIMIT 1];
              // o=[SELECT Id,LeadSource FROM Contact WHERE Id =:C.ContactId LIMIT 1];
    }
        for(CampaignMember m:trigger.new){
                 If(o<>Null && o.size()>0){
                 m.Lead_Source__C=o[0].LeadSource;
        }
    }
}


can i have test class for this
 
Shashikant SharmaShashikant Sharma
Just follwo this : http://forceschool.blogspot.in/search/label/Test%20Apex

Here you just need to create a Campaign, Contact and CampaignMember ( Make sure member is contact ) in you test class and it will run. Populate mininmum required fields in these records.

Let me know if you still have issues.