+ Start a Discussion
PS81PS81 

Picklist event : ActionSupport doesn't work

Hi

I have a picklist in my VF page and have set an event.....based on the value that is picked i need to set a percentage field with some value which i think is not happeing....i'm sure there is something i'm missing and need help to fix it please?

my vf code:

            <apex:inputfield value="{!Opportunity.StageName}" >
                <apex:actionSupport id="oprstage" event="onchange" action="{!setProbability}" rerender="productInfo" immediate="TRUE" />
            </apex:inputfield>
            <apex:inputfield value="{!Opportunity.Day_Rate__c}" id="oprrate"/>
            <apex:inputfield value="{!opr.Probability}" id="oprprob"/>

controller:

public with sharing class OpportunitySave {
    public string probability {get;set;}
    public Opportunity opr {get;set;}
    public OpportunitySave(ApexPages.StandardController controller) {

    }
    public PageReference setProbability(){
        opr.Probability = '30%';
        return null;
    }
}
Best Answer chosen by PS81
PS81PS81
used jquery to fix it...fpor reference:
 
function setProb(input){
     var stage =  input.value;
     if (stage == 'Suspect/Prospect') jQuery( '[id$=oprprob]' ).val(0);
     if (stage == 'Opportunity Identified') jQuery( '[id$=oprprob]' ).val(10);
     if (stage == 'Opportunity Qualified') jQuery( '[id$=oprprob]' ).val(20);
     if (stage == 'Proposal Submitted') jQuery( '[id$=oprprob]' ).val(30);
     if (stage == 'Shortlisted') jQuery( '[id$=oprprob]' ).val(40);
     if (stage == 'Preferred Bidder') jQuery( '[id$=oprprob]' ).val(60);
     if (stage == 'Indication to go ahead') jQuery( '[id$=oprprob]' ).val(80);
     if (stage == 'Closed Won') jQuery( '[id$=oprprob]' ).val(100);
     if (stage == 'Closed Lost') jQuery( '[id$=oprprob]' ).val(0);
     if (stage == 'Opportunity Identified (IC Only)') jQuery( '[id$=oprprob]' ).val(30);
     if (stage == 'Opportunity Qualified (IC Only)') jQuery( '[id$=oprprob]' ).val(40);
     if (stage == 'Proposal Submitted (IC Only)') jQuery( '[id$=oprprob]' ).val(70);
     if (stage == 'Won not signed (IC only)') jQuery( '[id$=oprprob]' ).val(95);   
     //oprstage();
    }

apex code:

<apex:inputfield value="{!Opportunity.StageName}" onChange="setProb(this)" required="true" >


 

All Answers

Arunkumar RArunkumar R
Hi Prabhu,

Remove  immediate="TRUE" attribute in actionsupport and rerender the correct block id. If not this works, share your code.
PS81PS81
thanks arun, what wud typically gointo the rerender ? i'm bit confused with that...any help on it please?
Arunkumar RArunkumar R
Rerender used to render a particular region instead of whole page refresh. 

You can have a below example, this will give you a clear thought.

http://www.cloudforce4u.com/2013/07/render-and-rerender-in-salesforce.html
PS81PS81
tried it but getting an error in VF page:


System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!setProbability}' in page opportunitysave: Class.OpportunitySave.setProbability: line 8, column 1
Class.OpportunitySave.setProbability: line 8, column 1
Arunkumar RArunkumar R
could you share your code?
 
PS81PS81
standard controller class is:

public with sharing class OpportunitySave {
    public string probability {get;set;}
    public Opportunity opr {get;set;}
    public OpportunitySave(ApexPages.StandardController controller) {

    }
    public PageReference setProbability(){
        Opportunity.Probability = 30;
        return null;
    }
}


VF page:

<apex:page standardController="Opportunity" tabStyle="Opportunity" extensions="OpportunitySave" >
<apex:form >
<body>
    <apex:pageBlock title="Opportunity Edit" mode="edit"  >
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save" />
            <apex:commandButton action="{!Cancel}" value="Cancel"/>
        </apex:pageBlockButtons>
        <apex:pageblocksection id="OprInfo" title="Opportunity Information" columns="2">
            <apex:inputfield value="{!Opportunity.name}" id="oprname"/> 
            <apex:inputfield value="{!Opportunity.AccountId}" id="opraccname"/> 
            <apex:inputfield value="{!Opportunity.Business__c}" id="oprbusiness"/>
            <apex:outputfield value="{!Opportunity.OwnerId}" id="oprOwner"/>
            <apex:inputfield value="{!Opportunity.Area__c}" id="oprarea"/>
            <apex:inputfield value="{!Opportunity.Opportunity_Team__c}" id="oprteam"/>
            <apex:inputfield value="{!Opportunity.New_Ext__c}" id="oprnewext"/>
            <apex:inputfield value="{!Opportunity.Practice_Director__c}" id="oprpractdirect"/>
            <apex:inputfield value="{!Opportunity.Type}" id="oprType"/>
            <apex:inputfield value="{!Opportunity.CloseDate}" id="oprCloseDate"/>
            <apex:inputfield value="{!Opportunity.Base_Location__c}" id="oprloc"/>
            <apex:inputfield value="{!Opportunity.Start_Date__c}" id="oprsdate"/>
            <apex:inputfield value="{!Opportunity.Presales__c}" id="oprpresales"/>
            <apex:inputfield value="{!Opportunity.Number_of_Days__c}" id="oprndays"/>
            <apex:inputfield value="{!Opportunity.StageName}" >
                <apex:actionSupport id="oprstage" event="onchange" action="{!setProbability}" rerender="OprInfo"  />
            </apex:inputfield>
            <apex:inputfield value="{!Opportunity.Day_Rate__c}" id="oprrate"/>
            <apex:inputfield value="{!Opportunity.Probability}" id="oprprob"/>
            <apex:inputfield value="{!Opportunity.CampaignId}" id="oprcamp"/>
            <apex:inputfield value="{!Opportunity.Closed_Lost__c}" id="oprcloselot"/>            
            <apex:outputText ></apex:outputText>
            <apex:inputfield value="{!Opportunity.Reason_for_Lost__c}" id="oprlostreason" style="width:250px ; height:100px"/>        
         </apex:pageblocksection>
    </apex:pageBlock>
</body>
</apex:form>
</apex:page>
PS81PS81
anything to be amended in the code?
Arunkumar RArunkumar R
Prabhu,

Here is the updated code,

VF:
 
<apex:page standardController="Opportunity" tabStyle="Opportunity" extensions="OpportunitySave" >
<apex:form >
    <apex:pageBlock title="Opportunity Edit" mode="edit"  >
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save" />
            <apex:commandButton action="{!Cancel}" value="Cancel"/>
        </apex:pageBlockButtons>
        <apex:pageblocksection id="OprInfo" title="Opportunity Information" columns="2">
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.name}" id="oprname"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.AccountId}" id="opraccname"/> 
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.Business__c}" id="oprbusiness"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:outputfield value="{!Opportunity.OwnerId}" id="oprOwner"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.Area__c}" id="oprarea"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.Opportunity_Team__c}" id="oprteam"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.New_Ext__c}" id="oprnewext"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.Practice_Director__c}" id="oprpractdirect"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
            <apex:inputfield value="{!Opportunity.Type}" id="oprType"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
            <apex:inputfield value="{!Opportunity.CloseDate}" id="oprCloseDate"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.Base_Location__c}" id="oprloc"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
            <apex:inputfield value="{!Opportunity.Start_Date__c}" id="oprsdate"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.Presales__c}" id="oprpresales"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.Number_of_Days__c}" id="oprndays"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
			<apex:actionRegion>
            <apex:inputfield value="{!Opportunity.StageName}">
                <apex:actionSupport id="oprstage" event="onchange" action="{!setProbability}" rerender="OprInfo"  />
            </apex:inputfield>
			</apex:actionRegion>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
			   <apex:inputfield value="{!Opportunity.Day_Rate__c}" id="oprrate"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.Probability}" id="oprprob"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
			   <apex:inputfield value="{!Opportunity.CampaignId}" id="oprcamp"/>
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.Closed_Lost__c}" id="oprcloselot"/> 
			</apex:pageBlockSection>
			
			<apex:pageBlockSection>
				<apex:inputfield value="{!Opportunity.Reason_for_Lost__c}" id="oprlostreason" style="width:250px ; height:100px"/> 
			</apex:pageBlockSection>
			
         </apex:pageblocksection>
    </apex:pageBlock>
</apex:form>
</apex:page>

class:
 
public with sharing class OpportunitySave {
    public string probability {get;set;}
    public Opportunity opr {get;set;}
    public OpportunitySave(ApexPages.StandardController controller)
    {
        opr = (Opportunity)controller.getRecord();

    }
    public PageReference setProbability(){
        opr.Probability = 30;
        return null;
    }
}

 
PS81PS81
used jquery to fix it...fpor reference:
 
function setProb(input){
     var stage =  input.value;
     if (stage == 'Suspect/Prospect') jQuery( '[id$=oprprob]' ).val(0);
     if (stage == 'Opportunity Identified') jQuery( '[id$=oprprob]' ).val(10);
     if (stage == 'Opportunity Qualified') jQuery( '[id$=oprprob]' ).val(20);
     if (stage == 'Proposal Submitted') jQuery( '[id$=oprprob]' ).val(30);
     if (stage == 'Shortlisted') jQuery( '[id$=oprprob]' ).val(40);
     if (stage == 'Preferred Bidder') jQuery( '[id$=oprprob]' ).val(60);
     if (stage == 'Indication to go ahead') jQuery( '[id$=oprprob]' ).val(80);
     if (stage == 'Closed Won') jQuery( '[id$=oprprob]' ).val(100);
     if (stage == 'Closed Lost') jQuery( '[id$=oprprob]' ).val(0);
     if (stage == 'Opportunity Identified (IC Only)') jQuery( '[id$=oprprob]' ).val(30);
     if (stage == 'Opportunity Qualified (IC Only)') jQuery( '[id$=oprprob]' ).val(40);
     if (stage == 'Proposal Submitted (IC Only)') jQuery( '[id$=oprprob]' ).val(70);
     if (stage == 'Won not signed (IC only)') jQuery( '[id$=oprprob]' ).val(95);   
     //oprstage();
    }

apex code:

<apex:inputfield value="{!Opportunity.StageName}" onChange="setProb(this)" required="true" >


 
This was selected as the best answer