• Pudbrook
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
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); 
    }
  }
}