+ Start a Discussion
Kiru535Kiru535 

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)
    {
       leadIds.add(cm.LeadId);
      
    }
    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(isUpdateRequired)
        leadforupdate.add(con);
       
    }
     if(leadforupdate.size() > 0)
            update leadforupdate; 
  }
}
Gupta.VishalGupta.Vishal
Hi ,
You can  go through this link
http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

for knowledge about test classes ,

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

Thanks