I am trying to call dynamic URLs of an external app(having same domain but different paths basis clicking on links inside salesforce) in Salesforce using Canvas app. How can this be implemented?

Currently I am using

< iframe>

in which I can give my dynamic url value, say using a variable "s" as

< iframe src="{!s}"/>.

Since, it is having clickjack protection issue, I wish to convert this into canvas app. Using < apex:canvasApp> does allow to pass custom parameters but how do we pass different paths?

  • I have the same problem. I need to pass a parameter on the canvas url so nginx would be able to target it. – user22011 Jul 9 '15 at 6:20
  • Do you need to have different URLs passed? Is this a single page app (e.g. in Angular) where you can manipulate the route in JavaScript? – Alex Tennant Jul 31 '15 at 19:47

I figured out the solution for this.

Step 1.Invoke the canvas using VF page and pass the variables using parameters... sample code.

<apex:page standardController="contact">
  <apex:form id="myform"> 
     <apex:pageblock > 
        <apex:canvasApp developerName="ConvasAppPOC" parameters="{'uNum':'{!contact.id}','viewPage':'Home'}" width="100%" maxHeight="infinite"/>  

Step2. Using canvas life cycle controller we should be able to retrive these parameters , based on parameters we can add the logic.

here is the sample CanvasLifecycleHandler code

public class CanvasLifecycleHandlerforPOC implements Canvas.CanvasLifecycleHandler {

public Contact part { get; set; }
public String sn { get; set; }
public String uNum { get; set; }

public Set<Canvas.ContextTypeEnum> excludeContextTypes(){
    Set<Canvas.ContextTypeEnum> excluded = new Set<Canvas.ContextTypeEnum>();
    return excluded;

public void onRender(Canvas.RenderContext renderContext) {

    //Get the Application and Environment context from the RenderContext
    Canvas.ApplicationContext app = renderContext.getApplicationContext();
    Canvas.EnvironmentContext env = renderContext.getEnvironmentContext();
    URL url = new URL(app.getCanvasUrl());
    Map<String, Object> params = (Map<String, Object>) JSON.deserializeUntyped(env.getParametersAsJSON());
    string unum=String.valueOf((String)params.get('uNum'));
    String queryParams='';
        queryParams = 'RelayState=user_num%253D'+uNum+'%2526action%253Dclienthomenew';
    System.debug('Controller finalURL: ' + app.getCanvasUrl() );
    System.debug('uNum ***: ' + uNum );
    System.debug('params ***: ' + params ); 

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.