+ Start a Discussion
KCLKCL 

Give Read/Write Access to Opportunity Members when New new quote is generate for that opportunity.

Give Read/Write Access to Opportunity Members when New new quote is generate for that opportunity.
sowmya Inturi 9sowmya Inturi 9
Hi,
Please try the below code. It worked fine for me.

trigger ChangeAccessOnOppTeamMem on Quote (after insert) {
    if(trigger.isInsert){
        List<Quote> qList = new List<Quote>();
        //   List<OpportunityTeamMember> otmList = new List<OpportunityTeamMember>();
        List<OpportunityShare> otmListUpdate = new List<OpportunityShare>();
    //    Map<OpportunityTeamMember,id> otmMap = new Map<OpportunityTeamMember,id>();
        Set<Id> oIds = new Set<Id>();
        for(Quote q:trigger.new){
            qlist.add(q);
            oIds.add(q.OpportunityId);  
        }
        System.debug('oIds'+oIds);
        if(qList.size()>0){ 
        //    otmList= [select id,OpportunityAccessLevel from OpportunityTeamMember where OpportunityId in: oIds];
            
            
            system.debug('In qList');
            
            List<OpportunityShare> oppShareRecords = [select Id, OpportunityAccessLevel,UserOrGroupId, RowCause from OpportunityShare where OpportunityId in:oIds and RowCause='Team'];
            System.debug('oppShareRecords'+oppShareRecords);
            for(OpportunityShare oShare:oppShareRecords){
                oShare.OpportunityAccessLevel = 'Edit';
                otmListUpdate.add(oShare);
            }
            
        }
        System.debug('otmListUpdate'+otmListUpdate);
        update otmListUpdate;
    }
}


Thanks,
Sowmya.