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
miku1051miku1051 

how to reference contact id..???

trigger test1 on Lead (after insert)
{
    
     Set<ID> ls = new Set<ID> ();
     for(Lead l:Trigger.new)
    {
        ls.add(l.id);  
    }
    
    List<Lead> lis=[Select Id,Name, Status,Email,Company,fax,from Lead where id in:ls];
       List<Contact> con=[Select Id,Name ,Email_2__c,fax from Contact ];
       List<Contact> lstContact = new List<Contact>();

          
       
   
       for(Lead ld:lis)
       {
           for(Contact cn:con)
           {
              
                   
                   Contact objC= new Contact();    
                objC.FirstName=ld.FirstName;
                objC.LastName=ld.LastName;
                lstContact.add(objC);
 
           }    
               customobj.lookupfield=objC.Id;//Here i am getting nothing ie id is null here...can u pl help        }
           
           if(lstContact.size() > 0 )
        insert lstContact;
      
                   
}

 

i am getting nothing ie id is null here...can u pl help..i want to get the recently created id there..did you understand what i am asking for...thanks for replying....:)

 how  to reference contact id of the record which is inserted when the lead is created....

Best Answer chosen by Admin (Salesforce Developers) 
b-Forceb-Force

You are trying to access id field of contact , before inserting contact.

 

First insert contactList and then access its Id

 

Thanks,

bForce

All Answers

b-Forceb-Force

You are trying to access id field of contact , before inserting contact.

 

First insert contactList and then access its Id

 

Thanks,

bForce

This was selected as the best answer