• Pudbrook
  • 10 Points
  • Member since 2015

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 0

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){
   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){
  FOR(Account a2: trigger.new){