I have one trigger. In my trigger i wrote some condition insert records into conatct / lead object while importing CSV file into Custom object. . I am importing CSV file into Custom object . In my custom object state field type is Text . Contact object state field type is Picklist. In picklist i have multble state. But in CSV file state names are replaced with their state codes . Like California = CA ,

For this reason when i import csv file into custom objects rescords are inserted in custom object only. They didn't insert / update in contacts object . CLient is not rady to change the field data type & not ready to insert CA into picklist field .How to write a code ?How to overcome this issue ?

I am giving my inserting code below. Here i am written code for one state . I think this is not proper issue.

Code :

 contact c4 = new contact();
 c4.AccountId = a.Id;
 c4.LastName = customObjRecord.Name;
 c4.FirstName = customobjrecord.First_Name__c;
 c4.OtherPhone = customObjRecord.Other_Phone__c;
 c4.Email = customObjRecord.Email_Address__c;
 c4.Phone = customObjRecord.Phone__c;
 c4.Title = customObjRecord.Title__c;
 c4.Contact_Status__c = customObjRecord.Contact_Status__c;
 c4.LeadSource = customObjRecord.Lead_Source__c;
 c4.Lead_Subsource__c = customObjRecord.Lead_Subsource__c;
 c4.Lead_Channel__c = customObjRecord.Lead_Channel__c;
 c4.MailingStreet = customObjRecord.Mailing_Address__c;
 c4.MailingCity = customObjRecord.Mailing_Address_City__c;
 // c4.MailingState=customObjRecord.Mailing_Address_State__c;
 c4.MailingPostalCode = customObjRecord.Mailing_Postal_Code__c;
 c4.External_Con_Id__c = 'Ext' + count;

 if (customObjRecord.Primary_Address_Country__c.equalsIgnoreCase('US') || customObjRecord.Primary_Address_Country__c.equalsIgnoreCase('usa')) {
  c4.MailingCountry = 'United States';
 } else {
  c4.MailingCountry = customObjRecord.Primary_Address_Country__c;

 if (customObjRecord.Mailing_Address_State__c.equalsIgnoreCase('CA')) {
  c4.MailingState = 'California';
 } else {
  c4.MailingState = customObjRecord.Mailing_Address_State__c;
  • Why don't you insert your contact by using the state codes and country codes directly? The country and state will be populated by Salesforce automatically if you specify the code. Jun 20, 2017 at 9:42

1 Answer 1


Instead of forcing Salesforce to transform your data (using code that is likely to only be used on this one occasion), I'd suggest transforming the data in your CSV file so that it matches what you are (or rather, your client is) expecting in Salesforce.

To me, this is a job for a simple vlookup in Microsoft Excel (well, as simple as vlookups can be). The idea is that you have your existing CSV file with state codes, and another spreadsheet that contains 2 columns. The first column contains state codes, while the second contains the state's full name. The vlookup would take the state code from your current CSV, use that to look up the corresponding row in the state code -> state name spreadsheet, and return the state name.

Assuming you're using the Salesforce-provided data loader, and label the column that your vlookup is in, you can simply adjust the mapping for the Contact's MailingState field to use the data from the vlookup column (instead of whichever column you're currently mapping it to).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .