+ Start a Discussion
Kiru535Kiru535 

Update multiselect picklist based on lookup field in VF page

Please help me ASAP to solve this scenario.

 

 I have one VF page on that we have a look up field  and Multiselect picklist. When ever user selects the lookup field from the custom object, automatically the corresponding picklist values should be updated. Here all are custom objects.

 

Please help me ASAP.

 

Regards,

kk

swatKatswatKat

The corresponding picklist values should be updated with what ? Is there a save button on clicking which the selected values from multiselect picklist will be updated? Could you paste your code.

Kiru535Kiru535

I have lookup field called IBX name ( Lookup field refering to IBX object) and Compitator (Custom multi select picklist field) on vf page. 

Click on new - The VF page will open with new

User enter the details and after he enter the Lookup field, Immediately the picklist values should be displayed for the competator field. otherwise picklist values will be null.

Kiru535Kiru535

<apex:page standardController="IBX_Lines__c">
<apex:sectionHeader title="IBX_Lines__c Edit" subtitle="{!IBX_Lines__c.name}"/>
<apex:form >
<apex:pageBlock title="IBX_Lines__c Edit" mode="edit">
<apex:pageBlockButtons location="top">
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Save & New" action="{!save}" />
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons> <apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Save & New" action="{!save}" />
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information" columns="2">
<apex:inputField value="{!IBX_Lines__c.Name}" required="false"/>
<apex:inputField value="{!IBX_Lines__c.CurrencyIsoCode}" required="false"/>
<apex:inputField value="{!IBX_Lines__c.Opportunity__c}" required="true"/>
<apex:inputField value="{!IBX_Lines__c.Primary_Campaign_Source__c}" required="false"/>
<apex:inputField value="{!IBX_Lines__c.IBX_Name__c}" required="true"/>
<apex:inputField value="{!IBX_Lines__c.Lead_Source__c}" required="false"/>
<apex:inputField value="{!IBX_Lines__c.Line_Type__c}" required="true"/>
<apex:inputField value="{!IBX_Lines__c.Cross_Region_Lead_Source__c}" required="false"/>
<apex:inputField value="{!IBX_Lines__c.Adjustment_Type__c}" required="false"/>
</apex:pageBlockSection> <apex:pageBlockSection title="Status" columns="2">
<apex:inputField value="{!IBX_Lines__c.Forecast_Status__c}" required="false"/>
<apex:inputField value="{!IBX_Lines__c.Closed_Won_Lost_Notes__c}" required="false"/>
<apex:inputField value="{!IBX_Lines__c.Lost_Reason__c}" required="false"/>
</apex:pageBlockSection> <apex:pageBlockSection title="MRR/NRR" columns="2">
<apex:inputField value="{!IBX_Lines__c.Forecast_MRR__c}" required="false"/>
<apex:inputField value="{!IBX_Lines__c.Forecast_NRR__c}" required="false"/>
<apex:inputField value="{!IBX_Lines__c.Booked_Gross_MRR__c}" required="false"/>
<apex:inputField value="{!IBX_Lines__c.Booked_Gross_NRR__c}" required="false"/>
<apex:inputField value="{!IBX_Lines__c.Booked_Net_MRR__c}" required="false"/>
<apex:inputField value="{!IBX_Lines__c.Booked_Net_NRR__c}" required="false"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Competitors" columns="2">
<apex:inputField value="{!IBX_Lines__c.Competitors__c}" required="false"/>
</apex:pageBlockSection> <apex:pageBlockSection title="Comments" columns="2">
<apex:inputField value="{!IBX_Lines__c.Comments__c}" required="false"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

swatKatswatKat

the code should work something like this :

When the look up field is null, the picklist will not be visible( done with the rendered attribute on the picklist field). When you choose some value in the look up field, the action support tag will rerender the pageblock and the piclist will be displayed.

 

<apex:pageBlock title="IBX_Lines__c Edit" mode="edit" id="pgBlockId">
  <apex:inputField value="{!lookupfield}" required="false">
      <apex:actionSupport event="onchange" reRender="pgBlockId"/>
  </apex:inputField>  
  <apex:pageBlockSection >
      <apex:inputField value="{!IBX_Lines__c.Competitors__c}" rendered="{!lookupfield!=null}" />
  </apex:pageBlockSection>
</apex:pageBlock>

 

Kiru535Kiru535

Thanks for your reply.

My requirement was

 

 If the llokup field value ="Bangalore"  picklist value should be "MG road" , "Marthalli"

 If the llokup field value ="Hydearbad"  picklist value should be "Banjara Hills" , "Jublihills"  in the picklist.

 

So based on the lookup value, Picklist value need to be change

 

Please help me how to do this?

swatKatswatKat

You will have to create an extension class to this vf page so that u can do the manipulation in a method.. 

 

public class extensionCls_Con {

    public IBX_Lines__c currentRec{ get ; set ;}
    public extensionCls_Con (ApexPages.StandardController controller) {
        currentRec=(IBX_Lines__c )controller.getRecord();
    }
    
    public void setPick(){
        if(lookupField ==''){//id for the record with the name Bangalore
            currentRec.Competitor__c='MG road;Marthalli';
        }
    }

}

  VF Page : Set the action attribute of the action support to a method say (setPick)set the correct values for the picklist.

 

<apex:pageBlock title="IBX_Lines__c Edit" mode="edit" id="pgBlockId">
  <apex:inputField value="{!lookupfield}" required="false">
      <apex:actionSupport event="onchange" reRender="pgBlockId" action="{!setPick}"/>
  </apex:inputField>  
  <apex:pageBlockSection >
      <apex:inputField value="{!currentRec.Competitors__c}" rendered="{!lookupfield!=null}" />
  </apex:pageBlockSection>
</apex:pageBlock>

 

Kiru535Kiru535

Hi,

Above code not working. you have hardcoded the values. as part of my requirement I have more that 20 lookup values. For each lookup we have to display different set of values.

 

Can you provide me the exact solution.

 

Regards,

Kiran

sukanth rsukanth r
Hi Kiran ,

Are able to implement this requirement , i am also having the same requirement, if u have done requirement please help me on this.

Regards,
Sukanth