Table of Contents


ForceUtility

This class provides utility methods to work with the Salesforce Platform within Magentrix.

 

Data Sync

If you require to force sync the data with Salesforce (Delta Sync), you can use the below code:

ForceUtility.PerformDeltaSync("Force__Opportunity");

 

Convert Salesforce IDs

In order to convert Salesforce IDs from 15 to 18 digit (case-insensitive):

//variable idIn15 is string
var id18 = ForceUtility.ID15to18(idIn15); 

 

Activate Assignment Rules for DML Operation

You can activate the assignment rules for Cases and Leads in Salesforce CRM by using the below methods:

ForceUtility.EnableAssignmentRules();
Create(lead);
ForceUtility.DisableAssignmentRules();

This feature becomes available in Release 21-2020.

 

Working with Salesforce Files

In order to create Salesforce files you need to use the below APIs:

// Creating a file using byte array, this method checks to see if user has permission to create files
var contentDocId = ForceUtility.CreateContentDocument(parentId, name, description, contentType, bytes);

// Creating a file using streams, this method checks to see if user has permission to create files
var contentDocId = ForceUtility.CreateContentDocument(parentId, name, description, contentType, contentStream);

// Creating a file in system mode (as administrator)
var contentDocId = ForceUtility.CreateContentDocumentAsAdmin(parentId, name, description, contentType, bytes);

// Update the Content file, when you make changes to Magentrix File's name or descriptionvar file = ForceUtility.UpdateContentDocument(id, parentId, title, description)

Note: parentId in the above examples is the ID of the record to which the file should be attached, such as Opportunity or Account record ID.

 

In order to download a Salesforce file via API:

var file = ForceUtility.DownloadContentDocument(string parentId, string contentDocumentId);

//file returned has the following properties:
var fileName = file.Name;
var fileSize = file.ContentSize;
var fileTitle = file.Title;
var fileExtension = file.FileExtension;
var contentDocumentId = file.ContentDocumentId;
var fileContent = file.Content;

Note: The file content is a Stream.

 

Manually Sync Deleted Records

You can manually sync deleted records from Salesforce to Mangetrix.

ForceUtility.SyncDeleteRecords(string entityName, DateTime since)
ForceUtility.SyncDeleteRecords<T>(DateTime since)