Created
March 13, 2017 14:10
-
-
Save TonyRenHK/f69d3f9ad26fac9e777a4f429ec27354 to your computer and use it in GitHub Desktop.
JSForce MeataData Backup.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jsforce = require('jsforce'); | |
var conn = new jsforce.Connection({ | |
loginUrl: 'https://test.salesforce.com', //'https://login.salesforce.com', | |
version: '36.0' | |
}); | |
conn.login('youSFDC@Account', 'YourPassword', function(err, res) { | |
if (err) { | |
return console.error(err); | |
} | |
var fullNames = [ 'Plan__c', 'ObjectName' ]; | |
conn.metadata.read('CustomObject', fullNames, function(err, metadata) { | |
if (err) { console.error(err); } | |
for (var i=0; i < metadata.length; i++) { | |
var meta = metadata[i]; | |
//console.log(meta); | |
// convert json object to string js | |
writefile(meta.fullName,JSON.stringify(meta)); | |
console.log("Full Name: " + meta.fullName); | |
console.log("Fields count: " + meta.fields.length); | |
console.log("Sharing Model: " + meta.sharingModel); | |
} | |
}); | |
}); | |
//Write the String to the file | |
function writefile(InputName,InputBody){ | |
var beautify = require('js-beautify').js_beautify,fs = require('fs'); | |
fs.writeFile(InputName, beautify(InputBody, { indent_size: 2 }), function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
//console.log("The file"+InputName+" was saved!"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment