function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
adreameradreamer 

CRUD-based development Metadata API

Hi All,

 

I am here below copying a paragraph from the Metadata API user guide that it is confusing me and I wonder if someone could shed some light.

 

You can modify metadata in test organizations on Developer Edition or sandbox, and then deploy tested changes to production organizations on Enterprise Edition or Unlimited Editions. You can also create scripts to populate a new organization with your custom objects, custom fields, and other components.

 

Does this means that the create(), update() and delete() calls of the Metadata API in a client running elsewhere outside salesforce would only work when calling a test/sandbox or developer orgs, and will not work for an Enterprise and Unlimited orgs ?.

 

Thank you very much in advance.

 

Best Answer chosen by Admin (Salesforce Developers) 
rungerrunger

It is always the case that metadata changes must go through a deploy to get to a production org.  Apex tests are not the only kind of sanity check performed in a deploy.

All Answers

rungerrunger

This is just saying that you can't change the metadata of a production org without doing a full metadata deploy.  This is for the same reason that you can't go into your production org and add arbitrary apex classes or custom objects through the UI.  It has to be done via a deploy process that runs tests, etc.

 

Rich

adreameradreamer

Hi Rich,

 

Thank you very much for your reply.

 

I understand from what you are saying that I cannot change the metadata of a prod org via the metadata api, and of course it makes sense what you say about deploying code and have it go through test methods.

 

In our case all we want to do is to add custom fields to a custom object that we deploy as part of our application. So basically we call the create() method to cfreate custom fields. Are you saying this will not work either ?.

 

Regards,

Fernando

rungerrunger

Sorry, I'm not quite understanding.  What create() method are you referring to?  Can you give me a sample of your code?  There are no apex methods for creating new custom fields, so far as I know.

 

Rich

adreameradreamer

Yes I think we are talking about different things. No worries.

 

I am talking about the create() method that is part of the Metadata API used in a server external to salesforce, say using Java, that allows one to modify the metadata of an org. For instance, to create custom fields in a standard or custom object.

 

Regards,

Fernando

rungerrunger

Ah, sorry, I see now how I misunderstood.  I tend to see everything through an Apex prism, since that's the team I'm on ;)

 

Yes, all metadata must be deploy()'ed to production orgs.  This is because there are all kinds of consistency checks that are only performed during a deploy, and production orgs require that extra sanity check.

 

Rich

adreameradreamer

Hi Rich,

 

Thank you for your replies.

 

I understand what you say about sanity checks performed when deploying to production orgs. That ceratinly would make sense when deploying Apex code (classes, triggers, etc.).

 

Hoevere here I am talking about adding custom fields to a custom object only. There is no code involve. This is something that one can do within a production org with the standard Salesforce UI. I would expect the Metadata API being behind these type of customizations.

 

So now more to the point, is it still the case that we have to go through deployment ?.

 

Regards,

Fernando

rungerrunger

It is always the case that metadata changes must go through a deploy to get to a production org.  Apex tests are not the only kind of sanity check performed in a deploy.

This was selected as the best answer
adreameradreamer

Thank you very much for your help !

adreameradreamer

Hi Rich,

 

A follow up on a related issue.

 

I have code in a server outside salesforce that creates custom fields on a custom object using the Metadata API. It creates the deployment XML file on the fly and calls deploy(). This works fine.

 

The question is: does this deployment kick any run of test code ?.

 

The custom object is part of a package.

 

Thanks

Fernando

rungerrunger

Again you have me a bit confused. You can't use metadata deploy on part of a package.

adreameradreamer

Hi Rich,

 

Thanks for the prompt reply.

 

Sorry I was not clear. Let me try again.

 

First, a user install our package.

 

Second, as part of the functionality, at some point the package interacts with our server.

 

Third, in this interaction between Salesforce and our  server, the server uses the Declarative (File-Based) Metadata API. Basically, we create a zip file on the fly, which contains the package.xml manifest, and XML components organized in folders. We use the deploy() method to deploy the zip file. This has been working for a long time, no problem.

 

In all cases the deployment involves creation of custom fields in one custom object that is part of our package, and exists in the target org because the package is already installed.

 

My question is: this on-the-fly deployment from our server, does kick a run of test classes in the target org ?. I can tell it does, but what is not clear is what tests it runs. For instance, does it run all the test code in the target org (including other packages or custom development) ? . What is the criteria to decide what to run ?

 

Thanks again Rich.

Fernando

rungerrunger

Ah, now I understand.

Yes, it runs all the tests in the customer's org. It is making sure that the overall code coverage in the org is >75%.

adreameradreamer

Thanks Rich !

 

Just to make sure I undestand, when you say it runs all tests in the customer's org you mean:

 

- all the custom developed classes and triggers

- all the code in all unmanaged/managed pakages

- including our package (managed-release)

 

Cheers

Fernando

rungerrunger

I believe it depends on the deploy option you specify. You can either run ALL tests (customer's and all packages), or just the ones authored by the customer.

adreameradreamer

Great, I am making progress here. Thanks Rich.

 

We currently use only 2 options:

 

performanceRetrieve = false

rollBackOnError = true

 

Since our remote deployment only deals with custom fields in one of our managed-release package custom object, I would like to make it as independent as possible from any other code in the target org. For example, if the target org has a class or a trigger with badly written test code that fails, I do not want this to affect our on-the-fly deployment. 

 

The question now is what options we have and to what extent we can control that.

 

Looking at the documentation on the deploy options I see:

 

runAllTests

According to tthe doc "For deployment to a production organization, all tests, except for those that originate from installed managed packages, are automatically run regardless of this argument. If any of the tests fail when the rollbackOnError parameter is set to true, the entire deployment will roll back."

 

Do I understand correctly that setting runAllTest=false will not run any test from the installed managed packages, but it will run all other tests from classes and triggers in unmanaged packages or standalone ?

 

The issue I am having is that for a particular customer the deployment fails because it says that there is only 65% code coverage. I am pretty sure this is not from our package, so it must be coming from some other code in their org. What would you suggest as deploy options to be as independent as possible from code outside our package ?

 

Thank you very much Rich. As always you are helping us !

performRetrieve
rungerrunger

Unfortunately, with deploy (which is really intended to be used by the customer, not by packages), you're stuck running the customer's tests. They really need to up their code coverage for your process to work.

 

We're working on ways to be more flexible in this area, but nothing that's likely to be released in the next couple of releases.

adreameradreamer

I understand.

 

But if I add the option runAllTest=false do at least exclude all the managed packages installed in the target org ?

 

Thanks

rungerrunger

I believe so, yes.

adreameradreamer

Hi Rich

 

As always you have been a great help.

 

Thank you !

Apex LearnerApex Learner

is there any way to edit picklist value through metadat API . 

I am current testing meta data API via SOAP ui and till now I am able to add picklist values .

but can not edit any perticuler picklist value 

 

eg . object : lead 

       field : number__c

  type : picklist

 

values : 1 , 2

 

any methode i cn edit 1 to 11  ??

 

Apex LearnerApex Learner

hi i have been  woring on METADATA Api 

 

and i have successfully create soap envelope to add new picklist value in picklist field

via

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:met="http://soap.sforce.com/2006/04/metadata">
   <soapenv:Header>
      <met:CallOptions>
         <met:client>---</met:client>
      </met:CallOptions>
      <met:SessionHeader>
         <met:sessionId>---</met:sessionId>
      </met:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <update xmlns="http://soap.sforce.com/2006/04/metadata">
     <!--Zero or more repetitions:-->
      <UpdateMetadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="customfield">
		    <currentName>lead.number__c</currentName>
		                
		      <metadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CustomField">
		      <!--Optional:-->
		       <fullName>lead.number__c</fullName>
		       <label>number</label>
		    		<picklist>
		              <picklistValues>
		         			<fullName>new</fullName>
		              </picklistValues>
		         		 <sorted>false</sorted>
		  		</picklist>
		         <type>Picklist</type>
		    </metadata>
         </UpdateMetadata>
       </update>
   </soapenv:Body>
</soapenv:Envelope>

 Now issues I am facing , is

Is there any way to update / edit any particular picklist value ???

 

e.g , Object : Lead , field : number__c, type : picklist , picklist values : new , old 

 

any way i can edit "new " to "new_value" via meta data API .

 

Thanks in advance

Jerun JoseJerun Jose
Hi

Did you find a solution for this?