S4S includes what we call disparate updates. This is where you can update multiple objects in Salesforce with a single API call which will help keep the API count down. The following code shows how the DisparateSalesforceService can send multiple entities, in this case, analytics objects, to Salesforce.
The highlighted code shows where the multiple entries are populated. The code can be included in a custom WFFM Submit Action or modified for use with a Sitecore custom form. The implementing class, FuseIT.S4S.WebToSalesforce.WebToEnitity, is used as follows:
GenericSalesforceEntity genericEntity = new GenericSalesforceEntity(sfEntityName); FieldService fieldService = FieldService.Instance(sfEntityName, submitAction.SalesforceSessionInstance); List<SalesforceField> salesforceFields = fieldService.FieldsForObject(); //populate the entity fields submitAction.SetEntity(ref genericEntity, fields, salesforceFields, mapping); //get analytics data for current user WebToEntity webToSfEntity = new WebToEntity(); string visitorid = webToSfEntity.GetCurrentVisitorId(); Int32 totalVisitsValue = 0; Int32 totalPageCount = 0; string goalReached = string.Empty; //populate the Sitecore analytics fields if (webToSfEntity.GetVisitsData(visitorid, out totalVisitsValue, out totalPageCount, out goalReached)) { webToSfEntity.UpdateSfEntityAnalyticsFields(genericEntity, fieldService, visitorid, totalVisitsValue, totalPageCount, goalReached); } //save Salesforce entity SaveResult saveResult; try { GenericSalesforceService genericSalesforceService = submitAction.GenericSalesforceServiceInstance(sfEntityName); saveResult = genericSalesforceService.Save(genericEntity); idValue = saveResult.id; List<SitecoreVisit> sitecoreVisits; if (webToSfEntity.GetContactData(visitorid, numVisits, out sitecoreVisits)) { try { List<EntityBase> entities = webToSfEntity.UpdateSitecoreAnalyticsInSalesforce(idValue, sfEntityName, sitecoreVisits); DisparateSalesforceService disparateSalesforceService = new DisparateSalesforceService(submitAction.SalesforceSessionInstance); //Insert records in batch SaveResult[] saveResults = disparateSalesforceService.InsertEntities(entities); } catch (SalesforceException sfEx) { if (sfEx.GetType() != typeof(SalesforceCreateException) && sfEx.Message.Contains("DUPLICATE_VALUE")) { Logging.Error(this, "Update Analytics failed with Salesforce Exception.", sfEx); throw; } } } else { Logging.Warn(this, "Unable to get Analytics data for contact Id: " + visitorid); } } catch (Exception ex) { … }