54

My condolences if you're reading this, because it means that you're being tortured by an extremely useless and vague error message. Let's see if we can get through this without tearing out too much hair. :-) Deployment Error or DML Error? If you Google "duplicate value found: <unknown>...", the results you get will cover a wide variety of ...


53

it's definitely possible to use CRUD based Metadata API calls in APEX. salesforce to salesforce and even loopback inside the same instance, we tried both. Adam already mentioned that a major part of the functionality is based on zipped metadata packages which cannot be created or unzipped using apex. however you can still create custom fields or objects ...


48

I can confirm that it is indeed possible as h9nry has pointed out. I also had some issues getting the WSDL2Apex tool to generate anything usable, but was finally successful! I really wanted to use the generated Apex code rather than construct and parse the XML. The main key is getting it to output the xsi:type attribute to indicate the type of component ...


41

Apex Metadata API Introduction. The Salesforce Metadata API allows you to perform many org configuration and setup features programatically. Code examples given by Salesforce are in Java as the API is a SOAP API. In respect to the Apex library provided here, it wraps via the provided MetadataService.cls class the Salesforce SOAP version of the API to make it ...


30

While there is overlap, the Tooling API is specifically designed to help developers build IDE apps for salesforce, while the metadata API is more general purpose configuration migration. For example, you can get a symbol table for a class, such as it's members and functions, without writing your own parser. The metadata API is suitable for simple migrations, ...


28

So, as it turns outs there is no way of getting a valid API-capable Session Id from lightning component, here is a quote from the partner discussion forums: Three things: There's no $Api global variable in Lightning Components today. So, {! $Api.whatever } will always fail. This is intentional at this time. There's no official/supported way to get an API-...


25

To fetch objects from a managed package using the unmanaged package.xml, you need to explicitly call for each object, as the wildcard only retrieves objects outside a package. To retrieve layouts you need to include the full (namespaced) object name before the hyphen, and the full (namespaced) layout name after the hyphen. So for a packaged layout over a ...


22

Kris- We use ANT in our automated build process because we can invoke it programmatically (with SH/Jenkins, etc.) to move code between orgs and run tests without having to open an IDE, create a change-set etc. This helps our development process because we need to move code between non-namespaced and namespaced orgs and do some tweaking to it before we can ...


19

It turns out the following DeployOptions setting was what I was missing: singlePackage boolean Indicates whether the specified .zip file points to a directory structure with a single package (true) or a set of packages (false). I needed to set this to true, as I assume my flat zip file represents a single package. After doing that the Number of ...


18

It'll take some heavy lifting, but you can do this with the metadata API or ANT. Step 1 Figure out what components are available Use a describeMetadata() call to get a list of all metadata component types that are available for retrieval. It'll return the name to use in your package.xml, as well as info about if it's stored in a folder. Unfortunately it ...


17

A hidden gem in the Metadata API deploy operation takes a DeployOptions structure, in it is a purgeOnDelete setting that will do what you need! purgeOnDelete. If true, the deleted components in the destructiveChanges.xml manifest file aren't stored in the Recycle Bin. Instead, they become immediately eligible for deletion. This field is available in API ...


16

There are a couple of routes into listing packages giving both the namespace and versions of those installed in your org via the Metadata API. In summary you have two routes, that both result in the same information... listMetadata call followed by retrieve call. The first is to use the 'listMetadata' operation using the InstalledPackage component type, ...


16

You are looking for DescribeFieldResult.getLength(): For string fields, returns the maximum size of the field in Unicode characters (not bytes). Schema.DescribeFieldResult F = Account.AccountNumber.getDescribe(); Integer lengthOfField = F.getLength();


16

We are still working out the details of this type of access - there are multiple reasons we have this in place today: security as discussed in my other posts/answers performance: direct access via arbitrary XHR client code cannot take advantage of the scarce resource (connections) management infrastructure provided by Lightning's Action Service. We've had ...


14

As of Summer '19 (v46.0), the INVALID_OPERATION errors you were hitting are no longer an issue! force:source:deploy now works when deploying to production. See an example below: sfdx force:source:deploy -m ApexClass:MyApexClass -l RunSpecifiedTests -r MyApexClass_Test -w 3 -u MyProductionOrg


14

As per the discussion with Pranay in the comments, the cause of the issue was the "singlePackage" setting in the deploy options. Indicates whether the specified .zip file points to a directory structure with a single package (true) or a set of packages (false). Typically my deployment tooling would have this set to true (and then would work fine with v45....


13

This is pretty straightforward in both Apex and Visualforce using describes: Apex: Integer len = SObjectType.Object__c.Fields.Field__c.Length; Visualforce: {!$ObjectType.Object__c.Fields.Field__c.Length}


12

Here's what I did.... I was receiving this error when trying to do a whole bunch of changes to my internal customized code base (uninstalled an unmanaged package which was basically a way of migrating stuff from another instance, but I was tired of it being coupled to this unmanaged package). Here's how I dealt with them, one by one: Save error: ...


12

I think you might be referring to the brand-spanking-new UI API. https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_get_started.htm User Interface API enables you to create native mobile apps and custom web apps with your own branding and look and feel. A single REST request returns enough metadata, layout information, and data to ...


11

Good question, both these things are not as clear as they should be in the docs. Here are some points that can help you. Discovering all Metadata Types. This topic in the documentation gives you the top level types. However you will notice that other types such as CustomField or ValidationRule are not listed. This is due to them being child meta types. ...


11

It does not have to be through the retrieve->deploy process. I got this to work using CRUD metadata api calls. This is the meat of the logic in C# Logger.Info("SalesForceProxy.UpdateFieldVisibility invoked. (Profiles: {0}; Fields: {1})", String.Join(", ", profilefullNames), String.Join(", ", fieldfullNames)); if (String.IsNullOrWhiteSpace(...


11

You can actually call the metadata API from JavaScript exceptionally easy. I threw this together in response to this question: var binding = new XMLHttpRequest(), payload = '<?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"> <...


10

You should contain the package within a single folder of the ZIP file, like this: + Zip File |-- src |-- package.xml +-- classes |-- MyCustomWrapper.cls |-- MyCustomWrapper.cls-meta.xml The system saw a single folder in the ZIP file, and assumed that that was the wrapper folder.


10

Disclaimer: I work for Gearset. You could use Gearset (http://gearset.com) - we built it for exactly this purpose! We do several things around tracking and migrating changes between orgs that might help in this scenario: Daily scheduled comparisons to show org changes over time (great for auditing changes that have happened to an org since you last "...


10

Here is a listing of all standard profiles and their license key definition and their corresponding metadata API Name, when performing a retrieve: Unfortunately SFSE does not have markdown for tables so I have added as a picture to preserve formatting. Developer documentation for metadata API and profiles SOAP API documentation for User License Key


10

Use Schema.getGlobalDescribe() method that accepts String as API name of object and then use getMap() method to get map of SObjectFields String objectName = 'Opportunity'; String fieldName = 'AccountId'; Schema.DescribeFieldResult f = Schema.getGlobalDescribe() .get(objectName) .getDescribe() .fields .getMap() .get(fieldName) ....


10

This is a very similar scenario to what is occurring in Tooling API in Apex - polymorphism, generic query() callout? and is caused by an underlying limitation in Wsdl2Apex and WebServiceCallout.invoke(). The Metadata API readMetadata web method returns a generic ReadResult with records of type tns:Metadata: <xsd:complexType name="ReadResult"> <...


10

You have two choices. First, you can use force:package commands to create an unlocked package. You can install this in production with force:package:install; it is similar to installing an AppExchange package. Otherwise, you would need to use force:source:convert to get a mdapi style format, then use force:mdapi:deploy with the relevant test level (e.g. ...


9

It appears there is something special about the meta data for a Connected App. I have one in my Dev org, but I can't add it to an unmanaged package. However, in a managed package the "Connected App" Component Type appears. Based on the managed package component type select options I'd expect the Metadata component to be "ConnectedApplication2". As you ...


9

The "correct answer" is that administrators are expected to configure any endpoints that they need to use manually in a situation like this. This is a one time process, takes only a minute to complete, and is often used in packages that access salesforce.com servers. This is the best solution, because with the addition of "my domain" settings, there are ...


Only top voted, non community-wiki answers of a minimum length are eligible