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
Tarun KaushikTarun Kaushik 

How to make a field mendatory when a field(picklist) on the same object change.

Hi All
I have two field on same object
1 -status(picklist values-opened,pending,resolved,closed)
2 -notes
If status="pending" then notes field should become mendetory on the spot without any other action,just an update on status field.
or 
if status="closed" then some other fields should become mendatory on the spot 

 
BalajiRanganathanBalajiRanganathan
1) Add validation rule, this will ensure data integrity if the reocord is created using APIs
2) use, Visualforce Ajax Support to rerender the section with the fields required. basically you have to use apex:actionRegion and apex:actionSupport

Below is the sample, you can refer, it is a template, you have replace <object> etc.
<apex:outputPanel id="MyPanel">
 <apex:actionRegion >
<apex:pageblockSectionItem > <apex:outputLabel value="{!$ObjectType.<object>.Fields.<picklistfield>.label}" /><apex:inputField required="true" value="{!<object>.<picklistfield>}"><apex:actionSupport event="onchange" rerender="MyPanel" oncomplete="setDefaultCountry()"/></apex:inputField>  </apex:pageblockSectionItem>

<apex:pageblockSectionItem required="{!IF(<object>.<picklistfield> = 'pending', true, false)}"> <apex:outputLabel value="{!$ObjectType.<object>.Fields.<otherfield>.label}" /> <apex:inputField id="opportunity" required="true" value="{!<object>.<otherfield>}"/> </apex:pageblockSectionItem>
</apex:actionRegion>
</apex:outputPanel>
 
Geoffrey J FlynnGeoffrey J Flynn
For this you want a validation rule I think.  To expand on Balaji,
Error Message for Validation Rule:

OR
(
ISPICKVAL(Status, "pending")
&&
ISBLANK(Notes)
)
,
(
ISPICKVAL(Status, "Closed")
&&
ISBLANK(Some_other_field__c)
)

Don't forget to check that it's actually working as well, with both positive and negative tests