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
TackTack 

How to map field in custom object to field in standard object

Hi,

I'm working on development custom object integration app.
I can implement below code in apex.
 
Lead lc1 = new Lead();
                    
                    lc1.Company = HogeObjectSelects[idx].record.Name;
                    lc1.LastName = HogeObjectSelects[idx].record.LastName__c;
                    lc1.FirstName = HogeObjectSelects[idx].record.FirstName__c;
                    lc1.email = HogeObjectSelects[idx].record.EmailAddress__c;
                    lc1.Status = 'Open - Not Contacted';
                    lc1.OwnerId = HogeObjectSelects[idx].record.OwnerId;
                upsert lc1;
sure, this is hard-code.
The app users are not able to change mapped fields...
Even though I provide mapping rule on GUI,
I can not implement the code.
 
My above idea is similar to general feature "Map Custom Lead Field".
https://help.salesforce.com/apex/HTViewHelpDoc?id=customize_mapleads.htm&language=en
Could you please provide your sample code or reference?
 
Thanks,
Tack
 
Wizno @ ConfigeroWizno @ Configero
  1. Create a new Custom Object: Object Mapping (Object_Mapping__c)
    1. Create Text Field: Source Object (Object that is providing the data)
      1. Example: Data is coming from "Lead" Source) and being mapped to "Account" (Target)
    2. Create Text Field: Target Object (Object that we're mapping data to)
  2. Create a new Custom Object: Field Mappings (Field_Mappings__c)
    1. Add Master Detail lookup to Object Mapping object
    2. Add Text field: Source Object Field
      1. Store the API Name of the Source Field in this field
      2. (example: Lead.Company (Source) > Account.Name (Target))
    3. Add Text field: Target Object Field
      1. Store the API Name of the Target Field in this field

So in the end you have 2 new objects and a few fields.

Let's say we have a Custom Object called "Prospect__c" and we want to map it to "Account"
  1. Create new Object Mapping record: 
  2. Object_Mapping__c om = new Object_Mapping__c();
    om.Source_Object__c = 'Prospect__c';
    om.Target_Object__c = 'Account';
    
    insert om;
    
    Field_Mappings__c[] fmaps = new Field_Mappings__c[]{};
    Field_Mappings__c item = new Field_Mappings__c();
    item.Source_Object_Field__c = 'Prospect_Name__c';
    item.Target_Object_Field__c = 'Name';
    
    fmaps.add(item);
    
    item = new Field_Mappings__c();
    item.Source_Object_Field__c = 'Prospect_City__c';
    item.Target_Object_Field__c = 'ShippingCity';
    
    fmaps.add(item);

     
So now, you can reference that Object_Mapping__c object in Apex to get the field mappings for the Prospect__c object. Whether it be in a trigger or a custom VF Admin page.
Wizno @ ConfigeroWizno @ Configero
I forgot to add in the relationship to Object_Mapping__c:
 
Object_Mapping__c om = new Object_Mapping__c();
om.Source_Object__c = 'Prospect__c';
om.Target_Object__c = 'Account';

insert om;

Field_Mappings__c[] fmaps = new Field_Mappings__c[]{};
Field_Mappings__c item = new Field_Mappings__c();
item.Source_Object_Field__c = 'Prospect_Name__c';
item.Target_Object_Field__c = 'Name';
item.Object_Mapping__c = om.Id;

fmaps.add(item);

item = new Field_Mappings__c();
item.Source_Object_Field__c = 'Prospect_City__c';
item.Target_Object_Field__c = 'ShippingCity';
item.Object_Mapping__c = om.Id;

fmaps.add(item);

This is what was added:
item.Object_Mapping__c = om.Id;

 
TackTack
Dear Wizno @ Configero,

It's really great support!!
I'm working the implement based on your sugguestion.
I'll get back to you when I can implement what I want.

Regards,
Tack

 
TackTack
Hi,

In Object_Mapping,
I tried to define below List in order to get mapped object list.
public List<Object_Mapping__c.Target_Object__c> ExistingRecords{get;set;}
Following error message is displayed.
Invalid type: Object_Mapping__c.Target_Object__c
Could you please let me know how to use Object_Mapping__c.Target_Object__c as sObject??

Regards,
Tack