Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)
edited by

// creating metadata

var metadata = {

  fullName: 'SampleObject__c', 

  label: 'Sample Object',

  label: 'Sample Object',

  pluralLabel: 'Sample Object',

  nameField: {

    type: 'Text',

    label: 'Sample Object'

  },

  deploymentStatus: 'Deployed',

  sharingModel: 'ReadWrite'

};

conn.metadata.create('CustomObject', metadata, function(err, results) {

  if (err) { 

    console.err(err); 

  }

  else{

    console.log('success ? : ' + result.success);

    console.log('fullName : ' + result.fullName);

  }

});

I'm not able to create a customField here. The only Object is getting created and there is no documentation available to create a custom field using jsforce. I have tried one approach, i.e, after successful creation of the custom object, I have updated the metadata with custom fields, but failed. What is the approach to create customFields in the customObject.

1 Answer

0 votes
by (32.1k points)
edited by

In order to solve this issue, add an array of fields to your custom object metadata definition. I had a hard time with this too. I figured it out by creating the fields in Salesforce setup->create->objects (point and click admin) and then reading the metadata produced via:

conn.metadata.read(type, [fullName1, fullName2, ..], callback)     

Put the array of objects below into the metadata variable and it should work.

fields: [ { fullName: 'A_Value__c',

           externalId: 'false',

                label: 'A Value 2',

           precision: '18',

            required: 'false',

               scale: '0',

       trackTrending: 'false',

                type: 'Number',

              unique: 'false' },

         {  fullName: 'A3_Value__c',

          externalId: 'false',

               label: 'A Value 3',

           precision: '18',

            required: 'false',

               scale: '0',

       trackTrending: 'false',

                type: 'Number',

              unique: 'false' } ],

Want to become a salesforce Analyst, here's a Salesforce Course for you! 

Browse Categories

...