[SalesForce] Metadata API – Struggling With First Custom Object + Fields Creation Project

Update:

First and foremost, this is all about building a proper package.xml, objects folder full of ___.object files, and profiles folder full of ___.profile files.

You do that, the rest is cake – ZIP it up and Workbench has your back.

See my further notes in the answers at https://salesforce.stackexchange.com/a/115186/17667.


Original Post:

I am finding the bar too high for first-time usage of the Salesforce Metadata API to create a few custom objects and fields.

Background:

I am in charge of setting up a Jitterbit connection from one production org to another. Before I set it up, I'll need copies of a few 4-5 source-org custom objects mirrored in the target-org, as well as copies of some of those custom objects' fields. (I tried using packages, but that didn't work because some of the objects are part of a managed package.)

Appearance on Page Layouts isn't a priority, nor is setting up any sort of special field security (easy to fix in bulk later compared to creating the fields – either "open to all" or "closed to all but sysadmins" is fine at time of creation).

As I figure out which source fields I'm actually going to need in the target, I'm basically building a list of their API names (although some will need renaming to avoid conflicts target org naming conflicts). I know I have the text-parsing skills to turn these notes into an XML representation of an object+fields without too much trouble.

Which means it feels* wasteful to build those object/field copies by hand in the target org. But that's what I'm going to do, because my ballpark estimate is 5 hours to build everything by hand, whereas I've already lost at least 8 trying to figure out "Newbie's First Metadata API Write". And I have about 5-10 hours left for this part of the project.

Still, for future reference, I'd love to be set up to do simple "create an object and its fields" operations against Salesforce orgs.

I've looked through the PDF manual and the Quick Start, but I feel like this documentation makes way too many presumptions that I already know what I'm doing with respect to setup.

  • For example, "Prerequisites" tells me to download the "Force.com WSC," but it completely skips over any instructions on what I'm supposed to do with the .jar file it links me to. I'm that noob.

So, below is an example of the kind of XML representation of a custom object that I know I could build without too much effort and would subsequently want to use for creating such an object in a target org.

My questions are:

  1. By any chance, is this XML and having the plain-old Eclipse Force.com IDE installed on my local machine sufficient for the task I want to accomplish?

    • If so, what steps am I missing to make the job happen? (I tried copying/pasting into another part of the project tree in Eclipse & saving to server / deploying. No dice.) Also, if so, skip Question #2.

    • If not, what would you say is minimum set of "for dummies" / "GUI preferred" pieces of software I need to install and configurations I need to make in addition to what I already have set up? (Win7x64, Chrome, Firefox, Eclipse+Force.com IDE)

  2. I know StackExchange isn't really for asking people, "Help me go from zero to hero in an entire development environment in a single question!" That's more the domain of tutorials & blog posts – shame on me. But I feel like the Salesforce developer community is currently missing such "Metadata API hello world" tutorials for people who are completely new to all of the tools involved (well, except to reading & writing simple Java-like code).

    If anyone is willing to help walk me through this, limited in scope to "creating a custom object with its custom fields," please let me know somehow.

    • The simpler, the better – for example, hand-typing a Salesforce session key into code right before executing it will suffice for this exercise.

    • I guess I should also mention that I don't have to use an XML like this. I could probably do enough text-parsing to build code that has the object & field names/descriptions inlined in string notation, too, if it keeps the whole solution simpler.

    • If the answer is big, maybe we can take the conversation outside StackExchange. Then once I've had my first success I'd love to help others by screenshotting the process for a blog post (my blog / your blog / a big newbie-blog like Women Code Heroes or SFDC99) and link to it here.

Of course, if there is such a tutorial out there already, my apologies and please just let me know where it is. (But remember that I already got lost even with the official "quick start!)

Thanks a million.

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <actionOverrides>
        <actionName>Accept</actionName>
        <type>Default</type>
    </actionOverrides>
    <actionOverrides>
        <actionName>CancelEdit</actionName>
        <type>Default</type>
    </actionOverrides>
    <actionOverrides>
        <actionName>Clone</actionName>
        <type>Default</type>
    </actionOverrides>
    <actionOverrides>
        <actionName>Delete</actionName>
        <type>Default</type>
    </actionOverrides>
    <actionOverrides>
        <actionName>Edit</actionName>
        <type>Default</type>
    </actionOverrides>
    <actionOverrides>
        <actionName>Follow</actionName>
        <type>Default</type>
    </actionOverrides>
    <actionOverrides>
        <actionName>List</actionName>
        <type>Default</type>
    </actionOverrides>
    <actionOverrides>
        <actionName>New</actionName>
        <type>Default</type>
    </actionOverrides>
    <actionOverrides>
        <actionName>SaveEdit</actionName>
        <type>Default</type>
    </actionOverrides>
    <actionOverrides>
        <actionName>Tab</actionName>
        <type>Default</type>
    </actionOverrides>
    <actionOverrides>
        <actionName>View</actionName>
        <type>Default</type>
    </actionOverrides>
    <compactLayoutAssignment>SYSTEM</compactLayoutAssignment>
    <deploymentStatus>Deployed</deploymentStatus>
    <description>zzzTestSmallObjectHasADescription</description>
    <enableActivities>false</enableActivities>
    <enableBulkApi>true</enableBulkApi>
    <enableFeeds>false</enableFeeds>
    <enableHistory>false</enableHistory>
    <enableReports>false</enableReports>
    <enableSharing>true</enableSharing>
    <enableStreamingApi>true</enableStreamingApi>
    <fields>
        <fullName>BoolCustField__c</fullName>
        <defaultValue>false</defaultValue>
        <description>ThisIsABoolCustField</description>
        <externalId>false</externalId>
        <inlineHelpText>ThisIsABoolCustField</inlineHelpText>
        <label>BoolCustField</label>
        <trackTrending>false</trackTrending>
        <type>Checkbox</type>
    </fields>
    <label>zzzTestSmallObject</label>
    <nameField>
        <label>zzzTestSmallObject Name</label>
        <type>Text</type>
    </nameField>
    <pluralLabel>zzzTestSmallObjects</pluralLabel>
    <searchLayouts/>
    <sharingModel>ReadWrite</sharingModel>
</CustomObject>

Best Answer

if you have setup ant correctly you can follow below steps

  1. Create deploy folder inside c:\apache-ant\sample folder
  2. Create one package.xml and objects folder

    <?xml version="1.0" encoding="UTF-8"?>
    <Package xmlns="http://soap.sforce.com/2006/04/metadata">
      <types>
        <members>xyz__c</members>
        <name>CustomObject</name>
    </types>
    <version>35.0</version>
    </Package>
    

enter image description here

  1. create a xml file inside objects folder and name it with xyz__c.object and put your xml content which you have added as question.

  2. I assume that you have setup ant deploy in build.xml so you can run command ant deploy and it will deploy this object in your target org.

Related Topic