You need to sign in to do that
Don't have an account?
Abraham Durojaiye
How do I create an Apex Trigger to make a custom field in Contacts mandatory to fill out when a specific relationship type is selected?
Hi,
Still getting my feet wet with the developer thing, so I am not sure where to start on this one.
I have a custom lookup field in my Contacts object called Relationship Manager, which is manually populated with a user name. I also have a custom picklist(multi select) field called Relationship Type, which includes Donor and Board Member as choices.
I want a trigger that will make the Relationship Manager field mandatory to populate by the user when either the Donor and/or Board Member types are selected.
Thanks
Still getting my feet wet with the developer thing, so I am not sure where to start on this one.
I have a custom lookup field in my Contacts object called Relationship Manager, which is manually populated with a user name. I also have a custom picklist(multi select) field called Relationship Type, which includes Donor and Board Member as choices.
I want a trigger that will make the Relationship Manager field mandatory to populate by the user when either the Donor and/or Board Member types are selected.
Thanks
Sorry, my fault! Try this:
AND (
OR( INCLUDES(relationship_type__c, "Donor"), INCLUDES(relationship_type__c, "Board Member") ), ISBLANK(relationship_manager__c)
)
All Answers
Why do you want to use a trigger for this?
I would go for a validation rule on the object.
Make the condition
OR( INCLUDES(relationship_type__c, "Donor"), INCLUDES(relationship_type__c, "Board Member") )
INCLUDES(multiselect_picklist_field, text_literal) Determines if any value selected in a multi-select picklist field equals a text literal you specify.
When this returns TRUE the error message will be displayed.
Try with below code it will helps !! Replace your field api name as per your org !!
Let me know if it helps !!
Thanks
Manoj
The validation rule you sent me worked. The only issue I am seeing now is that even though I insert a Relationship Manager, the record still does not save and still gives the error message to insert a Relationship Manager.
I attached a screenshot of the validation rule I set up
Once a Relationship Manager has been populated, the record sould be able to be saved.
Please advise.
I tried the Apex Trigger you sent me and got an error message about the OR operator only being able to be applied to Boolean expressions.
See below:
In the if condition replace =with == ,means Relationship_Type__c=='Donar;Board member'
Sorry, my fault! Try this:
AND (
OR( INCLUDES(relationship_type__c, "Donor"), INCLUDES(relationship_type__c, "Board Member") ), ISBLANK(relationship_manager__c)
)