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
RstrunkRstrunk 

SOQL Query

I need to create a soql query that will query the AccountShare object and return any records that have related users that are not assigned to specific profiles.  The profile IDs are 00eE0000000d2WD , 00eE0000000dh09 , 00eE0000000eQAK.

 

Any thoughts on how to do this?

 

 

 

 

Sfd developerSfd developer

Hi,

 

Set<Id> profileIds = new Set<Id>{'00eE0000000d2WD','00eE0000000dh09','00eE0000000eQAK'};
List<AccountShare> accShareList = [SELECT Id FROM AccountShare WHERE UserOrGroupId IN: [SELECT Id User WHERE ProfileId NOT IN:profileIds]];

RstrunkRstrunk

Thanks for the quick response.

 

   I get an error when trying to post that code in a trigger.  The second WHERE clause is what it doesn't like.

 

Error: Compile Error: unexpected token: WHERE at line 4 column 104

Avidev9Avidev9

Try this

 

List<AccountShare> accShareList = [SELECT Id FROM AccountShare WHERE UserOrGroupId IN: [SELECT Id FROM User WHERE ProfileId NOT IN('00eE0000000d2WD','00eE0000000dh09','00eE0000000eQAK')];

 

ryanjuptonryanjupton

There was a typo in the response. try:

 

Set<Id> profileIds = new Set<Id>{'00eE0000000d2WD','00eE0000000dh09','00eE0000000eQAK'};
List<AccountShare> accShareList = [SELECT Id FROM AccountShare WHERE UserOrGroupId IN: [SELECT Id from User WHERE ProfileId NOT IN:profileIds]];