+ Start a Discussion
trublutrublu 

Please help - Need to set value to fields that are not writeable in UNIT TEST

Hi all,

 

I am totally stuck writing some unit tests for my triggers. There is a need for me to create the following test data in my unit tests, since the triggers are checking these field values as conditions:

 

- accounts with isPartner = true (obtained not writeable error on runtime)

- userrole with portaltype = Partner (obtained not writeable error on compilation)

- Group with relatedid = a UserRole.id (obtained not writeable error on compilation)

 

20080906031603.219:Class.TestTriggers.testUpdateAccountAfterInsert: line 7, column 9: testUpdateAccountAfterInsert

System.SObjectException: Field is not writeable: Account.IsPartner

 

Could somebody please send me some sample unit tests that cover these fields please? I am dealing with accountshare records on on this project, and the triggers case check for these fields that are not assessible. In general, how do we write unit tests that need access to these fields?

 

Please help!!! Thank you.

 

 

 

hisrinuhisrinu
Hi,

  user user1 = [select Id from User where ContactId!= NULL LIMIT 1]; // It will take one partner user.
So based upon this partner user, you can perform all the queries.
you can write your test methods.

trublutrublu

thank you. so there is no way to create a partner user and userrole within the unit test? thanks!

 

hisrinuhisrinu
According my knowledge there is no way to create partner users through code.

Bhawani SharmaBhawani Sharma
1. Create an account record in your test method.
2. Create a contact record where contact.AccountId = accountId;
3. Create a user record with user.contactId = contact.Id;

This will create the partner user.