Print this page

To get "probability" field values assigned automatically when selecting "Stage" field on opportunity through VF page.

Knowledge Article Number 000152610
When selecting the "Stage" field on Opportunity record , "probability" field get values automatically on standard detail page .
But when using inputField in VF page; it do not gives the values automatically .
<apex:page standardController="Opportunity">
<apex:inputField value="{!Opportunity.StageName}"/>
<apex:inputField value="{!Opportunity.Probability}"/>
"OpportunityStage" object represents a value in the opportunity stage picklist & provides additional information about the stage of an Opportunity, such as its probability or forecast category.
Please follow the below mentioned code for implementing this work in VF page :- 
<apex:page standardController="Opportunity">
<script src="" />
<script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
sforce.connection.sessionId = "{!$Api.Session_ID}";
function processChange(){
var obj = document.getElementById('{!$Component.frm.stageFieldId}');
var p = document.getElementById('{!$Component.frm.probabilityFieldId}');
var qr = sforce.connection.query("Select DefaultProbability From OpportunityStage where MasterLabel = '" + $(obj).val() + "'") ; 
records = qr.getArray("records");
for (var i=0; i< records.length; i++) {
var record = records[i];
return true;
<apex:form id="frm">
<apex:inputField value="{!Opportunity.StageName}" onchange="processChange()" id="stageFieldId" />
<apex:inputField value="{!Opportunity.Probability}" id="probabilityFieldId"/>
NOTE :- You can directly copy/save this code without any modifications, however this is a sample code, kindly modify it according to your requirement.
Please refer to below mentioned link to know more about this object.

promote demote