You need to sign in to do that
Don't have an account?
Pudbrook
Map Custom Lead Field to Account Type
Hey
I have created a trigger to map my custom lead "Type" field to the AccountType field. I finally got the trigger to save, however when I try to convert a lead record and create a new account record I recevie the following error:
Error: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, accountType: execution of BeforeInsert caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Lead.ConvertedAccountId Trigger.accountType: line 9, column 1: [] (System Code)
Coul really use some help solving. Also the trigger is below:
trigger accountType on Account (before insert){
Set<Id> accts = new Set<Id>();
FOR(Account a: trigger.new){
accts.add(a.Id);
}
List<Lead> leads=[SELECT Id, Type__c FROM Lead WHERE convertedAccountId IN: accts];
Map<Id,String> leadMap=new Map<Id,String>();
FOR(Lead l: leads){
leadMap.put(l.ConvertedAccountID,l.Type__c);
}
FOR(Account a2: trigger.new){
IF(leadMap.containsKey(a2.Id)){
a2.Type=leadMap.get(a2.Id);
}
}
}
I have created a trigger to map my custom lead "Type" field to the AccountType field. I finally got the trigger to save, however when I try to convert a lead record and create a new account record I recevie the following error:
Error: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, accountType: execution of BeforeInsert caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Lead.ConvertedAccountId Trigger.accountType: line 9, column 1: [] (System Code)
Coul really use some help solving. Also the trigger is below:
trigger accountType on Account (before insert){
Set<Id> accts = new Set<Id>();
FOR(Account a: trigger.new){
accts.add(a.Id);
}
List<Lead> leads=[SELECT Id, Type__c FROM Lead WHERE convertedAccountId IN: accts];
Map<Id,String> leadMap=new Map<Id,String>();
FOR(Lead l: leads){
leadMap.put(l.ConvertedAccountID,l.Type__c);
}
FOR(Account a2: trigger.new){
IF(leadMap.containsKey(a2.Id)){
a2.Type=leadMap.get(a2.Id);
}
}
}
Replace the query.....
List<Lead> leads=[SELECT Id, Type__c, convertedAccountId FROM Lead WHERE convertedAccountId IN: accts];
It should work..
All Answers
Replace the query.....
List<Lead> leads=[SELECT Id, Type__c, convertedAccountId FROM Lead WHERE convertedAccountId IN: accts];
It should work..
Query is the problem, bcoz the requested field missing in that ur query.the field is bold in below query.
List<Lead> leads=[SELECT Id, Type__c, convertedAccountId FROM Lead WHERE convertedAccountId IN: accts];
Thanks,
Ramakrishnan Ayyanar.