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.