+ Start a Discussion
force shahidforce shahid 

How to map the state code with state names ?

Hi Friends ,

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.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.MailingState=customObjRecord.Mailing_Address_State__c;
                              ||  customObjRecord.Primary_Address_Country__c.equalsIgnoreCase('usa') ){
                                c4.MailingCountry='United States';
                        } else 
                        if(customObjRecord.Mailing_Address_State__c.equalsIgnoreCase('CA')  ){
                        } else 
Anil JAdhav 14Anil JAdhav 14
Hi Shahid,

I do feel your pain. 
I will suggest this, please let me know if you are flexible with it.
Create a custom object in custom setting. that will have two custom fields State and Code. and insert custom setting data accordingly.
Now you have mapping of both state and code. and to query this you do not need any query as well.

Write a logic to retrieve the state and populating codes and vice-versa.
Please let me know yours thoughts on this.