3

UPDATE: this might be a Spring 19 only issue. Will try to confirm this.

If I create an opportunity with a standard Salesforce license, no problem. But if I try the same operation as a community user I get one of three different errors (below). I don't know why it's not the same error every time but it's usually the first one.

Here are things I've tried.

  1. click Compile All Classes (4 times)
  2. edit the classes listed in the error and save in an attempt to recompile use several different community users to execute the test
  3. comment out the function Opportunities.checkSoldToAccountTerritoryOnUser(), I got the same error #1 but on a different line and mentioning the type Territory2 instead
  4. change with sharing to without sharing on the class

If I follow the stack traces they end at a describe call on an ETM object (territory2, etc). It appears that in the context of a community user these describe calls fail. Has anyone seen triggers fail for community users only like this? What did you do?

Error #1

OpportunityTrigger: execution of BeforeInsert caused by: line 781, column 9: 
Dependent class is invalid and needs recompilation: Class Opportunities : Invalid type UserTerritory2Association

Error #2

OpportunityTrigger: execution of BeforeInsert caused by: 
System.NullPointerException: Attempt to de-reference a null object 
Class.ilib_SObjectSelector.getSObjectName: line 199, column 1 
Class.ilib_SObjectSelector.getOrderBy: line 159, column 1 
Class.ilib_SObjectSelector.configureQueryFactory: line 359, column 1 
Class.ilib_SObjectSelector.newQueryFactory: line 269, column 1 
Class.ilib_SObjectSelector.newQueryFactory: line 259, column 1 
Class.UserTerritory2AssociationSelector.getTerritoriesforCurrentUser: line 175, column 1 
Class.Opportunities.checkSoldToAccountTerritoryOnUser: line 781, column 1 
Class.Opportunities.onBeforeInsert: line 149, column 1 
Class.ilib_SObjectDomain.handleBeforeInsert: line 181, column 1 
Class.ilib_SObjectDomain.triggerHandler: line 421, column 1 
Class.ilib_SObjectDomain.triggerHandler: line 328, column 1 
Trigger.OpportunityTrigger: line 17, column 1

Error #3

OpportunityTrigger: execution of BeforeInsert caused by: System.NoAccessException: Entity is not api accessible 
Class.UserTerritory2AssociationSelector.getSObjectType: line 52, column 1 
Class.ilib_SObjectSelector.getSObjectType2: line 234, column 1 
Class.ilib_SObjectSelector.newQueryFactory: line 270, column 1 
Class.ilib_SObjectSelector.newQueryFactory: line 259, column 1 
Class.UserTerritory2AssociationSelector.getTerritoriesforCurrentUser: line 177, column 1 
Class.Opportunities.checkSoldToAccountTerritoryOnUser: line 781, column 1 
Class.Opportunities.onBeforeInsert: line 149, column 1 
Class.ilib_SObjectDomain.handleBeforeInsert: line 181, column 1 
Class.ilib_SObjectDomain.triggerHandler: line 421, column 1 
Class.ilib_SObjectDomain.triggerHandler: line 328, column 1 
Trigger.OpportunityTrigger: line 17, column 1
  • 1
    Which community licence type are you using? – Dave Humm Jan 6 at 3:13
  • 1
    You've potentially got two issues going on here. Clearly you have territory management in this org which affects record, account & opportunity sharing. There may even be splits involved too, but those shouldn't affect before insert. If this is a partner community, you could also have apex managed sharing involved as well which hasn't shared the accounts or opportunity records being inserted yet. More info is clearly needed. Are account & opportunity teams also used? – crmprogdev Jan 6 at 14:07
  • @DaveHumm we have licenses for Partner Community. – Todd Jan 6 at 22:32
  • @crmprogdev the code is attempting to do two things here 1. run a validation - prohibit opportunity insert if the running user does not have ETM-based access to the account. Our accounts and opportunities are private, both internal and external. 2. share the opportunity with a few users who are associated via a custom table to the parent account. That doesn't sound like ETM. It does make queries though because I leveraged a library I wrote that does Apex-based sharing to other objects that ETM doesn't cover such as quotes, locations, installed equipment, etc – Todd Jan 6 at 22:33
  • I wouldn't' expect your Community Partner Users to get their record sharing through Enterprise Territory Management. I'd expect them to get it through Apex Managed Sharing on the Account. Presumably they have create permissions on related Opportunities. In which case, your code is probably doing what it's supposed to, which is preventing them from inserting their Opps. I wouldn't expect them to get their perms through ETM, but instead through the Channel Manager/ApexManagedSharing when they're added to the Community and have an Acct shared with them. – crmprogdev Jan 8 at 0:16
0

Confirmed, this is a Spring 19 bug reported by multiple customers and Salesforce is working to fix. This saga leads me to another more academic question which I'll post separately.

  • Hi @Todd , did you hear anything back from SF. We have a case logged for the same error, but haven't heard back from SF onto the same. – Abhijeet Bhandari Jan 18 at 10:22
  • @AbhijeetBhandari yes, they have a fix scheduled for 1/28 deployment. This is not a guarantee of course. Apparently before Spring, ETM objects could be accessed in code for any user. Even other partner licenses that can't be a part of ETM. They "fixed" that bug but it impacts some of us. Also, the kinds of partner licenses we use can use ETM and in fact we put some of those users in our territories. – Todd Jan 19 at 17:07

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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