3

My requirement is when i get the picklist values from account, it is showing all pick list values irrespective of record type?how to do this?

public List<selectOption> getPickValues(Sobject object_name, String field_name, String first_val) {
  List<selectOption> options = new List<selectOption>(); //new list for holding all of the picklist options
  //if (first_val != null) { //if there is a first value being provided
     options.add(new selectOption('','--None--')); //add the first option
  //}

  Schema.sObjectType sobject_type = object_name.getSObjectType(); //grab the sobject that was passed
  Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe(); //describe the sobject
  Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap(); //get a map of fields for the passed sobject
  List<Schema.PicklistEntry> pick_list_values = field_map.get(field_name).getDescribe().getPickListValues(); //grab the list of picklist values for the passed field on the sobject
  for (Schema.PicklistEntry a : pick_list_values) { //for all values in the picklist list
        options.add(new selectOption(a.getValue(), a.getLabel())); //add the value and label to our final list
  } 
  return options; //return the List
}
//Sobject Account;
//Sobject Contact;
Account a=new Account(RecordTypeId='0120n0000004VDs');
Contact c=new Contact();
public List<SelectOption> getAccountType(){
    return getPickValues(a, 'Type', NULL); 
}
public List<SelectOption> getAccountCountry(){
    return getPickValues(a, 'Country__c', NULL); 
}
public List<SelectOption> getContactType(){
    return getPickValues(c, 'Type__c', NULL); 
}

Thanks in Advance

3

I can't figure out a way to do this in simple Apex, but it looks like you can do it via the metadata API (https://success.salesforce.com/ideaView?id=08730000000gNpLAAU) and the open source FinancialForce library (https://github.com/financialforcedev/apex-mdapi)

| improve this answer | |
0

Note : When adding new record types it’s possible to include a picklist field on the page layout but it fails to make any of the picklist values available for use. The result is a field you have full access to but no way of seeing or selecting a picklist value recently added but not added in available options for picklist. Therefore make sure to mark it in the available list.

| improve this answer | |
-2

Here are the steps you need to follow!

Click: Setup > Create> Objects> Section_2_Balance_Sheet_c> Record Types > then click on each of the record types you need to add the picklist value to. On the record type detail page you will find a section called Picklists Available for Editing. From that list locate your picklist field and click Edit. Add the values you need to the right column. Click Save.

| improve this answer | |

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.