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
Vegaln1Vegaln1 

Using a Like statement within if a trigger issue

I would like to use a if statement in a trigger that checks if the User Profile is like 'ABC Customer Portal'. The following snippet doesn't like the use of the 'Like' keyword. I have also tried  ' += ' but that results in a error that 'And can be used only with boolean expressions'.

 

What is the proper syntax for using a like contition withn a If statement?

 

Regards,

 

String pf = u.ProfileId; Profile pfName = [select Name from profile where id = :pf]; String UserId = u.Id; if (contactId!=null && contactId!='' && (pfName.Name LIKE '%ABC Customer Portal%')) { . . . }

 

Best Answer chosen by Admin (Salesforce Developers) 
CaptainObviousCaptainObvious

Try the contains String method instead:

String pf = u.ProfileId; Profile pfName = [select Name from profile where id = :pf]; String UserId = u.Id; String profName = pfName.Name; String abcPortal = 'ABC Customer Portal'; if (contactId!=null && contactId!='' && profName.contains(abcPortal)) { . . . }

 

All Answers

CaptainObviousCaptainObvious

Try the contains String method instead:

String pf = u.ProfileId; Profile pfName = [select Name from profile where id = :pf]; String UserId = u.Id; String profName = pfName.Name; String abcPortal = 'ABC Customer Portal'; if (contactId!=null && contactId!='' && profName.contains(abcPortal)) { . . . }

 

This was selected as the best answer
Vegaln1Vegaln1
Excellent. Thank you for your prompt reply. Works great.