I have a query that checks if a custom button is clicked by the record Owner or a Salesforce Admin if not throw an error message. My code is below:
List<Opportunity> opportunityList = new List<Opportunity>([select Id from Opportunity where ID=:System.currentPageReference().getParameters().get('Id') and OwnerId=:UserInfo.getUserId()]);
My current code check if the user is the owner of the record. Now I want to check if the user is also an Administrator. I want to check the ProfileId and check if it matches the Admin Profile Id.
Get the Admin ID: String adminId = [Select Id from Profile where Name='System Administrator'];
Add to Query: UserInfo.getProfileId() = :adminId does not seem to work when I do the following:
List<Opportunity> opportunityList = new List<Opportunity>([select Id from Opportunity where ID=:System.currentPageReference().getParameters().get('Id') and (OwnerId=:UserInfo.getUserId() or UserInfo.getProfileId()=:adminId)]);
I also tried :UserInfo.getProfileId()=:adminId does not seem to work
Any suggestions?