You need to sign in to do that
Don't have an account?
Kumar Rao 1
Picklist value check - If statement
Dear Folks,
I'm new bee to salesforce and please help to get me a sample code if possible, as I didn't find it anywhere.
Requirement: I have picklist filed with 2 values (val 1, Val2)
Scenario (trigger):
If (picklist value = 'Val1') {
code here...
}
But I encounter bellow error, can you please suggest.
Error: Compile Error: Comparison arguments must be compatible types: Schema.SObjectField, String at line 5 column 12
I'm new bee to salesforce and please help to get me a sample code if possible, as I didn't find it anywhere.
Requirement: I have picklist filed with 2 values (val 1, Val2)
Scenario (trigger):
If (picklist value = 'Val1') {
code here...
}
But I encounter bellow error, can you please suggest.
Error: Compile Error: Comparison arguments must be compatible types: Schema.SObjectField, String at line 5 column 12
Your code should be something like So here, when a new Account is created I am checking if the Account type is "big", if yes then I am setting a checkbox field "Big_Account__c" to true.
Note: the field names should be the API Names and not labels.
So for me Account Type is a label, whereas the API Name is Account_Type__c.
Hope this helps :)
All Answers
You have to compare with '==' or using string methods
IF(obj.picklistfield=='val1'){
}
OR
IF(obj.picklistfield.equals('val1)){
}
Please share the actual IF statement so that I can help you.
Thanks,
Anjith
Your code should be something like So here, when a new Account is created I am checking if the Account type is "big", if yes then I am setting a checkbox field "Big_Account__c" to true.
Note: the field names should be the API Names and not labels.
So for me Account Type is a label, whereas the API Name is Account_Type__c.
Hope this helps :)
trigger Fund on Parthiv__Fund__c(Before insert, after Insert, before update, After update){
if(Trigger.isbefore){
if(Trigger.isInsert){
for(Parthiv__Fund__c fund : trigger.new){
// if(Parthiv__Fund__c.Parthiv__Fund_Split__c == 'value 1'){
// }
}
}
}
}
if(fund.Parthiv__Fund_Split__c == 'value 1'){
Here I am setting Ownership as 'Public' and Rating as 'Hot' based on Account Industry selection.
All 3 fields (Industry/Ownership/Rating) are Picklist values.
trigger BankingTriggerOnAccount on Account (before insert){
for (Account ac : Trigger.new){
if (ac.Industry.equals('Banking')){
ac.Ownership = 'Public';
ac.Rating = 'Hot';
}
}
}