• Jesse Rowe
  • 0 Points
  • Member since 2017

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 3
I have a publicly available page through salesforce sites. It was working before our sandbox got upgraded to Spring 2020 release. In order to replicate the problem a salesforce site needs to be created. The LWC will be embedded within salesforce site VFP.

I gave the external user access to Case object (read/edit) and visibility of fields to be displayed.

I get identical issue with aura component "lightning:recordEditForm" and LWC "lightning-record-edit-form".

I could replace the lightning-record-edit-form with input fields, however, it makes things complicated with dependent picklists.

<apex:page standardStylesheets="false" applyBodyTag="false" sidebar="false" showHeader="false">
    <apex:includeLightning />
    <div id="container"></div>
    $Lightning.use("c:Site_LWC_Viewer_App", function()
            console.log('component created');

AURA APP - "Site_LWC_Viewer_App":
<aura:application extends="ltng:outApp" access="GLOBAL" implements="ltng:allowGuestAccess">

LWC - "testLWC":
    <lightning-record-edit-form object-api-name="Case">

        <lightning-input-field field-name="Subject"></lightning-input-field>
        <lightning-button   class="slds-m-top_small"
                            label="Create new">

Error Message
We need certain users from our partner resellers to be able to create new users for their employees on our Partner Community. We have created a custom Lightning component for them to do this. This component works perfectly when used by a System Administrator. However, when it's used by a user with "Partner Community Login" license, it throws this exception:
Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Profile]: [Profile]
This is the Apex code in the controller that inserts the User:
public static void createPartnerUser(Contact partnerContact, Id profileId) {

    User currentUser = [SELECT Id, TimeZoneSidKey, LocaleSidKey, LanguageLocaleKey FROM User WHERE Id = :UserInfo.getUserId()];
    User newUser = new User(Username = partnerContact.Email, ContactId = partnerContact.Id, ProfileId = profileId,
            Alias = alias, Email = partnerContact.Email, EmailEncodingKey = 'UTF-8', Phone = partnerContact.Phone,
            LastName = partnerContact.LastName, CommunityNickname = partnerContact.Email.substringBefore('@'),
            TimeZoneSidKey = currentUser.TimeZoneSidKey, LocaleSidKey = currentUser.LocaleSidKey,
            LanguageLocaleKey = currentUser.LanguageLocaleKey, system_field_jump_future_method__c = true,
            FirstName = partnerContact.FirstName
    insert newUser;
As you see, the Profile is not missing and we have confirmed that it is not null. The code works perfectly when it's executed by an Admin or as Anonymous Apex.

Thank you for your help.