2

I want to create a homepage widget for the sidebar that has a button to create a new record in a custom app (which I intent to distribute, so it needs to be a portable solution).

I'd like to use a button: <button onclick="document.location='/path/to/new/foo'">New Foo</button>

Is there a way to get the path to the app no matter where it's installed? I assume that /a00 in my dev account is just because it's the first app.

1 Answer 1

3

You can add an HTML area component that contains an iframe that loads a VisualForce page with code that generates the URL for the New action of your custom object.

<iframe style="background:transparent; border:0; overflow:hidden" src="/apex/<Name of VisualForce page>" height="100" width="100%"></iframe>

Change <Name of VisualForce page> to the name of the VisualForce page that contains the button:

<apex:page showheader="false" sidebar="false" standardstylesheets="false">
    <apex:form >
        <input type="submit" value="New"
            onclick="window.top.location='{!URLFOR($Action.<Object API Name>.new)}'; return false;" />
    </apex:form>
</apex:page>

Change <Object API Name> to the API name of your custom object.

Note that iframes don't grow/shrink to fit their content so you'll have to set an explicit height. The loaded content is actually served from the force.com domain, so cross-domain security stops you accessing the parent document to resize it automatically.

1
  • Thanks .. I was going to just have a button to save doing this. But now I need to call Apex, I get to implement some other cool stuff I wanted! Commented Aug 12, 2012 at 3:34

You must log in to answer this question.

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