+ Start a Discussion
whitfty1whitfty1 

Is It Possible to Write To The AccountPartner Table?

I've been trying to write a test class and have finally narrowed down a major problem to the fact that several lines of code in my trigger are not being tested because I have a NULL Object .  This is where my trigger code stops:

accountpartner[] myAccountPartner = [Select AccountToId FROM AccountPartner WHERE AccountFromId = :myContact[0].AccountId];

 

So I've tried to place information into those fields in my test class:

AccountPartner AP2 = new AccountPartner(
		 AccountToId = endAccount.Id,
		 AccountFromId = portalAccount1.Id,
		 Role = 'Partner User'
		);
		Database.insert(AP2);

However, I receive "Field is not writeable: AccountPartner.AccountToId", "Field is not writeable: AccountPartner.AccountFromId", "Field is not writeable: AccountPartner.Role".

 

Is there a way around this?

HariDineshHariDinesh

Hi,

 

You cannot create accountpartner object record directly by assigning the values.

It needs to be created automatically by creating partner relationship between two accounts (when you create a Partner object and specify the AccountFromId).

 

So in your test class try to create partner object with required data, then automatically accountpartner will be created and data will be formed and code will be covered.

Currently I don’t have Code Sample for this to share.

But this Documentation will help you in understanding the relation and creation of Account partner.

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_accountpartner.htm#topic-title

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

 

whitfty1whitfty1

Thanks for response.

 

After reading the links that you gave, I have changed the code to :

Database.insert(AP1);
		
		Partner AP2 = new Partner(
		 AccountToId = endAccount.Id,
		 AccountFromId = portalAccount1.Id,
		 Role = 'Partner User'
		);
		Database.insert(AP2);

 And I don't receive the non-writeable code, however, I believe I'm still getting a NULL value for:

accountpartner[] myAccountPartner = [Select AccountToId FROM AccountPartner WHERE AccountFromId = :myContact[0].AccountId];

 

I've noticed that the documentation says "You cannot update() or upsert() partners via the API." regarding Partner Objects.  Is this why?

vignesh sethuramalingam 17vignesh sethuramalingam 17
Hi whitfty1,

I was also facing the same issue.Even though i create Partner object record in my test class Accountpartners records are not created,

Did u get any solution for this? Please let me know.

Thanks in advance