What happened? Next steps Getting started Customizing ReadMe Feedback

Developing with Salesforce

Customizing the Scaffolding with T4 Templates

The code scaffolded into your project is based on T4 templates that you can customize.

The steps are the following:

The Salesforce Provider will look in the following directory for customized templates:
%userprofile%\Documents\Visual Studio 2015\Templates\ConnectedServiceTemplates\Visual C#\Salesforce
However, this directory doesn't exist by default, so you'll have to create the directory first.

Create the customized template directory

Finding the master templates

Each version of the Salesforce Provider will place master templates in the extension directory. The provider never reads from this directory. They are placed here for reference only. Each new version of the Salesforce Connected Services Provider will continue to place the master templates here to avoid overwriting any modifications you've made. If templates aren't found in the custom directory above, it will use templates from resources embedded in the provider.

With the directory in place, you can now copy the templates from the extension directory to the directory you just created.

Extensions are placed in a unique directory, so we'll need to do a quick search to find it.

There are three T4 templates:

Filename Description Project Location
SalesforceOAuthRedirectHandler.tt The template for the Web Server Flow redirect handler Service References\Salesforce\SalesforceOAuthRedirectHandler.cs
SalesforceObject.tt The Model template for each scaffolded Salesforce Object Models\Salesforce\*
SalesforceService.tt The tempalte that represents the configured service object Service References\Salesforce\SalesforceService

Copying the templates

Copy any, or all of the templates you wish to customize to the directory created above.

Editing T4 Templates

Within each template, you'll see a parameter which is referenced when completing the template. Below is an example from the SalesforceObject.tt template

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="Salesforce.VisualStudio.Services.dll" #>
<#@ import namespace="Salesforce.VisualStudio.Services.ConnectedService.CodeModel" #>
<#@ output extension=".cs" #>
<#@ parameter type="Salesforce.VisualStudio.Services.ConnectedService.CodeModel.GeneratedObject" name="generatedObject" #>
...
namespace <#= generatedObject.Service.ModelsNamespace #>
{
        public class <#= generatedObject.Model.Name #>
    {
<#

By referencing the generatedObject, and the properties on it you can populate values within the template.

Parameter Object Model

To view the object model of the parameter, use the Visual Studio Object Browser.

Finding the Salesforce dll

T4 Template Syntax Coloring

The Devart T4 Editor is a Visual Studio add-in for editing T4 templates with syntax highlighting, intellisense, code outlining, and all features of a first-class text editor add-in for Visual Studio.

Note: As of November 10th, 2014, DevArt has not yet provided a version for Visual Studio 2015 Preview. In the meantime, you can use Visual Studio 2013 to edit the T4 templates. We hope they'll have a preview version soon.

Frequently Asked Questions

Q: Why aren't the templates in this custom directory location already?

A: With each version of the Salesforce provider, we may update the template code. In order to provide you a copy to start with, without overwriting your custom edits, we needed a unique location to place the master templates

Q: Why isn't the custom directory created with the provider?

A: VSIX have limited access to the file system to assure they have limited impact to muck wiht the stability of your environment. In this case, the VSIX is unable to create directories outside the scope of the VSIX.

Q: Why not just create the directory under the extension?

A: When the extension is removed or updated, the extension directory is completely removed, which would delete any customizations you've created.

Suggested Improvements

If you find enhancements we should incorporate, please let us know at: UserVoice - Visual Studio Connected Services