You need to sign in to do that
Don't have an account?

Multiselect picklist field should throw error!
1) There is a multiselect picklist field 'BU_Specialty_Name__c' with values "A","B","C" & "R". The condition is that, If user selects any value along with "R", an error should occur saying that 'R should be selected alone'. For this I have implemented a Validation rule as below:
IF(OR(AND(INCLUDES(BU_Specialty_Name__c,"R"),INCLUDES( BU_Specialty_Name__c,"A")),
AND(INCLUDES(BU_Specialty_Name__c,"R"),INCLUDES( BU_Specialty_Name__c,"B")),
AND(INCLUDES(BU_Specialty_Name__c,"R"),INCLUDES( BU_Specialty_Name__c,"C"))
),
true, false)
It is working fine for the environment(Sandbox) which has "A","B","C"&"R" values for 'BU_Specialty_Name__c'.
2) But now, the requirment is that, For the other environment(Prod), 'BU_Specialty_Name__c' has few more values "A","B","C","D", "E" & "R".
Here also same condition should be given that is, If user selects any value along with "R", an error should occur.
And we cannot overwrite Validation rule depending upon environment always.
So,Is there any alternative to throw an error When user selects any value along with "R", instead of calling all the values as I did above?
The idea should work for all environments independant on other multiselect picklist values.
Any kind of suggestion is accepted. Thanks in advance!
IF(OR(AND(INCLUDES(BU_Specialty_Name__c,"R"),INCLUDES( BU_Specialty_Name__c,"A")),
AND(INCLUDES(BU_Specialty_Name__c,"R"),INCLUDES( BU_Specialty_Name__c,"B")),
AND(INCLUDES(BU_Specialty_Name__c,"R"),INCLUDES( BU_Specialty_Name__c,"C"))
),
true, false)
It is working fine for the environment(Sandbox) which has "A","B","C"&"R" values for 'BU_Specialty_Name__c'.
2) But now, the requirment is that, For the other environment(Prod), 'BU_Specialty_Name__c' has few more values "A","B","C","D", "E" & "R".
Here also same condition should be given that is, If user selects any value along with "R", an error should occur.
And we cannot overwrite Validation rule depending upon environment always.
So,Is there any alternative to throw an error When user selects any value along with "R", instead of calling all the values as I did above?
The idea should work for all environments independant on other multiselect picklist values.
Any kind of suggestion is accepted. Thanks in advance!
You may probably want to move this validation to a trigger as shown here
trigger AccountTrigger on Account (before insert, before update) {
List<Account> accountList = trigger.new;
for(Account accObj:accountList){
Set<String> tempSet = new Set<String>(accObj.BU_Specialty_Name__c.split(';'));
system.debug('temp string:'+tempSet);
if(tempSet.contains('R') && tempSet.size()>1){
accObj.BU_Specialty_Name__c.addError('R should be selected alone');
}
}
}
Modify this with your object name and move the logic to an apex class if needed to keep the trigger simple.
All Answers
You may probably want to move this validation to a trigger as shown here
trigger AccountTrigger on Account (before insert, before update) {
List<Account> accountList = trigger.new;
for(Account accObj:accountList){
Set<String> tempSet = new Set<String>(accObj.BU_Specialty_Name__c.split(';'));
system.debug('temp string:'+tempSet);
if(tempSet.contains('R') && tempSet.size()>1){
accObj.BU_Specialty_Name__c.addError('R should be selected alone');
}
}
}
Modify this with your object name and move the logic to an apex class if needed to keep the trigger simple.
In your case, you can get out "R" from multiselect picklist (You can set R as a checkbox or anything else).
Then you can check if R is checked AND picklist is not blank.
With this technique you will be indipendent.
Bye.