+ Start a Discussion
yvk431yvk431 

restrict picklist values dynamically

Hello Friends,

 

Can any one tell me that the following requirement can be done or not?

 

I have 2 custom objects Company, Contacts. In the Contacts object I have  a custom picklist ContactName

consists of names like 'CEO','Manager','employee'

 

The thing is while creating contacts for a single company , i need the users to select the ContactName 'CEO' only for one time. I do not want to use Apex class to save the records, using the native save functionality can we achieve this kind of functionality.

 

Please let me know,

 

 

Thanks,

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
jpizzalajpizzala
Use an Apex trigger on before insert/update that checks to see if a Contact already exists with CEO as the ContactName.  If the new record also specifies CEO as the ContactName, you can prevent this record from being inserted by throwing an error on the record, thus preventing it from being saved to Salesforce.  This will be reflected as a red message at the top of the record the user is trying to create.  It helps to add a meaningful message to the error (something like "A CEO has already been created for this company." or something like that) so the user is aware of the exact reason why they cannot save the record.