function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Please refer the below code:
trigger OppShare on Opportunity (after update) {
Set<Id> uId = new Set<Id>();
set<Id> OId = new set<Id>();
for(Opportunity Oppo : Trigger.New)
{
if(Oppo.StageName != 'Closed Won')
{
uId.add(Oppo.OwnerId);
OId.add(Oppo.Id);
}
}
List<Opportunity> oppList= [Select Id,Name from Opportunity where Id =: OId];
system.debug(oppList);
List<OpportunityShare> oppShareList = new List<OpportunityShare>();
User usr = [Select Id,name,ManagerId from user where Id = : uId];
system.debug(usr);
for(Opportunity opp : oppList) {
OpportunityShare oppShare = new OpportunityShare();
oppShare.OpportunityAccessLevel = 'Edit';
oppShare.OpportunityId = opp.Id;
oppShare.UserOrGroupId = usr.ManagerId;
oppShareList.add(oppShare);
}
insert oppShareList;
}
Can you please Let me know if it works or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj