0

I've create a lightning component which implements lightning:actionOverride, for use as a custom new record page.

I've created an object called "Custom Object" with API Name "CustomObject__c"

Without the override enabled, clicking "New Custom Object" results in a modal appearing, and the previous page title remaining in the browser title bar.

With the override enabled, the lightning component is rendered, and the title bar is set to "New CustomObject__c". I'd expect the title to be "New Custom Object" (or the appropriate translation if supplied).

I've managed to override the title in my scratch org by a javascript call to set document.title. This feels a bit hacky, and unfortunately this doesn't work once the code is packaged, I assume due to locker service.

In visualforce overrides the VF page has a title attribute which could be set. Is there a correct way of setting the title from a lightning component I've not found?

0

You should be able to set the page title using document.title as mentioned in the following post.

Reference : Lightning: How to change page title for lightning app?

Ideally, you should Lightning Page Templates wherein you can set "title" attributes as follows.

Reference : https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/apps_template_overview.htm

And I would recommend you to go for the template implementation if there are a lot of customizations.

But, there are a couple of considerations before customizing the whole layout with lightning page templates.

  • The default list view cannot be overridden with lightning page template. So edit functionalities inside record:detail pages should be feasible. But the "new" button the default list view will not be possible.
  • And for a trivial thing such as the Page title, customizing the whole page template seems to be a bit far-fetched.

So I tried a simpler approach in the recent release 43.0 to see if the workaround is still valid/relevant with the current release (Summer 18). And it seems to work as described above.

Controller.js :

({
    doInit : function(component, event, helper) { 
        document.title = 'Custom Trainer Title';
    }
})

If this title is not set - then it would be showing something like "*New namespace__sObject__c | Salesforce *".

Sample :

SetTitleWorking

  • Hi, thanks for the input. Using document.title js works fine in my scratch org, but once the code is put in a managed package, and the package installed in another org and used there, it ceases to work. It looks to me like the templating function you linked to is only for apps - if I try to apply the template attribute to my component I get an error 'Invalid attribute "template"', I can't see how to embed an app into a component. – James Jun 19 '18 at 22:13
  • @James : This approach does not work on managed packages. I think this is because of the execution context's. Will update the post if i find something. – StormBr34ker Jul 16 '18 at 9:10

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.