sf-metadata-converter
v0.1.6
Published
Salesforce SObject Metadata Converter
Downloads
9
Readme
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
export default class Account {
constructor(params) {
this.Id = params.Id;
this.IsDeleted = params.IsDeleted;
this.MasterRecordId = params.MasterRecordId;
this.Name = params.Name;
this.Type = params.Type;
this.RecordTypeId = params.RecordTypeId;
this.ParentId = params.ParentId;
// ...
}
}
builtin template
builtin template is js(default), typescript, apex
This is example for apex template
$ sfmconv -T Account -t apex
output
// generated by salesforce2js
public 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.txt
Hello <%= name %>
EOS
put this command
$ sfmconv -T Account -t template.txt
output
Hello Account