I have a requirement like,

If user enter BillingState manually in visualforce page then BillingStateCode must have to set automatically based on the BillingState.

I am thinking to use MAP in this case, but I don't know How to get the all BillingStateCode and put as a value in MAP

MAP<String, String> mapStatetoStateCode = new Map<String, String>();

mapStatetoStateCode.put(sObject.BillingState, sObject.BillingStateCode);

Is there a way fetching all BillingStateCode from soql ?

Can anybody guide me on this situation ?

  • Why not show the BillingState values in a picklist instead, as users can make typos. – Raul Jun 21 '17 at 11:27
  • @RahulSharma What i am trying to achieve is : I am getting Quote.BillingAddress from Quote.Account.BillingAddress it's working fine while inserting Quote but i when user open that Quote and Edit the Quote.BillingState it's not working properly as expected that's why i though let's make some changes in custom save method in class – Nail David Jun 21 '17 at 11:31

You can describe the field and get the state value with the statecodes:

Schema.DescribeFieldResult fieldResult = Account.BillingStateCode.getDescribe();
Map<String, String> mapCodeToValue = new Map<String, String>();

for(Schema.PicklistEntry f : fieldResult.getPicklistValues()){
mapCodeToValue.put(f.getValue(), f.getLabel());


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.