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
KRISH9KRISH9 

Iterating Group standard object records in salesforce

The following in the SOQL query for Users

 

List<User> u = [SELECT Id FROM User];

 

Am able to get the id to iterate. Now i would like to get the id of Group standard object

List<Group> g = [SELECT Id FROM Group];

 

List<EntitySubscription>   es1 = [select Id from  EntitySubscription where SubscriberId =: j and ParentId NOT IN :usr ]; 

 

am retriving all entity subscriptions whose subscriber id not in the list of users. It is working fine. Now i want to retrive the entity subscriptions whose subscriber id not in the group also. For that i am writing the query like as above 

 

List<EntitySubscription>   es1 = [select Id from  EntitySubscription where SubscriberId =: j and ParentId NOT IN :grp ]; 

 

Am getting the following error. 

 

Error: AutoDeleteSubscriptions2 Compile Error: Invalid bind expression type of SOBJECT:Group does not match domain of foreign key

 

Please any one can help me on this how to retrive the entity subscriptions whose subscriber id not in the group.

 

 

 

 

 

MotiMoti

Can you post the whole code block ?

KRISH9KRISH9


public class AutoDeleteSubscriptions2
{
public List<User> usr ;
public List<EntitySubscription> es ;
public Map<String,ID> m1 = new Map<String,ID>();
public Map<String,ID> m2 = new Map<String,ID>();
public List<EntitySubscription> lest;
public List<EntitySubscription> es1;
public List<EntitySubscription> es2;
public List<Group> grp ;
public void deleteSubscriptions()
{
usr = [SELECT Id FROM User];
es = [SELECT Id,SubscriberId FROM EntitySubscription];

grp = [SELECT Id FROM Group];

System.debug('************GRoup****************'+grp);

System.debug(' Entity Subscription size : '+es.size()+' User Size : '+ usr.size());

for(User u : usr)
{
m1.put(u.Id,u.Id);
}
System.debug('***********User Ids**********'+m1.values()+'*****Map Size****'+m1.size());

System.debug(' Entity Subscription size : '+es.size());

for (EntitySubscription e : es)
{
m2.put(e.SubscriberId,e.SubscriberId);
}

System.debug('*************Entity Subscription User Ids***********'+m2.values()+'*****Map Size****'+m2.size());
// Comparing two map values
Set<String> ls = m1.keySet();

Set<String> ls1 = m2.keySet();
System.debug('**************List Elements*****************'+ls.size()+'*************'+ls1.size());

for (Id i :ls)
{
for ( Id j : ls1)
{
System.debug(' I = '+i +' J = '+j);
if ( i == j)
{
System.debug(' Both are equal ' + i +'***************** '+ j);
List<EntitySubscription> es = [select Id from EntitySubscription where SubscriberId =: j];
System.debug('**************************List Size ***********************'+es.size());

if(es.size() > 20)
{
es1 = [select Id from EntitySubscription where SubscriberId =: j and ParentId NOT IN :usr order by CreatedDate limit 5];
delete es1;
}
}
}
}
}
}

 

In query now i added the user lisr like NOT IN : usr the same way want to check with the group.

KRISH9KRISH9

In the query now i want to retrive all the EntitySubscriptions except the users and group remaining i want to retrive for that am trying put both the lists.

 

NOT IN : usr  and NOT IN : grp

 

for group am getting error please help me out on this.