I have a Update trigger on Opportunity. The trigger queries the Partner object.

[Select AccountToID from Partner where OpportunityID IN: Trigger.newmap.keyset()]

The above trigger has been running fine and it had no issues. I then created another trigger on OpportunityLineItem which updates Opportunity. As soon as I deployed the new trigger, users got error referencing the above query line.

Error Message: System.QueryException: sObject type 'Partner' is not supported.

Also the error doesn't always come. I have been unable to replicate the same in Sandbox. Can anyone highlight a reason for the above error?

UPDATE: After further debugging, I found that if the above query is executed via OpportunityLineItem trigger, it throws the QueryException. However, the same query if executed via Opportunity trigger, it works fine. It seems that the Partner object is accessible during the instance of Opportunity trigger. Any idea why? Also to solve my issue, I updated the query to use OpportunityPartner instead of Partner and everything works fine now.

P.S.: Opportunity is public read/write in the Org.

3 Answers 3


According to the documentation, "You must have the “View All Data” permission to access this object via the API". Are you sure the user executing the trigger has View All Data? What are you attempting to accomplish exactly? Would you be better off accessing the OpportunityPartner junction object?

  • Its not an issue with View All Data. I debugged further and found that when Opportunity trigger was called via OpportunityLineItem trigger, it give the query exception error. However, if the Opportunity trigger is directly called via UI Opportunity update, the same query runs fine. Weird I then updated the query to use OpportunityPartner instead of Partner as you suggested and it worked fine. Any idea why this would happen?
    – RajeshShah
    Commented Feb 10, 2015 at 14:12

I ran into the same problem with my Opportunity Trigger. However I query the Partner object in a separate class called by the Opportunity Trigger, so just putting without sharing in the class definition, got it to work.


public with sharing class OpportunityTriggerHandler


public without sharing class OpportunityTriggerHandler
  • Thats an interesting solution. However, it may not work always since in some cases we would want to keep the class "with sharing" for security reasons.
    – RajeshShah
    Commented Feb 21, 2015 at 9:05
  • That's true, though I guess you could just move the method that queries the Partner object to another class or only have that part outside of the trigger. Commented Feb 23, 2015 at 20:07

Summarising the points from the various posts and my solution:

  1. Partner object cannot be queried from OpportunityLineItem trigger (I haven't any documentation for this; it is strictly based on my findings.).
  2. Partner object can be queried from Opportunity Trigger.
  3. If you are querying for Partner with the Opportunity related, it is better to use the OpportunityPartner object (as suggested by @JimRae). This is solution I applied in my case.
  4. If you want to query the Partner object but from the OpportunityLineItem trigger, move the query to an apex class that is "without sharing" and call that from your trigger. (see answer of @MrShaneJensen for more details).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .