function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohammed AzarudeenMohammed Azarudeen 

Is it Possible to load dynamic values in Standard Picklist

My Scenario : I am doing with custom object. Object name is Test_Case__c and it has lookup to Module__c object. Module__c object contains one Long Text Area field called Components__c where users can enter texts by separate lines. So on new record creation of Test_case__c when Module__c is selected then the Components__c from Module__c should load into one of the picklist field called Solution_Component__c in Test_case__c. 
  1. Is this possible without writing vfp and controller?.
  2. If it is possible by writing vfp and controller what is the way i need to go?
  3. If it is not possible without writing vfp and controller, how could I get ID of the selected Module__c in Test_case__c creation(because need to capture the ID when it is selected from lookup popup)
Deepak GulianDeepak Gulian
1. Yes it is possible by VFpage and Controller.
2.
public class accountExtend {
public final Account acc;
public String[] Splits;
    public accountExtend(ApexPages.StandardController controller) {
        this.acc = (Account)controller.getRecord();
        System.debug(acc.SLASerialNumber__c);
        Splits = acc.SLASerialNumber__c.split('[\n]');
        System.debug(Splits.size());
    }
    public pageReference Clonesave(){
        System.debug(acc.SLASerialNumber__c);
        return null;
    }
    public List<selectOption> getPickValues(Sobject object_name, String field_name, String[] dynamic_val) {
        List<selectOption> options = new List<selectOption>(); //new list for holding all of the picklist options
        if ( dynamic_val.size() > 0 ) { //if there is a first value being provided
            for(Integer i=0; i<dynamic_val.size();i++){
                  options.add(new selectOption(dynamic_val[i], dynamic_val[i])); //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.getLabel(), a.getValue()));  //add the value and label to our final list
        }
        return options; //return the List
    }
    
    public List<selectOption> getCustomerPrio() {
        return getPickValues(acc, 'd33pak__CustomerPriority__c', Splits );
    }
         
}
<apex:page showHeader="false" sidebar="false" showChat="false" extensions="accountExtend" standardController="Account" >
  
 <apex:form id="updateRenewalForm"  style="margin-left: auto; margin-right: auto; width: 90%">
 <apex:pageBlock mode="edit" >
     
     <apex:pageBlockButtons >
             <apex:commandButton value="Save" action="{!Clonesave}"/>
     </apex:pageBlockButtons>
     <apex:pageBlockSection >
            <apex:inputField id="par" value="{!Account.Name}"/>
            <apex:inputField value="{!Account.SLASerialNumber__c}" />
            <apex:selectList id="locale" size="1" value="{!Account.CustomerPriority__c}" title="SLA Serial Number">
                <apex:selectOptions value="{!CustomerPrio}"></apex:selectOptions>
            </apex:selectList>
</apex:pageBlockSection>
 </apex:pageBlock>
 </apex:form>
</apex:page>
SLASerialNumber__c is Long Text Area field
CustomerPriority__c is picklist field with value (High,Medium,Low)

According to above code I'm fetching values from Long Text Area (SLASerialNumber__c) and binding those value in the picklist field (CustomerPriority__c).
Right now Long text area and picklist field are in same object but as per your requirement this can be implemented. need to do some major changes in code.

3. And you can also store the ID easily of Selected Module using a formula field simply.

 
Mohammed AzarudeenMohammed Azarudeen
@Deepak Gulian - Thanks for your post. I'll try with your code and get back to you. And I don't want to store Id anywhere why I need id means when module__c is selected from lookup popup(at this moment i want to capture id not after saving or inserting) then i can get the long text area values with this ID. 
Deepak GulianDeepak Gulian
Yes you can get Id when we select value from pop up for look up field and get those long text area value and bind easily to the picklist.