3

I'm not having any luck googling this and my google-fu is typically "Awesome." Do note we're talking about Partner object, not OpportunityPartner.

I'm using system.RunAs() to simulate a normal sales user profile. I'm creating two accounts, acc1 and acc2, one contact on acc1, and one Opportunity on acc1.

If I try to create a new partner record such as:

    Partner thisPartner = new Partner();
    thisPartner.Role = 'Test Role';
    thisPartner.IsPrimary = true;
    thisPartner.OpportunityId = opp;
    thisPartner.AccountToId = acct2;
    insert thisPartner;

I get the following error:

System.SObjectException: Invalid field Role

On the above line

thisPartner.Role = 'Test Role';

If I comment system.RunAs(); it inserts just fine as a SysAdmin user.

If I just hit "New Partner" on the webpage Opportunity detail related list as an actual user with the same profile as the test user, it works fine.

What might I be missing? Thank you.

1 Answer 1

1

Oh... You just can't create Parnter objects via Apex unless the user has 'View All Data' permissions. I cannot write a unit test that appropriately mimics a standard sales user's creation of a partner. Thus, I can't unit test validation and workflow rules that only fire for non-admin user profiles.

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_partner.htm

You must have the “View All Data” permission to access this object via the API. All of the Partner fields are accessible in the describeSObjects() and query() calls.

https://success.salesforce.com/ideaView?id=08730000000BqP8

Looks like you cannot write triggers on the partner object.

1
  • If you have "View All Data" on a @isTest then doesn't that make it no longer negated from code coverage? Mar 31, 2015 at 0:15

You must log in to answer this question.

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