You need to sign in to do that
Don't have an account?
juhi dhiver
Read Access for Opportunity!!!!!!
So my Opportunity are private and there is secondary owner field(lookup user) in Account. I want that my secondary owner can also view that particular Accounts opportunities.
trigger Accountshare on Account (After insert, after update) {
List<AccountShare> sharesToCreate = new List<AccountShare>();
User us = new User();
if (Trigger.isInsert) {
set<ID> accwnerBranch=new set<Id>();
For(Account acc:[SELECT Id,Owner.Branch__c FROM Account WHERE ID IN:Trigger.New]){
accwnerBranch.add(acc.Owner.Branch__c);
system.debug('The Branch owner Value is'+accwnerBranch);
}
for (Account ac : Trigger.new) {
system.debug('The Owner Branch is'+ac.Owner.Branch__c);
IF(ac.Owner.Branch__c =='HYDERABAD'){
system.debug('The Owner Branch is'+ac.Owner.Branch__c);
AccountShare cs = new AccountShare();
cs.AccountAccessLevel = 'Read';
cs.OpportunityAccessLevel='Edit';
cs.AccountId = ac.Id;
cs.UserOrGroupId = us.Id;
sharesToCreate.add(cs);
}
If(ac.Branch__c =='PUNE'){
AccountShare cs = new AccountShare();
cs.AccountAccessLevel = 'Read';
cs.OpportunityAccessLevel='Edit';
cs.AccountId = ac.Id;
cs.UserOrGroupId = us.Id;
sharesToCreate.add(cs);
}
if (ac.Secondary_Owner__c != null) {
// create the new share for group
AccountShare cs = new AccountShare();
cs.AccountAccessLevel = 'Read';
cs.OpportunityAccessLevel='Edit';
cs.AccountId = ac.Id;
cs.UserOrGroupId = us.Id;
sharesToCreate.add(cs);
}
Need Suggestion...What can be done for this .
Here this trigger is not working .
Any other solution for this ???
trigger Accountshare on Account (After insert, after update) {
List<AccountShare> sharesToCreate = new List<AccountShare>();
User us = new User();
if (Trigger.isInsert) {
set<ID> accwnerBranch=new set<Id>();
For(Account acc:[SELECT Id,Owner.Branch__c FROM Account WHERE ID IN:Trigger.New]){
accwnerBranch.add(acc.Owner.Branch__c);
system.debug('The Branch owner Value is'+accwnerBranch);
}
for (Account ac : Trigger.new) {
system.debug('The Owner Branch is'+ac.Owner.Branch__c);
IF(ac.Owner.Branch__c =='HYDERABAD'){
system.debug('The Owner Branch is'+ac.Owner.Branch__c);
AccountShare cs = new AccountShare();
cs.AccountAccessLevel = 'Read';
cs.OpportunityAccessLevel='Edit';
cs.AccountId = ac.Id;
cs.UserOrGroupId = us.Id;
sharesToCreate.add(cs);
}
If(ac.Branch__c =='PUNE'){
AccountShare cs = new AccountShare();
cs.AccountAccessLevel = 'Read';
cs.OpportunityAccessLevel='Edit';
cs.AccountId = ac.Id;
cs.UserOrGroupId = us.Id;
sharesToCreate.add(cs);
}
if (ac.Secondary_Owner__c != null) {
// create the new share for group
AccountShare cs = new AccountShare();
cs.AccountAccessLevel = 'Read';
cs.OpportunityAccessLevel='Edit';
cs.AccountId = ac.Id;
cs.UserOrGroupId = us.Id;
sharesToCreate.add(cs);
}
Need Suggestion...What can be done for this .
Here this trigger is not working .
Any other solution for this ???
Please try the below code. In your code I think Branch__c is a lookup to branch object from Account. Assuming that please find below code. Please let me know if it works for you.
Thanks
Anupama
Thanks
Anupama