0

Can we use a standard page layout inside a lightning page/component?

Thanks

  • 2
    What is your use case? Have you taken a look at lightning:recordForm, if that's something helps here. – Jayant Das Jul 19 '18 at 17:25
  • Here's my use case: Based on the record type chosen on an object, I need to take the user to a custom lightning edit page and show different page layouts on the page based on the selection by user. My question: Can we embed a standard page layout inside a lightning component/page instead of designing the page with the fields which we do with vf pages ? – SFDC_BigDog Jul 19 '18 at 17:30
  • So your use case is to create a record? – Jayant Das Jul 19 '18 at 17:35
  • Yeah. But based on the record type selected I need to show different fields to the user who can enter the values. So instead of lightning tags equivalent of <apex:inputField>, I thought if we can create a page layout and embed that inside lightning component so that I can dynamically embed them based on the record type chosen. – SFDC_BigDog Jul 19 '18 at 17:40
  • Okay, I think you need force:createRecord here. Take a look and see if that's what you are looking for. – Jayant Das Jul 19 '18 at 18:04
3

Based on your comments around requirements (as below), you are looking to be able to dynamically reflect the page layout for creating a record using a Lightning Component.

  1. Based on the record type chosen on an object, I need to take the user to a custom lightning edit page and show different page layouts on the page based on the selection by user.
  2. Based on the record type selected I need to show different fields to the user who can enter the values.

You need to use force:createRecord event for this purpose. This is what the documentation for this event mentions:

This event opens a page to create a record for the specified entityApiName, for example, "Account", or "myNamespace__MyObject__c".

To display the record create page for an object, set the object name on the entityApiName attribute and fire the event. recordTypeId is optional and, if provided, specifies the record type for the created object. defaultFieldValues is optional and, if provided, specifies values to use to prepopulate the create record form.

Now, that you want to be able to display the page layout based on the record type, you will need to use the recordTypeId attribute of the event for that purpose. You just need to pass the record type's id that was selected in the previous page and it will render the page layout associated with that record type.

Note - Though the documentation does not explicitly mention that it opens associated page layout with a record type, but once you provide the record type id, it takes care of opening the correct page layout based on the assignment (I have verified this as a test).

This is how your code should look like:

var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": "Account",
        "recordTypeId": "recordtypeid"
    });
createRecordEvent.fire();

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.