Salesforce SObject Metadata Converter
Salesforce SObject Metadata Converter
Install
$ npm install -g sf-metadata-converter
Usage
$ export SALESFORCE_USERNAME=xxx$ export SALESFORCE_PASSWORD=xxx$ sfmconv -T Account
output
{ thisId = paramsId; thisIsDeleted = paramsIsDeleted; thisMasterRecordId = paramsMasterRecordId; thisName = paramsName; thisType = paramsType; thisRecordTypeId = paramsRecordTypeId; thisParentId = paramsParentId;// ... }
builtin template
builtin template is js(default), typescript, apex
This is example for apex template
$ sfmconv -T Account -t apex
output
// generated by salesforce2jspublic with sharing class AccountApiController { public AccountApiController() {} @RemoteAction public static Map<String, Object> query(String query) { return new Map<String, Object> { 'success' => true, 'records' => Database.query(query) }; } @RemoteAction public static Map<String, Object> create(Map<String, Object> properties) { Account obj = new Account(); obj.Id = properties.get('Id'); obj.IsDeleted = properties.get('IsDeleted'); obj.MasterRecordId = properties.get('MasterRecordId'); obj.Name = properties.get('Name'); obj.Type = properties.get('Type'); obj.RecordTypeId = properties.get('RecordTypeId'); obj.ParentId = properties.get('ParentId');// ... try { insert obj; return new Map<String, Object>{ 'success' => true, 'id' => obj.Id }; } catch (Exception e) { return new Map<String, Object> { 'success' => false, 'error' => e.getMessage() }; } } @RemoteAction public static Map<String, Object> updateRecord(String sfid, Map<String, Object> properties) { Account obj = [SELECT Id FROM Account WHERE Id = :sfid]; obj.Id = properties.get('Id'); obj.IsDeleted = properties.get('IsDeleted'); obj.MasterRecordId = properties.get('MasterRecordId'); obj.Name = properties.get('Name'); obj.Type = properties.get('Type'); obj.RecordTypeId = properties.get('RecordTypeId'); obj.ParentId = properties.get('ParentId');// ... try { update obj; return new Map<String, Object>{ 'success' => true, 'id' => obj.Id }; } catch (Exception e) { return new Map<String, Object> { 'success' => false, 'error' => e.getMessage() }; } } @RemoteAction public static Map<String, Object> destroy(String sfid) { try { Database.DeleteResult dr = Database.delete(sfid); return new Map<String, Object> { 'success' => dr.isSuccess() }; } catch (Exception e) { return new Map<String, Object> { 'success' => false, 'error' => e.getMessage() }; } }}
Custom template
You can specify custom template file.
$ cat << EOS > template.txtHello <%= name %>EOS
put this command
$ sfmconv -T Account -t template.txt
output
Hello Account