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
Pablo VenturinoPablo Venturino 

API 34.0 introduces INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY on portal user self-updating contact?

I have the following test that asserts that a portal user is able to update it's own contact first name.
@IsTest
public class MyTestClass {
    
    @IsTest
    static void portalUserSelfUpdateContact() {
        
        Account ac = new Account(Name = 'the account');
        insert ac;

        Contact ct = new Contact(LastName = 'contact_lastname', AccountId = ac.Id);
        insert ct;

        Profile pf = [SELECT Id FROM Profile WHERE UserType = 'CspLitePortal' LIMIT 1];

        User usr = new User(
            Alias                 = 'usralias',
            Email                 = 'theuser@email.com',
            Emailencodingkey      = 'UTF-8',
            Lastname              = 'user_lastname',
            Languagelocalekey     = 'en_US',
            Localesidkey          = 'en_US',
            Profileid             =  pf.Id,
            Timezonesidkey        = 'America/Los_Angeles',
            Username              =  Math.random() + 'test@testuser.com',
            ContactId             =  ct.Id,
            CompanyName           = 'the company',
            Salesforce_Edition__c = 'DE',
            IsPortalSelfRegistered = true
        );

        System.runAs(usr) {
            ct.FirstName = 'contact_firstname';
            update ct;
        }
    }
}
When I compile the class using API 33.0, the test passes. But when I try with API 34.0, the update fails with this message.
System.DmlException: Update failed. First exception on row 0 with id 005Q000000NtSmRIAV; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
What has changed in API 34.0 that causes this issue. What other changes should I make in my code for this test to pass?

Note: same question in http://salesforce.stackexchange.com/questions/89697
Tejpal KumawatTejpal Kumawat
Hello Pablo Venturino,

Code seems fine, But need to check these thing:
1. Edit test class & save If error Remove IsPortalSelfRegistered = true from test class and RUN test class, If PASS then enable portal setting and re-run class by adding IsPortalSelfRegistered = true

2. If step 1 not work follow : https://developer.salesforce.com/forums/?id=906F00000008yAPIAY

If this answers your question mark Best Answer it as solution and then hit Like!
Pablo VenturinoPablo Venturino
Thanks @Tejpal. I tried both with and without IsPortalSelfRegistered with no success.
I also checked the question you propose on step 2, but that is for a different problem.
Thanks again!
Tejpal KumawatTejpal Kumawat

Hello Pablo,

Can you check all UserType = 'CspLitePortal' profile have contact update permission, if not then please change query for specific profile that have update permission by putting AND Name = 'your_updatable_profile_name'

User-added image

Profile pf = [SELECT Id FROM Profile WHERE UserType = 'CspLitePortal' AND Name = 'your_updatable_profile_name' LIMIT 1];


If this answers your question mark Best Answer it as solution and then hit Like!
Pablo VenturinoPablo Venturino
Thanks again @Tejpal. I just tried specifying the exact profile I want to use and giving that profile full CRUD access on Contact, but again the test failed for the same reason.
I can still make the test pass using API 33.0. I also verified that API 35.0 does not solve the problem.
Thanks again!
Tejpal KumawatTejpal Kumawat
Hello Pablo,

I have same test class in my org with all version from 31 to 35 working fine, Can you connect me via skype so easy assit.

Regards
Tej Pal Kumawat
Skype : tejpalkumawat1991

If this answers your question mark Best Answer it as solution and then hit Like!