function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shaafshaaf 

Map Lead Fields to existing Account.Type field

I created a field called type in Leads and I would like to map it to the existing field Account.Type.  However, this is not an option.  Any way around this?

 

I can map fields that I have created in Leads to Accounts.

 

Thanks,

Sandy

jkucerajkucera

Unfortunately you can't map custom fields to standard fields.  If you don't want to create a custom field on Account, the workaround is to use an Account trigger (code) to populate Account.Type when the account is created. 

 

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); 

    }

  }

}

 

gotmikegotmike

where exactly does that code go to make sure it is triggered?

jkucerajkucera

Create a new trigger on Account and it should fire at the right time.

William PlayfairWilliam Playfair

 Hello, I am trying to implement this and I am getting an unexpected token: "{" in like 12 column 34.
 

Any idea why this could be?