function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Siddharth Birari.ax1164Siddharth Birari.ax1164 

Update Account Record Through Customer Portal in Test Code

Hi,

In one of my production environment, I am still using Customer Portal (Not Community). 
Here, I have one visualforce page on customer portal on which I update one specific Account record.

This works perfectly fine when I log in to the customer portal with a user having profile 'Custom Overage High Volume Customer Portal'. A custom profile with access rights to udpate the Account record.

Now, I need to replicate the same use case in Test code. Hence I created first an Account reocrd and a User record with above given profile.
When I run my test code under the context of the created user, and perform update operation on Account record, it gives me an exception.

I don't have any clue why the test code is not working as expected whereas the actual execution is as desired.

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY
Arunkumar RArunkumar R
Hi Siddharth,

Try to insert / update Account within the System.runAs() mode.

In this mode pass the current user data, not a created test user data Due to the Sharing Accessblity.
@isTest
public class testclass
{

static testMethod void insertAccount()
{
    User usr = [Select id from User where id =:UserInfo.getUserID()];
    System.runAs(usr)
    {
    // do you account insert/update
   
    }
}

}


For Reference : http://www.tgerm.com/2011/03/trigger-insufficient-access-cross.html
Siddharth Birari.ax1164Siddharth Birari.ax1164
Thanks for the help, however I am doing it in same way but no success at such.