Understanding apex:iframe Component in Visualforce

The <apex:iframe> component allows you to embed an external webpage or dashboard directly within your Visualforce page. It’s useful for integrating third-party content like charts, videos, or tools.


Why Use <apex:iframe>?

  • Display external websites within Salesforce.
  • Embed internal tools like dashboards or analytics.
  • Integrate videos, maps, or help content from other sources.

Basic Syntax

xmlCopyEdit<apex:iframe src="https://www.example.com" height="500px" width="100%"/>

Example: Embedding a YouTube Video

xmlCopyEdit<apex:page>
    <apex:iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ"
                 height="315px" width="560px"/>
</apex:page>

Key Attributes

  • src: URL of the external resource.
  • height / width: Define the dimensions of the frame.
  • scrolling: Allows scrollbars (optional).
  • frameborder: Set to 0 to remove border.

Things to Keep in Mind

  • The embedded URL must be HTTPS and allowed by Salesforce CSP (Content Security Policy).
  • Some websites may block iframe embedding for security reasons.
  • For internal content, ensure user authentication if required.

Use Cases

  • Embed company intranet tools or dashboards.
  • Show external tutorials or documentation.
  • Integrate with 3rd party charts or analytics.