0

This is my 1st week taking over my company's salesforce application, so I'm an extreme newbie. I apologize if this is an exceptionally simple issue. I have details listed below, but basically, I need to know how to specify which values I want to use to populate a dropdown list. For example, display all values from table_X where the id = 1,3, or 5, into the dropdown list.

On one of our salesforce pages, we have a dropdown list. Normally this list simply displays all values from a particular salesforce table. Now however, I need to change this to the following:

  • If the client of this particular order is associated with is "ABC Company", only show 3 values in the dropdown list: New, Pending, & Shipped.
  • Exclude all other values from this drop down list

Here's the apex code:

<apex:column title="Shipping Status" >
                        <apex:facet name="header">
                            <apex:outputLabel title="Shipping Satus">Status
                            <apex:image value="/s.gif" alt="" styleclass="helpIcon"/>
                            </apex:outputLabel>
                        </apex:facet>
                        <apex:inputField id="shippingStatus" value="{!i.item.shipping_Status__c}" rendered="{!i.editable}" style="width:80%"/>
                        <apex:outputField value="{!i.item.shipping_Status__c}" rendered="{!!i.editable}" style="width:80%"/>
                    </apex:column>

And here's some code I found (although I'm not sure if this pertains to what I need. Still new to this):

public List<ShipStatusResult> ShipStatusResults {
    get {
        if (ShipStatusResults == null) {
            ShipStatusResults = new List<ShipStatusResult>();
        }
        return ClinicalResults;
    }
    set;
}   
public class ShipStatusResult{
    public Shipment_Status__c item {get; set;}    
    public boolean editable {get; set;}
    public string state {get; set;}
    public boolean ShipmentStatusIsEditable{get;set;}       
}  

Like I said, this may not be the full code, but hopefully it helps.

Thanks

1
  • I apologize that my example's a little vague, so even if you can just point me in the right direction or a good link about how to do this, I would greatly appreciate it!
    – goalie35
    May 25 '17 at 18:06
1

I would suggest you the build the picklist values in apex controller code based on Account.

So, you can specify particular account type or recordtype or specific record indicator for which you will prepare specific set of picklist values. Because today you are looking for ABC Company, tomorrow it can be XYZ Company.

Create a custom settings or custom metadata type which will hold the mapping between Account Type and picklist values.

This is a sample code to prepare picklist values.

//retrieve mapping entries from Custom settings
Map<String, String> valueMap = new Map<String, String>();
valueMap.put(/* add desired picklist entries New, Pending, & Shipped*/);
//if you want to display all the values then do not put in the map.
//retrieve picklist values based on the valueMap
getPicklistValues(ShipStatusResult, shipping_Status__c,valueMap);

public static List<SelectOption> getPicklistValues(SObject obj, String fld, Map<String,String> valueMap)
{
    List<SelectOption> options = new List<SelectOption>();
    // Get the object type of the SObject.
    Schema.sObjectType objType = obj.getSObjectType();
    // Describe the SObject using its object type.
    Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
    // Get a map of fields for the SObject
    map<string, schema.sobjectfield> fieldMap = objDescribe.fields.getMap();
    // Get the list of picklist values for this field.
    List<Schema.PicklistEntry> values =
    fieldMap.get(fld).getDescribe().getPickListValues();
    // Add these values to the select option list.
    for (Schema.PicklistEntry a : values)
    {
        //here you will add picklist entries based on valueMap entries.
        if(valueMap.values().size()>0)
        {
            if(valueMap.containsKey(a.getValue()))
            {
                options.add(new SelectOption(a.getLabel(), a.getValue()));
            }
        }
        else
        {
            //here you want to display all the values
            options.add(new SelectOption(a.getLabel(), a.getValue()));
        }       
    }
    return options;
}

Rather than using apex:inputField, use apex:selectList to display picklist values in the visualforce.

Hope, it will help you to find good direction.

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.