[SalesForce] Apply multiple sharing set on one object same profile

My goal is to give partner users access to records based on two field on the same object.
I use Sharing sets (From setup->communities settings->sharing sets)
On opportunity, I have two custom fields (Primary partner account and secondary partner account) which i want to based the sharing rules on them.
So i created two sharing sets, but still cannot see the secondary partner account records.

This one works:
enter image description here
While this one does not:
enter image description here

i.e Cannot see opportunity records where user.contact.acount == opportunity.secondary_partner_account__c
(Edit:You cannot apply two sharing sets on same profile)

Any ideas?

Please help:)
Best regards.

Best Answer

I solved this issue with help of some apex coding. Solution is based on OpportunityShare object which connects between users and opportunity records.

opportunity attrOpp = [select Secondary_Partner_Account__r.id,secondary_partner_account__r.name from opportunity where id =: opportunity.id];
list<User> users = [SELECT Id, Contact.AccountId, Contact.Account.Name FROM User where Contact.AccountId =: attrOpp.secondary_partner_account__r.id ];
        List<OpportunityShare> oppShareList = new List<OpportunityShare>();
        for(User usr: users){
            OpportunityShare oppShare = new OpportunityShare();
            oppShare.OpportunityAccessLevel = 'Read';
            oppShare.opportunityid = opportunity.id;
            oppShare.UserOrGroupId = usr.Id;
            oppsharelist.add(oppshare);
        }

        database.update(oppsharelist,false);
    }
Related Topic