Code Generation for Salesforce

The FuseIT SFDC Explorer can strongly type standard Salesforce objects in C#.NET for use with S4S. Developers can strongly type custom Salesforce records and fields or, alternatively, refer to these entities by their string name. There are advantages to both approaches. If choosing the strongly typed path, the custom entities need to be initially generated in C# and regenerated if changes are made to these objects in Salesforce.


If your coding preference is strongly typed C# objects over using string names to access custom fields in Salesforce then this can be achieved using the T4 template generation tab in FuseIT SFDC Explorer. There is a tab that is specifically for this purpose. Just drag the entities in the left panel to the surface and generate strongly typed C# custom objects that can be used in your Sitecore code. Note that you may need to make some namespace changes to the generated code.

Please note that although strongly typed objects are architecturally superior, using them adds effort when a developer needs to add a new Salesforce custom field to a custom web form. For this reason, most customers use string names to work with custom objects and fields.  

Code Generation using FuseIT SFDC Explorer

The fastest way to create strongly typed objects is to use the FuseIT SFDC Explorer (download here). This is a free windows application that lets you explore Salesforce using the same technology S4S uses. We recommend you download and use it to validate your calls to Salesforce, logins, generate T4 templates and much more – as can be seen in the tabs in the following image.

After logging into the FuseIT SFDC Explorer with your Salesforce credentials and security token, select the Code Generation (T4) tab.


Drag each Salesforce object from the left panel (see image below) onto the entity canvas then select Generate Selected Entities. 

Enter a Namespace and select the remaining options. Clicking Generate will create a folder at the nominated location containing the strongly typed C# classes that you can add to your .NET project.


For each Salesforce object (x) accessible via the Partner API the following classes will be generated:

  • x : EntityBase
    Represents a single object instance
  • xService : SalesforceServiceBase<x>
    Service class for performing CRUD (Create, Retrieve, Update, Delete) operations using the entity objects
  • xDataSource : SalesforceDataSource
    Provides querying against the specific object type with support for filters.

These generated classes can then be used for strongly typed data access into the specific Salesforce instance.