0

I have 2 standard objects, Accounts and Users and the Territory object. Accounts and Users have a lookup to the Territory. I need to display the user only accounts from his territory. How correctly to setup sharing rules?

  • "I need to display the user only accounts from his territory", can you please shade some light on this? – Mahmood Nov 8 '17 at 18:01
  • The Territory has records (Spain, France, Germany). Each user has a link to the territory. Each Account is the same. I need to display the user only accounts with his territory – Nikita Diadia Nov 8 '17 at 18:15
  • Where do u want to display that? – Mahmood Nov 8 '17 at 18:25
  • On the standard salesforce page(tabs) Account – Nikita Diadia Nov 8 '17 at 19:31
  • Why do you think you need sharing rules with your requirement? – Mahmood Nov 8 '17 at 19:35
0

With the current model, as described by you, on account standard page you will have the territory field, as it is parent. Since , user is the child of territory, you’ll need to create a VF page with account standards controller and an extension controller.

In the extension controller, get the users against the territory of the current account.

public myControllerExtension(ApexPages.StandardController stdController) {
    account acc = (Account)stdController.getRecord();
// query the territory against account

// Query the users against territory retrieved above 

// display the users on vf page
}

Finally, edit the page layout and put your vf page on the desired location to have the users related to the territory.

Edit

You could also use a VF page without a controller, as I learned that recently

<apex:page standardcontroller="Accoount"> 
    <apex:relatedList subject="{!Account.Territory__c}" list="Users"/> 
</apex:page>

Salesforce defines the subject in <apex:relatedList> as

Subject - The parent record from which the data and related list definition are derived. If not specified, and if using a standard controller, this value is automatically set to the value of the ID query string parameter in the page URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.