I'm trying to create a trigger that creates an account and contact when the lead status is changed to a given value. The contact value needs to come from the Lead Owner User. How can I achieve that?
if(Trigger.isInsert){
List<Account> accountList = new List<Account>();
List<Contact> contactList = new List<Contact>();
List<User> leadOwner = new List<User>();
for (Lead lead : Trigger.new) {
System.debug('lead: ' + lead);
if(lead.Status == 'Confirmed Contact'){
Account account = new Account(Name = lead.Company, cnpj__c = lead.cnpj__c);
accountList.add(account);
Contact contact = new Contact(
FirstName = //need information from the owner lead
LastName = //need information from the owner lead
Email = //need information from the owner lead
Phone = //need information from the owner lead
AccountId = account.Id
);
contactList.add(contact);
}
}
if(accountList.size() > 0 && contactList.size() > 0){
insert accountList;
insert contactList;
}
}