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

Test class for lead campaign

I need help to write a test clss for below class. Please help me

public class LeadFieldUpdate
  public void UpdateLead(CampaignMember[] cmember)
    Set<Id> leadIds = new Set<Id>();
    Set<String> campaignperLead;
    List<Lead> leadforupdate = new List<Lead>();
    String Compname;
    for (CampaignMember  cm: cmember)
    for(Lead con:[SELECT id, Cname__c,(SELECT id, CampaignId, CreatedDate,Campaign.Name, Campaign.StartDate, Status, LeadId, HasResponded FROM CampaignMembers Order by CreatedDate,HasResponded) FROM Lead where Id IN :leadIds])
      Compname = NULL;
      campaignperLead = new Set<String>();
      for(CampaignMember uis: con.CampaignMembers)
        IF(uis.CampaignId!= NULL && uis.HasResponded == true)
          Compname = uis.CampaignId;
      boolean isUpdateRequired = false;
      if(con.Cname__c != string.valueof(Compname))
        con.Cname__c = string.valueof(Compname);
        isUpdateRequired = true;
        system.debug('6----******Lead Updated Compaign Name is*********' + con.Cname__c);
     if(leadforupdate.size() > 0)
            update leadforupdate; 
Hi ,
You can  go through this link

for knowledge about test classes ,

Create a class with @isTest  annotation and then create the Test method to test your functionalities .