I have an LWC component which is used to display contact information to guest user, using which they can also update the contact details.
When I'm running that LWC component as a system admin, I can see the field values, but as a guest user, I can't see any value.
I have already given class and object access to guest user profiles, also FLS permission is given for all fields.
HTML:
<template>
<lightning-card>
<div class="slds-m-around_medium">
<lightning-input type="text" label="Name" value={Name}></lightning-input>
<lightning-input type="text" label="Custom Field" value={CustomField}></lightning-input>
</div>
<div>
<lightning-button label="Save"></lightning-button>
</div>
</lightning-card>
</template>
JS:
import { LightningElement , wire, api, track} from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import CONTACT_OBJECT from '@salesforce/schema/Contact';
import CONTACTNAME from '@salesforce/schema/Contact.Name';
import CUSTOMFIELD from '@salesforce/schema/Contact.CustomField__c';
export default class UpdateDealerSocialMedia extends LightningElement {
@api recordId;
@track record;
@track error;
@track nameValue;
@track customFieldValue;
@wire(getRecord, { recordId: '$recordId', fields: [CONTACTNAME,CUSTOMFIELD] })
wiredAccount({ error, data }) {
if (data) {
this.record = data;
console.log('>>> record... '+JSON.stringify(this.record));
this.error = undefined;
this.nameValue = this.record.fields.Name.value;
this.customFieldValue = this.record.fields.CustomField__c.value;
} else if (error) {
this.error = error;
this.record = undefined;
}
}
}
Best Answer
I feel your pain, according to the new Guest User security, there's a lot less one can do through UI now, here's a good summary: https://help.salesforce.com/articleView?id=networks_guest_policies_timelines.htm&type=5
For external user to View a record, you need to add a sharing rule, which has a new option now: Guest user access, based on criteria *Note that Guest user can no longer be owner of any records, so you can set your sharing rule to "Created By", or something else other than Owner Id.
And if you want to Edit / Delete record, it would have to be apex, (without sharing) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm , which runs in system context.
Also, an alternative method: Flow(Without Sharing) is mentioned here: https://www.isimio.com/2020/08/07/migrating-to-salesforce-secure-site-guest-user/