1

We are integrating Salesforce with External System both inbound and outbound integration. External System can not accept Pick List values with any Spaces and want to accept with stripped out spaces and in lowercases due to their system limitation.Ex: Great Product to greatproduct. What is the best way to achieve this functionality? Custom Settings or Apex Helper Class or any other solution. It is bidirectional integration.

SF-External: Great Product---greatproduct

External-SF: greatproduct---Great Product

3

Use a standard Salesforce picklist. Since Spring '17, you can now define an "API Name" and a "Label", which can be independent of each other. Your code can receive the API Name values from the other system and map them correctly to Salesforce values, and vice versa. There's no longer any need to come up with wonky workarounds, such as using custom metadata types or custom settings. This is in the Release Notes:

Value Labels Are No Longer Tied to API Names

Each picklist value has a display label and an API name. Now you can change the label without the API name changing. You can also edit the API name. However, you can disable the ability to change API names. The label is displayed in a picklist field on a record, and the API name is used everywhere else. For example, data import and export and Apex code use the API name.

You can prevent users from changing a picklist value’s API name. From Setup in Salesforce Classic, enter Picklist Settings in the Quick Find box, and then select Disable editing picklist values’ API names. You can only access Picklist Settings from Salesforce Classic.

  • Although this was always possible with the translation workbench. – martin Feb 24 '17 at 0:19
1

1) Create a custom metadata type to store Product Information. Let's say Product_Type_Mapping__mdt will have 2 columns:

Product_Category__c - stores SF recognizable Picklist value like. Great Product Product_Category_Ext__c - stores External System recognizable picklist value like. greatproduct.

2) Create 2 factory methods which will be used for transformation.

a) When you pass value from SF to External system, use this getProductNameForExternalSystem() method. If you pass Great Product, it will return greatproduct.

public Map<String, String> SFToExternalMap = new Map<String,String>();
public static String getProductNameForExternalSystem(String productCategory){   
    if(SFToExternalMap.containsKey(productCategory))
    {
        return SFToExternalMap.get(productCategory);
    }

    for(Product_Type_Mapping__mdt mdt: [SELECT Product_Category__c,Product_Category_Ext__c
                                    FROM Product_Type_Mapping__mdt]){

        if(mdt.Product_Category__c !=null){         
            if(!SFToExternalMap.containsKey(mdt.Product_Category__c)){
                SFToExternalMap.put(mdt.Product_Category__c, mdt.Product_Category_Ext__c); //Great Product---greatproduct
            }
        } 
    } 
    return SFToExternalMap.get(productCategory);        
}

b) Similarly, use getProductNameForSF() for reverse transformation.

public Map<String, String> ExternalMapToSF = new Map<String,String>();
public static String getProductNameForSF(String trimmedproductCategory){    
    if(ExternalMapToSF.containsKey(trimmedproductCategory))
    {
        return ExternalMapToSF.get(trimmedproductCategory);
    }

    for(Product_Type_Mapping__mdt mdt: [SELECT Product_Category__c,Product_Category_Ext__c
                                    FROM Product_Type_Mapping__mdt]){

        if(mdt.Product_Category__c !=null){         
            if(!ExternalMapToSF.containsKey(mdt.Product_Category_Ext__c)){
                ExternalMapToSF.put(mdt.Product_Category_Ext__c,mdt.Product_Category__c); //greatproduct----Great Product
            }
        } 
    } 
    return ExternalMapToSF.get(trimmedproductCategory);     
}

Just to note that, use of SFToExternalMap map at class level variable will hold the mapping. So, for the first time it will fire SOQL query and creates a map and second time onwards it will retrieve from the map.

  • It sounds great.I will also send other fields along with this piclist field value. I think I need to add this extra logic for each picklist field which I am sending and need to store all picklist field values not just for onepicklist but for entire picklist fields for the object. – crmsj Feb 24 '17 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.