You need to sign in to do that
Don't have an account?
Soundar Rajan Ponpandi
SOQL Query for old Team Member ?
Hi,
I am sharing Opportunity record from Quote team members. In This scenario i would like to add one more functionality as mentioned below.
1. As of now this functionality is working for add a new team members.
2. But if already this record has shared to User A, Again i am sharing to same User A. At that time system should update a Old record with latest update (Without Creating a new record).
3. I am little confused to launch this functionality.
Can you please check my code and let me know where i need to make a changes to achieve metioned functionality.
Code For Review
Thanks in advance,
Soundar Rajan P.
I am sharing Opportunity record from Quote team members. In This scenario i would like to add one more functionality as mentioned below.
1. As of now this functionality is working for add a new team members.
2. But if already this record has shared to User A, Again i am sharing to same User A. At that time system should update a Old record with latest update (Without Creating a new record).
3. I am little confused to launch this functionality.
Can you please check my code and let me know where i need to make a changes to achieve metioned functionality.
Code For Review
public with sharing class GD_CreateQuoteTeam { @AuraEnabled public static void saveQuoteTeam(List<GD_Quote_Team__c> teamList, string quoteId){ try{ list<GD_Quote_Team__c> qtTeamList = new list<GD_Quote_Team__c>(); list<opportunityShare> readShareList = new list<opportunityShare>(); list<opportunityShare> editShareList = new list<opportunityShare>(); GD_Quote__c qt = [select id,GD_Opportunity__c from GD_Quote__c where id =: quoteId]; id oppId = qt.GD_Opportunity__c; system.debug('Opportunity Id '+ oppId); for(GD_Quote_Team__c team : teamList){ team.GD_Quotes__c = quoteId; qtTeamList.add(team); } if(qtTeamList.size()>0){Insert qtTeamList;} for(gd_quote_Team__c qTeam : qtTeamList){ if(qTeam.GD_Quote_Access__c == 'Read Only'){ system.debug('Enter Into the Read only = ' + qTeam.GD_Quote_Access__c); opportunityShare shareRecord = new opportunityShare(); shareRecord.OpportunityAccessLevel = 'Read'; shareRecord.UserOrGroupId = qTeam.GD_user__c; shareRecord.OpportunityId = oppId; readShareList.add(shareRecord); } } if(readShareList.size()>0){insert readShareList;system.debug('Read Access Provided');} for(gd_quote_Team__c qTeam : qtTeamList){ if(qTeam.GD_Quote_Access__c == 'Read/write'){ system.debug('Access |' + qTeam.GD_Quote_Access__c); opportunityShare shareRecord = new opportunityShare(); shareRecord.OpportunityAccessLevel = 'edit'; shareRecord.UserOrGroupId = qTeam.GD_user__c; shareRecord.OpportunityId = oppId; editShareList.add(shareRecord); } } if(editShareList.size()>0){insert editShareList;system.debug('Edit Access Provided');} }catch(Exception e){system.debug('Exception -' + e);} } }
Thanks in advance,
Soundar Rajan P.
for(gd_quote_Team__c qTeam : qtTeamList){
if(qTeam.GD_Quote_Access__c == 'Read/write'){
if (!sharingMap.ContainsKey(qTeam.GD_user__c) || (sharingMap.ContainsKey(qTeam.GD_user__c) && sharingMap.get(qTeam.GD_User__c) == 'Read'))
{
system.debug('Access |' + qTeam.GD_Quote_Access__c);
opportunityShare shareRecord = new opportunityShare();
shareRecord.OpportunityAccessLevel = 'edit';
shareRecord.UserOrGroupId = qTeam.GD_user__c;
shareRecord.OpportunityId = oppId;
editShareList.add(shareRecord);
}
}
}
All Answers
public with sharing class GD_CreateQuoteTeam {
@AuraEnabled
public static void saveQuoteTeam(List<GD_Quote_Team__c> teamList, string quoteId){
try{
list<GD_Quote_Team__c> qtTeamList = new list<GD_Quote_Team__c>();
list<opportunityShare> readShareList = new list<opportunityShare>();
list<opportunityShare> editShareList = new list<opportunityShare>();
GD_Quote__c qt = [select id,GD_Opportunity__c from GD_Quote__c where id =: quoteId];
id oppId = qt.GD_Opportunity__c;
system.debug('Opportunity Id '+ oppId);
for(GD_Quote_Team__c team : teamList){
team.GD_Quotes__c = quoteId;
qtTeamList.add(team);
}
if(qtTeamList.size()>0){Insert qtTeamList;}
List<opportunityShare> existingShareRecords = [SELECT UserOrGroupId,OpportunityAccessLevel from shareRecord where OpportunityId = : oppId ];
Map<Id,String> sharingMap = new Map<Id,String>();
for (opportunityShare oppShareRecord: existingShareRecords)
{
if (!sharingMap.ContainsKey(oppShareRecord.UserOrGroupId))
{
sharingMap.put(oppShareRecord.UserOrGroupId,oppShareRecord.OpportunityAccessLevel);
}
else
{
string accessLevel = sharingMap.get(oppShareRecord.UserOrGroupId);
if (accessLevel == 'Read' && oppShareRecord.OpportunityAccessLevel == 'Edit')
{
sharingMap.put(oppShareRecord.UserOrGroupId,oppShareRecord.OpportunityAccessLevel);
}
}
}
for(gd_quote_Team__c qTeam : qtTeamList){
if(qTeam.GD_Quote_Access__c == 'Read Only'){
if (!sharingMap.ContainsKey(qTeam.GD_user__c))
{
system.debug('Enter Into the Read only = ' + qTeam.GD_Quote_Access__c);
opportunityShare shareRecord = new opportunityShare();
shareRecord.OpportunityAccessLevel = 'Read';
shareRecord.UserOrGroupId = qTeam.GD_user__c;
shareRecord.OpportunityId = oppId;
readShareList.add(shareRecord);
}
}
}
if(readShareList.size()>0){insert readShareList;system.debug('Read Access Provided');}
for(gd_quote_Team__c qTeam : qtTeamList){
if(qTeam.GD_Quote_Access__c == 'Read/write'){
if (!sharingMap.ContainsKey(qTeam.GD_user__c) || (sharingMap.ContainsKey(qTeam.GD_user__c) && sharingMap.get(qTeam.GD_User__c) == 'Read'))
{
system.debug('Access |' + qTeam.GD_Quote_Access__c);
opportunityShare shareRecord = new opportunityShare();
shareRecord.OpportunityAccessLevel = 'edit';
shareRecord.UserOrGroupId = qTeam.GD_user__c;
shareRecord.OpportunityId = oppId;
editShareList.add(shareRecord);
}
}
}
if(editShareList.size()>0){insert editShareList;system.debug('Edit Access Provided');}
}catch(Exception e){system.debug('Exception -' + e);}
}
}
Hearty Thanks for your quick response.
Record sharing is perfect, at the same time and duplicate record also created.
Regards,
Soundar.
This sharing functionality is working fine.
1. Already i have shared opportunity record to "User A - ReadOnly".
2. Again, When i am sharing for "Read / write" new record is creatd for "User A - Read / Write".
3. Now it's 2 records created for same user "User A", I need to avoid this functionality only. Instead for creating we need to update the record if it's same User.
Regards,
Soundar.
for(gd_quote_Team__c qTeam : qtTeamList){
if(qTeam.GD_Quote_Access__c == 'Read/write'){
if (!sharingMap.ContainsKey(qTeam.GD_user__c) || (sharingMap.ContainsKey(qTeam.GD_user__c) && sharingMap.get(qTeam.GD_User__c) == 'Read'))
{
system.debug('Access |' + qTeam.GD_Quote_Access__c);
opportunityShare shareRecord = new opportunityShare();
shareRecord.OpportunityAccessLevel = 'edit';
shareRecord.UserOrGroupId = qTeam.GD_user__c;
shareRecord.OpportunityId = oppId;
editShareList.add(shareRecord);
}
}
}
It's Working fine.
Regards,
Soundar.