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
mssfdcmssfdc 

Wild card characters allowed?

In my trigger, I want to check if 'Lead Status' is either 'Closed - Working' or 'Closed - Converted'. If it is, then my custom field is set to true. My following code to check one status works but I don't know how to check for 'Closed - Working' OR 'Closed - Converted'

 

trigger setApntFlag on Lead (before insert, before update) {for (Lead a : Trigger.new) { 
If(a.Status == 'Closed - Converted')
{a.ApmntFlag__c = True;}
else
{a.ApmntFlag__c = False;}
}
}

iBr0theriBr0ther

I wonder if you could use OR in the if statement:

 

If(a.Status == 'Closed - Converted' || a.Status == 'Closed - Working' )

 

Cheers,

WesNolte__cWesNolte__c

Hey

 

You could do this:

 

 

trigger setApntFlag on Lead (before insert, before

 update) {for (Lead a : Trigger.new) { 
If(a.Status.contains('Closed'){ // or you could use a.Status.startsWith('Closed')
a.ApmntFlag__c = True;} else {a.ApmntFlag__c = False;} } }

 

This is generally not advised because in future you (or someone else) might be asked to add in another status that also starts with 'Closed' but which requires different logic, either in this trigger or somewhere else in your code that uses similar branching logic. That said it's better to use the @Poorman's approach, but there you should also try to use variable names in your conditions and not hardcoded values, making later maintenance easier.

 

Wes

 

 

David81David81

Would a Workflow Rule + Field Update accomplish the same goal without the need for Apex?