Skip to main content
ats batch が「#Apex」で質問

trigger CreateClead on Lead(after insert){

list<Id>deletLeadList=new list<Id>();

if(Trigger.isInsert){

List<Clead__c> cleadlst= new List <Clead__c>();

for(Lead le: trigger.new){

system.debug('==================='+le);

if(le.LeadSource=='Job Application'){

deletLeadList.add(le.id);

Clead__c cl= new Clead__c ();

cl.Name=le.LastName;

cl.Email__c=le.Email;

cl.Phone__c=le.Phone;

cl.Job_Post__c=le.Subject__c;

cl.Comments__c=le.Description;

cl.CurrencyIsoCode='USD';

cl.Reason__c='Available';

cl.Status__c='Pre-Active';

cl.Clead_Source__c='Web';

//cl.Selling_Rate_Hr__c='Fiftydalor';

//cl.Technology__c='SQL';

cl.Role__c='Other';

//cl.Current_Visa__c='H1';

cleadlst.add(cl);

}

}

insert cleadlst;

}

if(!deletLeadList.isEmpty())

delete([SELECT Id FROM Lead WHERE ID IN:deletLeadList]);

}

 
3 件の回答
  1. 2016年9月15日 11:11
    Hi ats ,

    Try the below code to achieve 100% code coverage

    @isTest

    public class CreateClead_Test{

    static testmethod void testDoAfterUpdate() {

    List<Lead> leadlist = new List<Lead> ();

    list<Id> deletLeadList = new list<Id>();

    Lead ld = new Lead();

    ld.LastName = 'Test';

    ld.Company = 'Manual';

    ld.LeadSource='Job Application';

    insert ld;

    leadlist.add(ld);

    deletLeadList.add(ld.id);

    Clead__c cld = new Clead__c();

    cld.Name = 'Test';

    cld.Email__c= 'Mnaual@test.com';

    insert cld;

    //Delete deletLeadList;

    }

    }

    Hope this helps you!

    Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.

     

    Thanks and Regards

    Paarth Jolly