/
Working with the SalesforceGenericEntity
Working with the SalesforceGenericEntity
The GenericSalesforceEntity can be used to work with both standard and custom Salesforce Objects. The GenericSalesforceService is used to perform CRUD on the GenericSalesforceEntity instances. When working with Salesforce Objects and Fields, it is necesary to use their API names.
Working with a Standard Salesforce Object
The following code shows how to work with a standard Salesforce Object. In this case the Contact Object:
SalesforceSession salesforceSession = SessionTest.GetSalesforceSession();
GenericSalesforceService genericSalesforceService = new GenericSalesforceService(salesforceSession, "Contact");
GenericSalesforceEntity genericContact = new GenericSalesforceEntity("Contact");
genericContact.InternalFields["FirstName"] = "Firstname";
genericContact.InternalFields["LastName"] = "Lastname";
genericContact.InternalFields["Email"] = "test@test.com";
genericContact.InternalFields["My_Custom_Field__c"] = "My Value";
SaveResult saveResult = genericSalesforceService.Save(genericContact);
//Validate the insert
ContactService contactService = new ContactService(salesforceSession);
Contact contact = contactService.GetByEntityId(saveResult.id);
Assert.AreEqual(genericContact.InternalFields["FirstName"], contact.FirstName);
Assert.AreEqual(genericContact.InternalFields["My_Custom_Field__c"], contact.InternalFields["My_Custom_Field__c"]); |
Working with a Custom Salesforce Object
The following code shows how to work with a custom Salesforce Object:
SalesforceSession salesforceSession = SessionTest.GetActiveSession();
GenericSalesforceService genericSalesforceService = new GenericSalesforceService(salesforceSession, "S4S__Project__c");
GenericSalesforceEntity genericEntity= new GenericSalesforceEntity("Project__c");
genericEntity.InternalFields["Name"] = "My Name";
genericEntity.InternalFields["Custom_Text_Field__c"] = "My Custom Field Value";
SaveResult saveResult = genericSalesforceService.Save(genericEntity);
//Validate the insert
GenericSalesforceEntity validateGenericEntity = genericSalesforceService.GetByEntityId(saveResult.id);
Assert.AreEqual(validateGenericEntity.InternalFields["Name"], genericEntity.InternalFields["Name"]);
Assert.AreEqual(validateGenericEntity.InternalFields["My_Custom_Field__c"], genericEntity.InternalFields["My_Custom_Field__c"]);
//How to delete a Generic Entity
genericSalesforceService.DeleteEntity(validateGenericEntity); |
, multiple selections available,
Related content
S4S Code Examples
S4S Code Examples
Read with this
Retrieving a Specific Salesforce Entity
Retrieving a Specific Salesforce Entity
More like this
Update an Existing Lead
Update an Existing Lead
More like this
Finding the RecordType
Finding the RecordType
More like this
Methods
Methods
More like this
Create a new Person Account
Create a new Person Account
More like this