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
bathybathy 

Opportunity Validation rules

Hi All,


Can we use validation rules to make field available for user when the stage of an opportunity is changed? For example, User needs to enter comments particular to that stage change when they change it from "In discussion" to "WON". Like wise for every stage change they record in salesforce, they have to add some comments in the newly avaiable text area.

Can this be achieved?

Best Answer chosen by bathy
Vinit_KumarVinit_Kumar
You should use rendered attribute which would make the text box  visible only on conditions,something like below :-

<apex:page standardController="Opportunity">
<apex:form> 
<apex:inputText value = "<Your Text>" id="theText" rendered = "{!If(Opportunity.StageName='Closed Won',true,false)}" /> // This woulld make the text box visible only if the Opp stage name is Closed won
</apex:form> 
<apex:page>

If this helps,please mark it as best answer to help others :)

All Answers

AshlekhAshlekh
Hi,

If you want to show field based on picklist values then It is not possible for native opportunity page. Yes you can apply validation on that field which you want required on particular value by validation rule.
If you want to to show field on a particular value then you have two option.
1) Create your own VFP. and apply condaiton on elements.
2) Create a record type on opportunity. when value of picklist change the update record type and based on record type you can apply the different page layout so in new layout you can remove or add the extra fields

Please mark it a solution if it helps you and ENJOY APEX.
bathybathy
Thanks for your reply Ashlekh.

We already have 8 opportunity record types and this must be implemented on all the record types. Can you please provide me with some code as a start off
Thanks,
Vinit_KumarVinit_Kumar
The way I would approach is to have validation rules which would check if Opportunity Stagname has been changed ,then throw an erro of the corresponding text field is blank.Something like below :-

AND( PRIORVALUE( StageName ) <> StageName , ISPICKVAL( StageName , "Closed Won"),ISBLANK(<Your Text Field>) )

If this helps,please mark it as best answer to help others :)
bathybathy
thanks VInit. My requirement here is to make another text box available each time the user changes the stage and ask them to updtae that text box. I think this can be achieved by visualforce pages. I dont have expertise in that. Can you guys help me with some code?
Vinit_KumarVinit_Kumar
You should use rendered attribute which would make the text box  visible only on conditions,something like below :-

<apex:page standardController="Opportunity">
<apex:form> 
<apex:inputText value = "<Your Text>" id="theText" rendered = "{!If(Opportunity.StageName='Closed Won',true,false)}" /> // This woulld make the text box visible only if the Opp stage name is Closed won
</apex:form> 
<apex:page>

If this helps,please mark it as best answer to help others :)
This was selected as the best answer
bathybathy
Thanks for your help VInit. I will start creating a visual force page.