[SalesForce] Provide access to visualforce page for all profiles

I am creating a visualforce page from apex, using the metadata api. To call the metadata api I am using https://github.com/financialforcedev/apex-mdapi

    MetadataService.MetadataPort service = createService();     
    MetadataService.ApexPage apexPage = new MetadataService.ApexPage();
    apexPage.apiVersion = 25;
    apexPage.fullName = getPageName(objectName);
    apexPage.label = 'myprefix'+ objectName;
    apexPage.content = EncodingUtil.base64Encode(Blob.valueOf(getPageMarkup(objectName)));
    List<MetadataService.SaveResult> results = service.createMetadata(
            new MetadataService.Metadata[] { apexPage });

This creates the page succesfully, but it is only available to System administrator profile(creator). I want the page to be available to all profiles. How to do this?

Best Answer

You can either do it manually from the Page Security section (Setup/Develop/Pages --> Security link next to your page name). This is easier than going to the profile, because you can give access to all profiles at the same time.

You can also update the ProfileApexPageAccess part of the Profile Metadata: https://www.salesforce.com/us/developer/docs/api_meta/Content/meta_profile.htm#profileApexPageAccess_title