0

Hi I am new to the salesforce development. I have made a trigger by looking at some videos but not sure about how to make a test class for it.I am pasting it over here. how shall i start. I havenot found enoug videos for salsforce test classes

trigger UpdateLeadSource on Lead (before insert, before update) {
if(Trigger.isUpdate)
{
 if(trigger.old[0].LeadSource == null &&
 trigger.old[0].Lead_Source_for_Employer__c != trigger.new[0].Lead_Source_for_Employer__c
 )
 {
  trigger.new[0].LeadSource = trigger.new[0].Lead_Sources_for_Career_Advisor__c ; 
 }
 else if(trigger.old[0].LeadSource == null &&
  trigger.old[0].Lead_Source_for_Employer__c != trigger.new[0].Lead_Source_for_Employer__c
 )
 {
  trigger.new[0].LeadSource = trigger.new[0].Lead_Source_for_Employer__c ; 
 }
}
else if (Trigger.isInsert)
{
 if(trigger.new[0].Lead_Sources_for_Career_Advisor__c != null)
 {
  trigger.new[0].LeadSource = trigger.new[0].Lead_Sources_for_Career_Advisor__c ;  
 }
 else if(trigger.new[0].Lead_Source_for_Employer__c != null)
 {
  trigger.new[0].LeadSource = trigger.new[0].Lead_Source_for_Employer__c ;    
 }
}
}

It is updating the LeadSource if its empty from the two different lead sources i.e "Lead_Sources_for_Career_Advisor__c" and "Lead_Source_for_Employer__c".

Any help will be much appreciated.

Thanks in advance

  • @metadaddy Looks like the probable duplicate question has been removed. Probably a case to reopen ? – Prady Jan 9 '15 at 1:16
  • Here are some links which would help you write a test class. salesforce.stackexchange.com/questions/10988/… salesforce.com/us/developer/docs/apexcode/Content/… – Prady Jan 9 '15 at 1:19
  • Since the question is closed, i dont have an option to answer. Pls follow the links and accordingly create the test class and test method. In your test method create a new lead. ` lead l = new lead(); l.lastname='xxx'; l.leadsource='web'; `// add other fields of lead. insert l; This should take care of the insert code, similarly update the same lead by making change to l.leasdsource = 'Partner' and then use the update command to update . update l; – Prady Jan 9 '15 at 5:51
  • No case to open, in my opinion, since it's a 'do my work for me' kind of question. – metadaddy Jan 10 '15 at 1:36

Browse other questions tagged or ask your own question.