+ Start a Discussion
Sascha DeinertSascha Deinert 

Depending Field in List with edit mode

Hi,

I have a list of all open opportunities and the possibility to edit the list. Also I have the depending field recordtype (product) connected with stagename. If I change the recordtype the picklist of stages should update. But if I change the recordtype the stagenames updates not very well.

Thanks,
Sascha
 
<apex:page controller="depen001class">

<apex:form>
<apex:outputpanel id="oppOppList">
<apex:pageblock title="Opportunities" id="pbOpp" mode="inlineEdit">
    <apex:pageBlockButtons location="top">
    </apex:pageBlockButtons>
    <apex:outputtext style="font-size:12pt; font-weight: bold" value="open Opportunities"/>
    <apex:pageblocktable value="{!OppList2}" title="open Opportunities" var="Opp">
        <apex:column headervalue="LINK"> <apex:outputLink target="_blank" value="/{!Opp.Id}">Details</apex:outputLink> </apex:column>
        <apex:column headervalue="Name"> <apex:inputfield value="{!Opp.Name}" required="true"/> </apex:column>    
        
        <apex:column headervalue="Product">
            <apex:selectList value="{!SelectedRType}" size="1" multiselect="false" style="width:150px">
                <apex:actionSupport event="onchange" action="{!getStageList}" reRender="StageRefresh"/>
                <apex:selectOptions value="{!RTypeList}" />             
            </apex:selectList>   
        </apex:column>             
        
        <apex:column headervalue="Amount"> <apex:inputfield value="{!Opp.Amount}" required="true"/> </apex:column>
        
        <apex:column headervalue="Stage" id="StageRefresh">
            <apex:selectList size="1" multiselect="false" style="width:150px">
                <apex:selectOptions value="{!StageOptionList}" />             
            </apex:selectList>      
        </apex:column>                         
        
        <apex:column headervalue="Close Date"> <apex:inputfield value="{!Opp.CloseDate}" required="true"/> </apex:column>              
    </apex:pageblocktable>
</apex:pageblock>    
</apex:outputpanel>
</apex:form>

</apex:page>

Public class depen001class {

Public String SelectedRType {get; set;}
Public List <SelectOption> StageOptionList { get; set; }
Public List <Opportunity> OppList1 {get; set;}

Public depen001class () {
    getOppList2();
}

Public List <Opportunity> getOppList2() {
    OppList1 =  [SELECT Id, Name, RecordTypeId, RecordType.Name, Amount, CloseDate FROM Opportunity WHERE AccountId = '001g000000dzT5rAAE' AND IsClosed = false ORDER BY CloseDate DESC];
    RETURN OppList1;    
}

Public pageReference getOppList() {
    getOppList2();     
    RETURN NULL; 
}    

Public List <SelectOption> getRTypeList() {
    List <RecordType > RTypes = [SELECT Id, Name FROM RecordType WHERE sObjectType = 'Opportunity'];
    List <SelectOption> RTypeOptionList = new List <SelectOption>();
    FOR (RecordType R : RTypes) {
        RTypeOptionList.add (new SelectOption(R.Name, R.Name));
    }
    RETURN RTypeOptionList; 
}

Public void getStageList() {
    StageOptionList = new List <SelectOption>();   
        
        IF(SelectedRType == 'EUW') {
            StageOptionList.add (new SelectOption('0', 'PO'));
            StageOptionList.add (new SelectOption('30', 'TE'));
            StageOptionList.add (new SelectOption('50', 'KU'));
            StageOptionList.add (new SelectOption('75', 'AU'));
            StageOptionList.add (new SelectOption('90', 'UM'));
            StageOptionList.add (new SelectOption('100', 'GW'));
            StageOptionList.add (new SelectOption('0', 'GV'));                                                                        
        }
        IF(SelectedRType == 'BU') {
            StageOptionList.add (new SelectOption('0', 'PO'));
            StageOptionList.add (new SelectOption('10', 'TE'));
            StageOptionList.add (new SelectOption('30', 'AU'));
            StageOptionList.add (new SelectOption('70', 'UM'));
            StageOptionList.add (new SelectOption('100', 'GW'));
            StageOptionList.add (new SelectOption('0', 'GV'));  
        }
}


}

 
atla satheeshkumaratla satheeshkumar
Hi Sascha Deinert,

your code is correct just Rearrange Below mentioned 2 lines

your code
---------------

<apex:selectList value="{!SelectedRType}" size="1" multiselect="false" style="width:150px">
<apex:actionSupport event="onchange" action="{!getStageList}" reRender="StageRefresh"/> <apex:selectOptions value="{!RTypeList}" />
</apex:selectList>

Modified code
------------------------

<apex:selectList value="{!SelectedRType}" size="1" multiselect="false" style="width:150px">
<apex:selectOptions value="{!RTypeList}" />
<apex:actionSupport event="onchange" action="{!getStageList}" reRender="StageRefresh"/> 
</apex:selectList>

Please mark it as Corrcet anwswer.

 
Sascha DeinertSascha Deinert
Sorry, but the result is not better.

For example, my list shows three different opportunities, if I change the recordtype from one of the three opps it works, but if I change from an other opp the recordtype it doesn't work anymore.
Neetu_BansalNeetu_Bansal
Hi Sascha,

I found that after changing the record type, you are rendering the colum id i.e. StageRefresh, but in page block tables, as there will be many more columns, so the visualforce page itself append some varibales to the ids, so while reredering, it will not find the exact id. You can rerender the whole panel like:
<apex:page controller="depen001class">
    <apex:form>
        <apex:outputpanel id="oppOppList">
            <apex:pageblock title="Opportunities" id="pbOpp" mode="inlineEdit">
                <apex:pageBlockButtons location="top">
                </apex:pageBlockButtons>
            
                <apex:outputtext style="font-size:12pt; font-weight: bold" value="open Opportunities"/>
                <apex:pageblocktable value="{!OppList2}" title="open Opportunities" var="Opp">
                    <apex:column headervalue="LINK">
                        <apex:outputLink target="_blank" value="/{!Opp.Id}">Details</apex:outputLink>
                    </apex:column>
                    <apex:column headervalue="Name">
                        <apex:inputfield value="{!Opp.Name}" required="true"/>
                    </apex:column>    
                    <apex:column headervalue="Product">
                        <apex:selectList value="{!SelectedRType}" size="1" multiselect="false" style="width:150px">
                            <apex:actionSupport event="onchange" action="{!getStageList}" reRender="oppOppList"/>
                            <apex:selectOptions value="{!RTypeList}" />             
                        </apex:selectList>   
                    </apex:column>             
                    <apex:column headervalue="Amount">
                        <apex:inputfield value="{!Opp.Amount}" required="true"/>
                    </apex:column>
                    <apex:column headervalue="Stage" id="StageRefresh">
                        <apex:selectList size="1" multiselect="false" style="width:150px">
                            <apex:selectOptions value="{!StageOptionList}" />             
                        </apex:selectList>      
                    </apex:column>                         
                    <apex:column headervalue="Close Date">
                        <apex:inputfield value="{!Opp.CloseDate}" required="true"/>
                    </apex:column>              
                </apex:pageblocktable>
            </apex:pageblock>    
        </apex:outputpanel>
    </apex:form>
</apex:page>
Let me know, if you need any other help.

Thanks,
Neetu
Sascha DeinertSascha Deinert
Hi Neetu,

Thanks for your response, this works, but it make no sense to rerender the whole page and adjust all depending fields.
The change of the recordtype in row 1 should change just the stagefield in row 1.

Any other ideas?

Thanks,
Sascha
Neetu_BansalNeetu_Bansal
Hi Sascha,

You can achieve this, but for this you need to either use HTML table or if your values for stage list are constant, you can use javascript too. If you further need my help on this, you can please contact me either on my skype id: neetu.bansal.5 or gmail id: neetu.bansal.5@gmail.com.

If above resolve your problem, you can mark it as best answer.

Thanks,
Neetu