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
Jason FeldmanJason Feldman 

Make a field requirement dependent on a picklist value

I have a new field I created called Client lead Source.  I would like to name that field required based on 2 other picklist fields called "Primary Lead Source" and "Secondary Lead Source".  Once the picklist value for both is equal to "Client", this new field would be required.  I am not exactly sure how to accomplish this.
Cyrus TalladenCyrus Talladen
How I would implement this requirement is this:
1) Make a page that behaves such that when the record updates the FieldSet attributes of the custom field will be changed to required.  See docs : 

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_fieldsets_describe.htm

2) When the trigger executes ensure that the picklist values of the fields Primary Lead Source and  Secondary Lead Source are checked. 

example: 
List<Schema.FieldSetMember> myfield = [select Id, 
Lead Source__c , Lead Source__c from myObject where Id =:Id ];

if( myfield.Primary Lead Source__c.getDescribe.getValue() == "Client" && 
myfield.Secondary Lead Source__c == "Client){

field.required = true;field.dbrequired = true

}



Cyrus Talladen
CRM Engineer
www.levementum.com
Jason FeldmanJason Feldman
Can I just use a field validation for this or is this the only way?
Cyrus TalladenCyrus Talladen
What the requirement calls for is beyond the capability of a validation rule.  You may research if workflow rules can work but I doubt that the required attribute of a field will be accessible

Cyrus T
www.levementum.com
jwalshjwalsh
Why can't a validation rule handle this?

not(
and(
ispickval(Primary_Lead_Source__c, "Client"),
ispickval(Secondary_Lead_Source__c,"New Business"),
isblank(text(Client_Lead_Source__c))
))
Jason FeldmanJason Feldman
I used this rule:
not(
and(
ispickval(Lead_Sources__c, "Client"),
ispickval(Secondary_Lead_Source__c,"Client"),
isblank(text(Client_Lead_Source__c))
))

And then I get this error since Client Lead Source is a text area:

Error: Incorrect parameter type for function 'text()'. Expected Number, Date, DateTime, Picklist, received Text
jwalshjwalsh
In that case you can just say isblank(Client_Lead_Source__c)