function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JohnDuraiJohnDurai 

How to use URL i iframe src without hardcoding Aura Component

Hi All - I am trying to embed external web page in Salesforce Account record page using Aura component, I am trying the below approach which is working for me but need better way without harding the URL and passing the account id as well. can some one help me out on this.

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
    <iframe src="https://externalwebpage?id=XXXXXX"            
            width="100%"
            height="500px"
            sandbox="allow-same-origin allow-scripts allow-forms"
            scrolling="auto"/>
    
</aura:component>
Best Answer chosen by JohnDurai
Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi John
You can use Custom labels to store the base URL and then concatenate it with the recordId.

Something similar : 
 <iframe src= "{!$Label.c.labelName + '?=' + v.recordId}"        
            width="100%"
            height="500px"
            sandbox="allow-same-origin allow-scripts allow-forms"
            scrolling="auto"/>
    

All Answers

Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi John
You can use Custom labels to store the base URL and then concatenate it with the recordId.

Something similar : 
 <iframe src= "{!$Label.c.labelName + '?=' + v.recordId}"        
            width="100%"
            height="500px"
            sandbox="allow-same-origin allow-scripts allow-forms"
            scrolling="auto"/>
    
This was selected as the best answer
JohnDuraiJohnDurai
Thanks @Syed Insha Jawaid 2 it worked, but can you suggest is this best practice to get the custom label value in Component file or is there any other best practice to keep that in JS file or Helper file and then accessing that in component ? Thanks
Syed Insha Jawaid 2Syed Insha Jawaid 2
John
Aura component allows direct access of labels in HTML file hence you can use them as per your need. In case you have to perform complex computation using these labels then it would be recommended to use attribute and compute its value on the controller layer of the component.