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
Jamie CohanJamie Cohan 

How to fix 'blank' iframe in Lightning?

Hi  

When we move from Salesforce Classic to Lightning the <Iframe > does not display.
The page that does not work is:   <apex:iframe src="{!FrameLink}" />

In Classic Salesforce the Iframe works.  Our application has a side menu and the user clicks on the function they want and the resulting iframe page is shown in the 'console window'

User-added image

When we switched to Lightning the console in the picture above is blank i.e. the page in the <iframe > is blank in 'Chrome' and in Microsoft Edge the console says "This content can't be shown in frame"...

In the developer console in the Chrome browser there is the following error:

na7.salesforce.com/a08A000001CZFnkIAH:1 Refused to display 'https://na7.lightning.force.com/one/one.app#/alohaRedirect/a08A000001CZFnkIAH' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'".

How do fix this iframe issue?

Microsoft Edge Browser

User-added image

In Chrome the browser
User-added image
Raj VakatiRaj Vakati
Hi Jamie,

I have a simple Option.You will get the User Lightning login experience from UserPreferencesLightningExperiencePreferred Field on user record.
IF Use switch to lightning dnt renders the iframe on the visuaforce page. Otherwise, you can show iframe.Let me know if it will not work for you  


 
Jamie CohanJamie Cohan
Hi Raj,

Are you saying we set the flag in Apex  to False ?

{ User u=[Select ID,UserPreferencesLightningExperiencePreferred from User where id=:UserInfo.getUserId()]; u.UserPreferencesLightningExperiencePreferred = FALSE ;

UserPreferencesLightningExperiencePreferred— When true, redirects the user to the Lightning Experience interface. Label is Switch to Lightning Experience.

OR

are you saying that there is a field on the user object layout that we disable   to UserPreferencesLightningExperiencePreferred  = false?

Because I don't see a property on the user property form.


User-added image
Jamie CohanJamie Cohan
Hi Raj,

Are you saying that we write apex code to set the UserPreferencesLightningExperiencePreferred to False 

User u=[Select ID,UserPreferencesLightningExperiencePreferred from User where id=:UserInfo.getUserId()]; u.UserPreferencesLightningExperiencePreferred = False

// UserPreferencesLightningExperiencePreferred— When true, redirects the user to the Lightning Experience interface. Label is Switch to Lightning Experience.

OR
Are you saying there is a field on User Settings Layout that has a field UserPreferencesLightningExperiencePreferred  that we set to False ?

Because I don't see it on the layout

User-added image
 
Raj VakatiRaj Vakati
User u=[Select ID,UserPreferencesLightningExperiencePreferred from User where id=:UserInfo.getUserId()]; 

if(u.UserPreferencesLightningExperiencePreferred ){
// I frame show
}else{
//  hide i frame 
}



UserPreferencesLightningExperiencePreferred  --->> When true, redirects the user to the Lightning Experience interface. The label is Switch to Lightning Experience. This field is available in API version 35.0 and later



https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_user.htm