2

I'm trying to retrieve the metadata of all the objects. I retrieve all the objects using soapConnection.describeGlobal().getSobjects() and then insert them in my custom class Tables. This is then used in the Metadata class to obtain the metadata. However, I ran into this Warning message:

unpackaged/package.xml - Entity of type 'CustomObject' named 'CaseFeed' cannot be found ... unpackaged/package.xml - Can't retrieve non-customizable CustomObject named: HashtagDefinition

The corresponding Metadata retrieval code is:

   public void retrieveZip(List<Table> tables) throws Exception
        {
            RetrieveRequest retrieveRequest = new RetrieveRequest();
            retrieveRequest.setApiVersion(API_VERSION);
            setPackage(retrieveRequest, tables);

            AsyncResult asyncResult = metadataConnection.retrieve(retrieveRequest);
            RetrieveResult result = waitForRetrieveCompletion(asyncResult);

            switch (result.getStatus())
            {
                case Succeeded:
                    // Print out any warning messages
                    StringBuilder stringBuilder = new StringBuilder();
                    if (result.getMessages() != null)
                    {
                        for (RetrieveMessage rm : result.getMessages())
                            stringBuilder.append(rm.getFileName() + " - " + rm.getProblem() + "\n");
                    }
                    if (stringBuilder.length() > 0)
                        LOGGER.warn("Retrieved warnings:\n" + stringBuilder);

                    LOGGER.info("Writing results to zip file");
                    File resultsFile = new File(ZIP_FILE);
                    FileOutputStream os = new FileOutputStream(resultsFile);
                    try
                    {
                        os.write(result.getZipFile());
                    }
                    finally
                    {
                        os.close();
                    }
                    break;
                case Failed:
                    throw new Exception(result.getErrorStatusCode() + " msg: " + result.getErrorMessage());
                default:
                    break;
            }

        }

private void setPackage(RetrieveRequest request, List<Table> tables)
    {
        com.sforce.soap.metadata.Package p = null;
        List<PackageTypeMembers> listPackageTypes = new ArrayList<PackageTypeMembers>();
        List<String> members = new LinkedList<String>();
        for (Table tbl : tables)
            members.add(Utility.getsObjName(tbl.getName()));
        PackageTypeMembers packageTypes = new PackageTypeMembers();
        packageTypes.setName("CustomObject");
        packageTypes.setMembers(members.toArray(new String[members.size()]));
        listPackageTypes.add(packageTypes);
        p = new com.sforce.soap.metadata.Package();
        PackageTypeMembers[] packageTypesArray = new PackageTypeMembers[listPackageTypes.size()];
        p.setTypes(listPackageTypes.toArray(packageTypesArray));
        p.setVersion(API_VERSION + "");
        request.setUnpackaged(p);
    }

Is there any way to retrieve the objects or do I have to resort to storing describeSObject() result for reference? The main reason is to make comparison between metadata during a period of time for detecting changes but I am not able to retrieve the metadata for a certain set of objects.

1 Answer 1

1

The answer is pretty much in the question. You simply can't retrieve non-customizable objects by way of the Metadata API. The reason why is because that's not the metadata API's purpose. If you want to describe objects, use REST to describe one object at a time, or SOAP to describe lists of 100 objects at a time.

2
  • My intent is to compare structural changes to an object. Going by this answer (salesforce.stackexchange.com/a/75588/18516), idea would be to compare the metadata object. If not, describeSObject() call. Is this the only way to do it?
    – dmachop
    Aug 5, 2015 at 18:06
  • 1
    @dmachop I'd just use describeSObject for all objects. There's really no need to use the metadata API unless you're trying to migrate those changes between orgs, in which case the migration couldn't include some objects (e.g. CaseFeed) anyways.
    – sfdcfox
    Aug 5, 2015 at 18:30

You must log in to answer this question.

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