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
gwpgwp 

Populate lead fields from an account and contact

Hi,

 

I'm writing an "update Account" function for my partner portal users who don't have the rights to edit an account directly. This function creates a new lead, populated by the source account and it's main contact.

 

I want to write some Apex that will look up the conversion field mappings used in the conversion process and use these as a reference to tell my Apex script how to to populate my new Lead so that as fields are added and mappings changed over time I will not have to re-write the apex code.

 

Example:

Consider a lead L is converted into account A and contact C. My portal user then clicks on a button and some Apex creates lead L2 populating it with account B and contact C's information:

 

Lead L: Name= Bob Brady, Company = United Nations, Custom_field_IsNGO__c = True

 

***converts to...***

Account A: Name = A.Company, Custom_field_IsImportantClient = A.Custom_field_IsNGO__c

Contact C: Name = Bob Brady

 

***user clicks on update button and a new lead is created...***

Lead L2: Name = C.Name, Company = B.Name, CustomField_IsNGO__c = B.Custom_field_IsImportantClient

 

To solve this last step I beleive I need to either:

 

- hard code the field mappings (BAD! My org has no techies if I am not there, plus this is a major pain when customizing the conversion process for a DBA as it is effectively hidden logic)

 

or - create a custom object to act as a mapper (better but still "bad" as this means maintaining the salesforce lead conversion mapping logic in two places)

 

or - look up the standard salesforce conversion mapping and using that as a reference to transfer the data into the new lead L2

 

Any suggestions or ways anyone has worked out to do this kind of look up in Apex? The describe info only gets the standard schema data... And I don't see any schema object containing the data I need...

 

Thanks!

 

Matt

jkucerajkucera

I don't think I understand the goal - how will creating a 2nd lead let portal users update the account?  As you've found, you cannot access the lead mapping from Apex.

 

btw-I believe this may be a violation of the terms of service for portal users.