I'm attempting to use the Metadata API to add a custom button to my contact layout:


I'm following the example written here: https://andyinthecloud.com/2014/04/24/apex-metadata-api-and-spring14-keys-to-the-kingdom/

To begin, I copied the MetadataService.cls and MetadataServiceTest.cls into my force.com developer instance. Then, I attempted to run through the example by first creating a webLink MetadataService, however when I get to the last line it gets stuck:

MetadataService.WebLink webLink = new MetadataService.WebLink();
webLink.fullName = 'Test__c.googleButton';
webLink.availability = 'online';
webLink.displayType = 'button';
webLink.encodingKey = 'UTF-8';
webLink.hasMenubar = false;
webLink.hasScrollbars = true;
webLink.hasToolbar = false;
webLink.height = 600;
webLink.isResizable = true;
webLink.linkType = 'url';
webLink.masterLabel = 'google';
webLink.openType = 'newWindow';
webLink.position = 'none';
webLink.protected_x = false;
webLink.showsLocation = false;
webLink.showsStatus = false;
webLink.url = 'http://www.google.com';
webLink.width = 600;
service.createMetadata(new List<MetadataService.Metadata> { webLink })[0];

I am getting the error "Entity is not api accessible". This is my first time using the Metadata API and I'm not really sure how to troubleshoot this. Any suggestions?

  • You should use the install link and then try again.
    – Adrian Larson
    Aug 17, 2016 at 17:00
  • Also if you include the entire script you're trying to run, that would be helpful. Please edit your post with any new updates.
    – Adrian Larson
    Aug 17, 2016 at 17:11
  • @AdrianLarson Updated with full code (sorry should have done that initially)- also, what install link? Aug 17, 2016 at 17:23
  • There's a big, shiny Deploy to Salesforce button on the github page that leads to this page.
    – Adrian Larson
    Aug 17, 2016 at 17:24
  • Thanks, I'll try that. In the meantime, do you happen to know if the full code deploy is necessary for just what I'm trying to do above? It seems like it will bulk up the package by quite a bit. Aug 17, 2016 at 17:31

1 Answer 1


You get that error because you haven't instantiated service to anything. You could reproduce the error with this simple snippet as your entire execution:


You need to create a new MetadataPort to call the createMetadata method.

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
List<MetadataService.Metadata> elements = List<MetadataService.Metadata> { webLink };
MetadataService.SaveResult result = service.createMetadata(elements)[0];

I found this class by simply searching the MetadatService class for createMetadata(.

  • 1
    N.B. Service is considered by SFDC as some internal SObject and hence the error Entity is not api accessible
    – cropredy
    Aug 17, 2016 at 17:51
  • Same phenomenon can be observed with Project and some others.
    – Adrian Larson
    Aug 17, 2016 at 17:52
  • That seemed to do the trick! However now I'm getting a remote site error "System.CalloutException: IO Exception: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = na30.salesforce.com/services/Soap/m/37.0" Shouldn't that url/domain be included by default since it's my own domain? Aug 17, 2016 at 17:55
  • @user Nope you still have to add remote site settings. andyinthecloud.com/2014/07/29/…
    – Adrian Larson
    Aug 17, 2016 at 17:55

You must log in to answer this question.

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