I don't know if my question fits to ask here, but let me ask it anyway. I'm building a several features using Apex Wrapper Salesforce Metadata API: https://github.com/financialforcedev/apex-mdapi

Simply put, this is just an Apex SOAP callout that invokes Metadata API (thus, the issue might not depend on this module). Thanks to this module, I was able to operate metadata via Apex and verified the change of metadata from the Setting screen in the org. However, it turns out that if I try to create a record that is defined by the metadata that is created by the metadata api operation, then I realized the change actually isn't reflected.

The weird workaround of this issues is to just wait for like 20 min. If I retry after 20- min-long wait, then I successfully created a record.

But the 20-min-long wait is not something acceptable for real use-cases. Do you have any idea to resolve this issue? Thanks.

FYI, this is my sample code:

public static void createObject(String label, String api_name){
    MetadataService.MetadataPort service = createService();
    MetadataService.CustomObject obj = new MetadataService.CustomObject();
    obj.fullName = api_name+'__c';
    obj.label = label;
    obj.pluralLabel = label;
    obj.nameField = new MetadataService.CustomField();
    obj.nameField.type_x = 'AutoNumber';
    obj.nameField.label = 'Record Number';
    obj.nameField.displayFormat = 'SHN-{00000000}';
    obj.deploymentStatus = 'Deployed';
    obj.sharingModel = 'ReadWrite';
    obj.enableReports = true;
    obj.enableSharing = true;
    obj.enableBulkApi = true;
    obj.enableStreamingApi = true;
    obj.enableSearch = true;

    List<MetadataService.SaveResult> results =
            new MetadataService.Metadata[] { obj });
  • Could add some code samples for further clarity on this questions?
    – arut
    Jun 22 at 17:23
  • @arut Thank you for your reaction. I added some code sample. Jun 23 at 0:55
  • I had absolutely no problem running this piece of code and getting the custom object created immediately. Looks like you problem might be due to something else. Have you tried on a new developer org or sandbox & observed the same problem?
    – arut
    Jun 23 at 9:57
  • @arut Thank you so much for your verification. Did you also tried to create a record? It is certain that this code creates the custom object but it takes 20 min until I can create a record. I've tried this code on multiple orgs like : scratch org, developer org, subscriber org (enterprise edition) but I always need to wait to reflect the change. Jun 24 at 1:45
  • 1
    @arut I tried running this code sample in a plain scratch org and then confirmed the change of the metadata immediately reflected. Thus, as you said, this issue is caused by something depending an org. Thank you so much for your help. Jun 24 at 11:10

1 Answer 1


As the above comment mentioned, it turns out that this issue depends on its org, not on the implementation. I'm guessing the issue might be related to the amount of the metadata of the org. Without installing the package, which includes giant metadata components, the Metadata api operation successfully executed.

I leave this question here so that someone who encountered the same issue would get some hint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.