Andy in the Cloud

From BBC Basic to Force.com and beyond…

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

  1. Matt Lacey (@LaceySnr)'s avatar

    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. Mohith Kumar's avatar

    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. Hussey's avatar

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

    • Andrew Fawcett's avatar

      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. Mitesh Sura (@SFDC_Developer)'s avatar

    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?

    Mitesh

    • Andrew Fawcett's avatar

      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. Mitesh Sura (@SFDC_Developer)'s avatar

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

    • Andrew Fawcett's avatar

      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. Pablo Roldan's avatar

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

    Pablo

    • Andrew Fawcett's avatar

      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. Yasa Kusuma's avatar

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

    • Andrew Fawcett's avatar

      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.

    • Andrew Fawcett's avatar

      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. Yasa Kusuma's avatar

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

  9. Yasa Kusuma's avatar

    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. Mitesh S's avatar

    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. Mitesh S's avatar

    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. Niket's avatar

    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. Vinay Chanchlani's avatar

    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';
    displayMetadataResponse(messageText);
    }

    can you suggest the workaround for this ?
    Thanks

    • Andrew Fawcett's avatar

      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. sandeshganjare's avatar

    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.

    Thanks,
    Sandy

  16. Salma's avatar

    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. Mitesh Sura (@SFDC_Developer)'s avatar

    @Andrew, the idea says it is delivered, but calling Metadata from Apex still requires Remote Site. Here is the idea you posted originally: https://success.salesforce.com/ideaView?id=08730000000l7iEAAQ

    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. Oscar Scholten's avatar

    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 comment