+ Start a Discussion
Erik LarameeErik Laramee 

Expecting right square bracket error

Hi Folks, I am trying to modify a class to include and additional profile (profile name is Procurement). This is the snippet I am attempting to modify.
        profiles = [select Id from Profile where Id = :Userinfo.getProfileId() and  Name = 'Engineering- Apps Engineer'];
        return !profiles.isEmpty();

I append ,'Procurement' to the line as such:
        profiles = [select Id from Profile where Id = :Userinfo.getProfileId() and  Name = 'Engineering- Apps Engineer','Procurement'];
        return !profiles.isEmpty();

But I get the error: Error: Compile Error: expecting right square bracket, found ',' at line 72 column 119. Can someone help me out with what I'm missing here? Thanks!
Best Answer chosen by Erik Laramee
Mahesh DMahesh D
profiles = [select Id from Profile where Id = :Userinfo.getProfileId() and Name IN ( 'Engineering- Apps Engineer','Procurement')];

All Answers

Mahesh DMahesh D
You have to use the "IN" operator.
venkat-Dvenkat-D
try 
profiles = [select Id from Profile where Id = :Userinfo.getProfileId() and  (Name= 'Engineering- Apps Engineer' OR NAME ='Procurement')];
Mahesh DMahesh D
profiles = [select Id from Profile where Id = :Userinfo.getProfileId() and Name IN ( 'Engineering- Apps Engineer','Procurement')];
This was selected as the best answer
Mahesh DMahesh D
Hi Eric,

We can use both IN and OR operators but using the IN operator is more appropriate than OR operator.

Regards,
Mahesh
Ansh CoderAnsh Coder
Hi,
you cannot provide multiple values in name
set <string> profile_names =new set<string>();
profile_names.add('Engineering- Apps Engineer');
profile_names.add('Procurement');
 profiles = [select Id from Profile where Id = :Userinfo.getProfileId() and  Name IN:profile_names];

 
Erik LarameeErik Laramee
Thanks for all the suggestions. I tried the IN operator first and that worked for me.