Andy in the Cloud

From BBC Basic to and beyond…

38 thoughts on “Post Install Apex Metadata API Configuration Solved!

  1. Be interesting to see if this technique passes security review, I’d really hope so since it’s informing and requesting permission from the administrator.

  2. Wondering even if salesforce would have not allowed to Call directly from Visualforce due to cross domain ,worth trying with /services/proxy and generating client side proxy and making the request .

  3. Can you please let me know if it passes security review.

    • Sure will do, I am not in a position to submit my app using his yet, but will follow up here when I do. In the meantime see my thoughts on this in the blog.

  4. Hi Andy,

    This is good solution. but how can someone create components via Post-Install if somebody needs to go to the VF to create remote site for host?

    Post install script would run before admin goes to this VF page. And in post-install you cannot create remote site via meta-data API, because the remote site to Host is missing. Sounds like catch 22 to me.

    Does this make sense or am I missing something here?


    • No your not missing something. Instead if a post install script you can since summer’14 define a post install page on your package (i think during upload process). I have not tried it yet but maybe this is a better place?

  5. Other solution might be to include all Salesforce instance in RemoteSite and package that. That is NOT at all what I want to do.

    • Not not at all, good news upgrades can include such scripts assuming user has setup after initial install. In the blog I think I linked to Idea to white list Salesforce servers, please help and up vote. Thanks for your comments! 🙂

  6. Andrew,
    I’m really interested if you have pass the security review. Could you tell me?


    • I have yet to go through this process with this solution. My speculation is that it will pass, but i cannot confirm as yet. I have used this approach in my Decalrative Lookkup Rollup Summary tool, which i do plan to put through security review again in the future. I’ll update when i do.

  7. Brilliant! Do you have a sample code of retrieving page layouts in an installed managed package?

    • See the MetadataServiceExamples.cls for a layout retrieve. The secret is in the naming of the layout it needs to include the managed package namespace in the name. Best approach is to login to org using Salesforce Developer Workbench and use the Metadata menu option to list all the layouts in the org and observe the layout names it shows here to use when calling the retrieveMetadata operation.

    • There was also a question in the GitHub repo Issues list about this as well as i recall. Let me know if your struggling to find these things.

  8. Thanks for your help! I will give it a shot…

  9. I was able to read the layout, but it seems to be the old version of the layout (from the original 1.0 version of the package), not the updated layout from the latest 1.1 version of the package, and in the workbench I only see one version of the layout. I was hoping to see all versions. bummer.

    What I’m trying to do is somehow read the latest 1.1 version of the layout, make a copy of the original/old 1.0 layout (because the original is part of a managed package thus not editable) and then update this copy. Doesn’t look like I’ll be able to get to the 1.1 layout…

  10. This is same Mitesh harnessing you on your other blog. Thank you for your prompt reply. We have implements this workaround to create few fieldsets in subscriber org when they go to “Welcome” page. While this works in EE org, I am afraid it won;t work in PE org. if they do not have API enabled.

    Have you encountered this with your PE customers?

  11. Thank you Andy. We will have some message for PE org. Wish you a very Happy New Year!!

  12. Pingback: Unable to update metadata (picklist values etc) after post install script is executed | DL-UAT

  13. Andy – Is it possible to automate 1) package installation and 2) other manual tasks such as updating layouts or picklist values, field level security using the Apex MetaData API you created in the managed package production environment? THanks in advance.

  14. Hi Andy,
    I used the above solution for creation of remote site settings and it works fine in firefox and chrome but in case of IE, the above solution does not seem to work perfectly. The problem is on clicking of ‘Create Remote Site Settting’ button, method named ‘displayMetadataResponse’ is not getting called.

    As I further analyzed the problem, then found that in case of IE ‘this.readyState’ is undefined and even ‘this.response’ is undefined so following code block is not working with Internet Explorer :

    if(this.readyState==4) {
    var parser = new DOMParser();
    var doc = parser.parseFromString(this.response, ‘application/xml’);
    var errors = doc.getElementsByTagName(‘errors’);
    var messageText = ”;
    for(var errorIdx = 0; errorIdx < errors.length; errorIdx++)
    messageText+= errors.item(errorIdx).getElementsByTagName('message').item(0).innerHTML + '\n';

    can you suggest the workaround for this ?

    • I am not sure what the problem is here, I am on a Mac so cannot easily try. There ought to be general http comms examples for ie to compare though. Might also be worth asking in a more general way on stackexchange. Worth checking you don’t have any backwards compatibility settings on or page headers controlling it. This should be an industry standard approach for http comms I think.

  15. Hi Andy,
    Can this possible at the time of installation i.e. in onInstall() method of Installhandler Interface. Because giving user to set the endpoint is not great idea. If it is possible can you suggest way using your code.


  16. Hello Andy ,
    From where can i get please the Tooling api TEST classes? I went to the github repository but found only classes
    Thanks for your Help

  17. @Andrew, the idea says it is delivered, but calling Metadata from Apex still requires Remote Site. Here is the idea you posted originally:

    Am I misreading it? Not sure what is “delivered”?

    This will be big win for all fellow developers and ISVs. Can you please cross check?

  18. Hi Andrew, thanks for a spot on blog post. We are an ISV already going though a yearly security review, so we are also curious whether your solution has gone through one, and if it passes.

Leave a Reply to Mitesh S Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s