-
Notifications
You must be signed in to change notification settings - Fork 23
Picklists
As of version 2.1.1, ts-force now supports typed pick-list fields.
NOTE: You must use typescript > 3.4.x to use classes generated with picklists!
To enable generation of picklist enums, add "generatePicklists": true to your configuration json.
When generatePicklists=true, you can also choose to force pick-list fields to be typed to the generated enums via the enforcePicklistValues configuration:
-
false: do not enforce -
'RESTRICTED': only enforce type on pick-lists whereRestrict pick-list to the values defined in the value setis enabled in Salesforce -
'ALL': Restrict on all pick-lists regardless ofRestrictsettings in Salesforce (unless configuration point is overridden at the object level
These configuration points both the global level, as well as on the individual sObjects config (seem example below).
{
"sObjects": [
{
"apiName": "Account",
"enforcePicklistValues": "RESTRICTED"
},
{
"apiName": "Contact",
"generatePicklists": false
}
],
"generatePicklists": true,
"enforcePicklistValues": "ALL"
}
In the above example, pick-list enums will be generated for Account because it is set at the global level, but not for Contact because it is overridden at the object level. enforcePicklistValues is also overridden to restricted picklist fields only on Account.
Picklists are generated on a namespace that matches the generate SObject. The pick-list enums themselves, match the field name
const {type, industry} = Account.PICKLIST; //destructure for brevity
let acc = new Account({
type: type.PARTNER,
});
//multi-picklist
acc.industry = [industry.RETAIL, industry.B2B];"Multi-picklists" are now mapped to and from arrays during mapping from API to RestObject