8

The question is fairly straightforward - is there a way to get apex into a home page component (left side/narrow component) without resorting to loading a visualforce page in to an iframe?

I can't use an iframe but I need to be able to access things like static resources, user IDs, and other elements that are fairly easy to do in apex. I have some workarounds in place but they feel a little hack-ish. If there is a proper way to do that I'd love to try that approach.

2 Answers 2

9

your only choice at this point is Javscript. I am doing the same thing as we speak.

  1. google cdn reference to jquery,
  2. $.ajax(function(){ load visualforce page, returns json}
  3. render json data into page.

and you need to use jsonP as well. visualforce pages are housed on a different domain.

function jsonpcallback(data){
    $('#id').html(data.amount);
}
$('document').ready(function(){

    $.ajax({
        url: '{!host}/apex/<VFPAGE>',
        dataType: "jsonp",
        jsonp : "callback",
        jsonpCallback: "jsonpcallback",
        success: function() { console.log("success"); }, 
        error: function(a,b,c,d) { console.log("error"); } 
    });

});

the vf page:

<apex:page controller="CONTROLLER" contentType="application/json">
    jsonpcallback({!result});
 </apex:page>
3
  • You say "I am doing the same thing as we speak". I know it has not been long since you posted this, but I wonder if you have come to any conclusion on this. Were you able to get a working solution?
    – lindon fox
    Commented Sep 3, 2013 at 7:58
  • Good news is that a VisualForce page as a home page component is coming in the Summer '14 release: docs.releasenotes.salesforce.com/en-us/summer14/release-notes/…
    – collymitch
    Commented Jun 6, 2014 at 10:58
  • I was able to get a working solution, using jsonP you can request the data from a VF page and load it through javascript on the home page.
    – ebt
    Commented Jun 6, 2014 at 19:06
0

Outside of doing something like using the AJAX toolkit or the REST API this isn't possible as far as I know. Visualforce is served from a separate subdomain so the javascript same-origin policy prevents you from doing an AJAX load of content from it into an HTML component as well.

You may want to look into the AJAX toolkit's proxy if you're willing to proxy your visualforce content through custom javascript but that ends up being a lot of work to write.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .