I have a requirement in which I have to create a custom lookup field on lead object which selects the account Account__c
and during the lead to account conversion I have to map the field with 'Parent Account' field of the account which is a standard field.So i am trying to write the code on before insert trigger that maps the custom lookup field of lead to the standard field of account.
trigger populateParentAccount on Account (before Insert){
List<Lead> convertedLeads=[SELECT Id, ConvertedAccountID,Agency_account__c FROM Lead WHERE IsConverted=True AND ConvertedAccountId IN :trigger.new];
Map<ID,ID> acctParentMap=new Map<ID,ID>();
for (lead l: convertedleads){
acctParentMap.put(l.ConvertedAccountId,l.Agency_account__c);
}
for (account a:trigger.new){
if (acctParentMap.containsKey(a.Id)){
a.ParentId = acctParentMap.get(a.Id);
}
}
}
But It is not working.. Please help..