I want to query the RoleInTerritory2 field from UserTerritory2Association sObject. I am logged in as System Admin profile but still not able to query this field. Starnge thing here is that I am able to query this via developer console. Does anyone have any idea reagrding it? It gives me an error : No such column 'RoleInTerritory2' on entity 'UserTerritory2Association'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
Got the problem. There was an API version conflict. It works for API versions 30 above.
The class where I was trying to use UserTerritory2Association object, was of API version 30 which doesn't support it. I changed the API version for the class that solved my issue. Dec 23, 2015 at 12:07
Would you mind specifying which API version you changed it to? I tried this and it didn't solve my problem. Oct 26, 2016 at 18:05