Skip to main content
trigger Autounfollowopp on Opportunity (after insert,after update) {

 

set<id> oppid = new set<id>();

 

    for(opportunity opp:trigger.new){

 

        if(opp.StageName=='closed won')

 

            oppid.add(opp.Id);

 

           }

 

    list<opportunity> opportunity=[select id, createdby.name from opportunity where id in:oppid];

 

    

 

    for(user users : [select id from user ])

 

        {

 

          EntitySubscription[] followingES = [select id, parentid, subscriberid, parent.name from EntitySubscription where subscriberid = :users.id];

 

            Map<string,string> following = new Map<string,string> ();

 

            for( EntitySubscription Entitysub : followingES )

 

            following.put( Entitysub.parentid, Entitysub.parent.name );  

 

             If(opportunity [0].createdby.name == 'xxxx'

 

                    {

 

                    EntitySubscription follow = new EntitySubscription (parentId <>:opportunity [0].id,subscriberid = users.id);

 

                    delete follow;

 

                    }

 

      }

 

        

 

}
4 answers
0/9000