+ Start a Discussion
Nusha AhmadNusha Ahmad 

FIELD_INTEGRITY_EXCEPTION, Account ID: id value of incorrect type: 00Q2w000006RwzQEAS: [AccountId]: Class.Lead_Contact.AfterInsert: line 14, column 1

// Whenever a new Lead created create a corresponding contact with the same data.
public class Lead_Contact {
    
    public static void AfterInsert(List<Lead> leads){
        
        List<Contact> contacts= new List<Contact>();
        for(Lead l: leads){
             contact c = new Contact();
            c.LastName=l.LastName;
            c.Phone=l.Phone;
            c.Email=l.Email;
            c.FirstName=l.FirstName;
            c.AccountId=l.Id;
            contacts.add(c);
        }insert contacts;
    }

}
// trigger
trigger Lead_Contact on Lead (after insert) {
      Lead_Contact.AfterInsert(trigger.new);
}
Best Answer chosen by Nusha Ahmad
ShirishaShirisha (Salesforce Developers) 
Hi Nusha,

Greetings!

You can not use the Lead Id as the AccountId while creating the Contact record as Account and Lead both are different Objects.Also,there is no field on the Lead Object which referes the Account Object.

If you do not have the AccountId field as required then you can ignore the field.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri