0

In my lightning aura component: I am using below code to open a pop up for New user record creation and I am passing default field values to be pre-populated from another object, I am able to get the pop up fine with pre-populated values. Only problem is when I click the save button I get error saying "No access to field Billing. Either the field was removed from the entity or access to this field was removed.", For example if the title field has value "Junior Coordinator, Billing" then the comma between Coordinator, Billing is being considered as the start of another parameter.

            var pageReference = {
                "type": "standard__objectPage",
                "attributes": {
                    objectApiName: "User",
                    actionName: "new"
                },
                state: {
                    defaultFieldValues : 'FirstName='+component.get('v.ContactFirstName')+',title='+component.get('v.title')+',LastName='+component.get('v.ContactLastName')
                    }
                };
1

This is covered in the documentation. Use encodeDefaultFieldValues to get the correct encoding:

import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';

...

const defaultValues = encodeDefaultFieldValues({
    FirstName: 'Morag',
    LastName: 'de Fault',
    LeadSource: 'Other'
});

...

state: {
    defaultFieldValues: defaultValues
}
2
  • Thank you so much Brian for the direction, I was able to resolve it. As I was not using LWC, below code helped to fix the issue in aura component var pageReference = { "type": "standard__objectPage", "attributes": { objectApiName: "User", actionName: "new" }, state: { } } var defaultFieldValues = { FirstName: component.get('v.ContactFirstName'), Title: component.get('v.title'), LastName: component.get('v.ContactLastName') }; pageRef.state.defaultFieldValues = cmp.find("pageRefUtils").encodeDefaultFieldValues(defaultFieldValues); navService.navigate(pageReference); Jul 20 at 19:08
  • @Salesforce-Farmer Awesome. I missed the Aura tag, but I'm glad I was able to at least give you a hint.
    – sfdcfox
    Jul 20 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.