Angular module to normalize and denormalize Salesforce fields and object names.
Download the .js file from the dist folder or use Bower
$ bower install angular-normalize-salesforce --saveAfter including the dist file into your project you have to add the module as a dependency to your Angular project module:
angular.module('myModule',['angular-normalize-salesforce'])The normalizeSalesforce service offers 3 main methods:
normalize(part)
Supportsstring,array,object. It removes __c from the string, or all strings in the array. Ifpartis an object, all keys are normalized.denormalize(part, sObject)
Also supportsstring,arrayandobject. Needs the name of the sObject as a parameter to denormalize only custom fields and keep standard fields plain.denormalizeObjectName(name)
Supports only a plainstring. Adds __c to the given name, if the object is not a standard object.
This is a separate function to allow custom fields with the name of a standard object (e.g.Account__c)
In order to support all Salesforce standard objects, all standard fields have to be defined in the source code. We currently support all standard objects from API v34.0
angular.module('myModule',['angular-normalize-salesforce']);angular.module('myModule').factory('exampleFactory',['normalizeSalesforce',function(normalizeSalesforce){varsObject={'Field1__c': 'value1','field2__c': 'value2','ns__Field1__c': 'value3','Name': 'value4'};/** * Should return * { * 'field1': 'value1', * 'field2': 'value2', * 'ns_field1': 'value3', * 'name': 'value4' * } */console.log(normalizeSalesforce.normalize(sObject));varobject={'field1': 'value1','ns__field2': 'value2','name': 'value3'}/** * Should return * { * 'field1__c': 'value1', * 'ns__field2__c': 'value2', * 'name': 'value3' * } */console.log(normalizeSalesforce.denormalize(object,'CustomObject__c'));return'yeah :)';}]);- Install Node.js and NPM
- Install global dev dependencies:
npm install -g gulp - Install local dev dependencies:
npm install
- Build the whole project with
gulp
DEBUG.pbJSRestConnector.client.apiVersion="v37.0"allObjects=[]DEBUG.pbJSRestConnector.global(function(cb){allObjects=cb})allObjectsLowercased=_(allObjects.sobjects).filter({custom: false}).map('name').map(function(name){returnname.toLowerCase()}).value()standardFields={}_(allObjectsLowercased).each(function(objectName){DEBUG.pbJSRestConnector.describe(objectName,function(cb){standardFields[objectName]=_(cb.fields).filter({custom:false}).map('name').map(function(name){returnname.toLowerCase()}).value()})}).value()_(newData).each(function(value,key){if(!_.has(original,key)){original[key]=value}else{_.each(value,function(field){if(!_.contains(original[key],field)){original[key].push(field)}})}}).value()