CSV to Apex

Upload a csv file with object, field, datatype and list columns to generate apex classes.

All generated apex classes will have the Prefix as the start of the class name, custom datatypes in the csv file should already have this prefix if they refer to objects that will be generated.

Example

A CSV file with the these contents object,field,data_type Contact,Name,String Contact,Age,Integer Contact,BirthDate,Date Contact,Address,String Contact,PostalCode,String Contact,City,String Contact,Country,String Contact,BankAccounts,List<myapi_BankAccount> Contact,Account,myapi_Account BankAccount,IBAN,String BankAccount,BIC,String Account,Name,String Account,Phone,String Account,Email,String Account,NetWorth,Decimal Account,Contacts,List<myapi_Contact> and a prefix of myapi_ will generate a zip-file containing the following files

  • myapi_Object.cls - a base object class from which the others inherit
  • myapi_Exception.cls - a custom exception class
  • myapi_Utils.cls - a utilities class with functions used for parsing json. If, for example, your api uses numeric timestamps instead of ISO-8601 strings you can modify the parseDatetime function in this class.
  • myapi_Account.cls - The Account object with the fields from the CSV file.
  • myapi_Contact.cls - The Contact object with the fields from the CSV file.
  • myapi_BankAccount.cls - The BankAccount object with the fields from the CSV file.
  • + Test classes and a .cls-meta.xml file for each class

Optionally, you can include a description column in the CSV file whose values will be added in de code comments for each propperty in the generated classes.

Each of the generated objects will have:

  • A constructor that accepts a JSON string as input
  • A constructor that accepts a System.JSONParser as input
  • Two parse functions with the same parameters
  • A void toJsonString function that accepts a System.JSONGenerator
  • A String toJsonString function with no input parameters
  • A convertList function for conveniently casting a list of generic objects
  • The properties as listed in the CSV file, prefixed with p_ to avoid conflicts with reserved words.
  • >90% test coverage

Because indentation is hard, and preferences vary, you may want to run prettier on the generated code 😶

Source available at: