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
anil 007anil 007 

convert lead to oppurtunity

hiii ,

 

please help me with this code

 

trigger Lead_Opp on Lead (after insert) {
List<Opportunity> contact = new Opportunity[0];
List<Lead>lead=[SELECT Id, status ,name FROM lead WHERE Id in :Trigger.new];
 for(Lead a: Trigger.new)
 {
   if(a.status!=null)
    {   
 // contact.add(new Opportunity(Name ='anil',CloseDate=System.today(),stagename='qualification'));  
 // a.test_field__c='OKnott';
    Database.LeadConvert lc = new database.leadconvert();  
    lc.setLeadid(a.id);
    
     lc.setConvertedStatus('');
   //   Database.LeadConvertResult lcr = Database.convertLead(lc);
       
    }
    else
    {
      System.debug('fsdfds');
  //  a.test_field__c='OK';
    }
}
insert contact;
     
    }

 

 

iam getting error please help me.

bob_buzzardbob_buzzard

I'd imagine that you get an error that the contact list doesn't contain any opportunities, as you initialize it to a single element but don't actually add any opportunities.