You need to sign in to do that
Don't have an account?
Tatiana Cooke 9
Problem with trigger to give read write access to opportunity team member
Team,
I thought this trigger was working and I dont know how it is not now. When the secondary owner lookup field is populated on the opportunity I need it to create an opportunity with read write access.
it is only giving the users Read Only access.
Appreciate any help
I thought this trigger was working and I dont know how it is not now. When the secondary owner lookup field is populated on the opportunity I need it to create an opportunity with read write access.
it is only giving the users Read Only access.
Appreciate any help
trigger OTOpportunityTrigger on Opportunity (before update) { List<OpportunityTeamMember> listOpptyTeamMem = new List<OpportunityTeamMember>(); Set<Id> OpptyIdSet = new Set<Id>(); for(Opportunity oppty : trigger.New) { //Checking Oppty SecondaryOwner if(oppty.Secondary_Owner__c != null) { OpportunityTeamMember OTM = new OpportunityTeamMember(); OTM.OpportunityId = oppty.Id; OTM.TeamMemberRole = 'Secondary Owner'; OTM.UserId = oppty.Secondary_Owner__c; listOpptyTeamMem.add(OTM); } } if(listOpptyTeamMem.size() > 0) { insert listOpptyTeamMem; // get all of the team members' sharing recordsPost to Community List<OpportunityShare> shares = [select Id, OpportunityAccessLevel, RowCause from OpportunityShare where OpportunityId IN : OpptyIdSet and RowCause = 'Team']; // set all team members access to read/write for (OpportunityShare share : shares) share.OpportunityAccessLevel = 'Edit'; update shares; } }
You are not adding any Id in OpptyIdSet. So, when you are query at OpportunityShare, you are getting 0 list.
The following error is related to the test class associated. I am gettin INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY on insert O;
Please help!
First please do not use hardcoded record Id. if you move them to different region, this will always error out. Like o.Accountid=a.id; as you already created account. Same ways please create two user data one for each o.OwnerId & o.Secondary_Owner__c. Create data for Unit_Number__c and use those Id's from test data.
I created the following in order to mittigate that. But now I get the error, "invalid u.id"!
o.ownerid=u.id;
similarly:
o.accountid=a.id;