IsExcludedFromRealign would also prevent the reassignment when manually updated no?
When you go into a territory and select Manage Rules, down at the bottom there is a Preview button. Does the account show there? Could it be that there is another assignment rule running when you manually update and thus not working when you run the rule you're looking at? Are you actually pressing the Run Rules button?
Not trying to be condescending but running through all the possible scenarios.
After clarifying in a comment on your question, we're working with the Associate Contacts with Multiple Accounts
feature, which was made generally available in Summer '16 (API v37.0)
After you've enabled Contacts to be related to multiple Accounts, if you wish to retrieve all the related contacts on an Account, you'll need to query the AccountContactRelation
object, which is the junction object Salesforce is using to track the Many-to-Many relationship.
The following queries should work
Using a semi-join:
SELECT Id, Name FROM Contact WHERE Id IN (SELECT ContactId FROM AccountContactRelation WHERE AccountId = <account Id here>
)
Using a parent-child subquery
SELECT Id, (SELECT Contact.Name FROM AccountContactRelations) FROM Account WHERE Id = <account Id here>
)
The different results that you're getting between the dev console and compiled Apex may be due to your Apex using an API version of 36.0 or below.
Best Answer
I found a separate documentation that might help others who encounters the same question:https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_objectterritory2association.htm
Cheers!