...
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:
Code Block | ||
---|---|---|
| ||
//sfEntityName can be "Lead" or "Contact" GenericSalesforceEntity genericEntity = new GenericSalesforceEntity(sfEntityName); FieldService fieldService = FieldService.Instance(sfEntityName, submitAction.SalesforceSessionInstance); List<SalesforceField> salesforceFields = fieldService.FieldsForObject(); //populate theSet WFFM form field vales into Salesforce entity fields according to mapping details submitAction.SetEntity(ref genericEntity, fields, salesforceFields, mapping); //get analytics data for current user WebToEntity webToSfEntity = new WebToEntity(); //Get current sitecore contact's visitor id string visitorid = webToSfEntity.GetCurrentVisitorId(); Int32 totalVisitsValue = 0; Int32 totalPageCount = 0; string goalReached = string.Empty; //populate the Sitecore analytics fieldsGet total visit value, total page count and goals reached for the relavant sitecore visitor id if (webToSfEntity.GetVisitsData(visitorid, out totalVisitsValue, out totalPageCount, out goalReached)) { //Update genericEntity object with above values webToSfEntity.UpdateSfEntityAnalyticsFields(genericEntity, fieldService, visitorid, totalVisitsValue, totalPageCount, goalReached); } SaveResult saveResult; try { //saveSave Salesforce entity SaveResult(Contact saveResult;or tryLead) { GenericSalesforceService genericSalesforceService = submitAction.GenericSalesforceServiceInstance(sfEntityName); saveResult = genericSalesforceService.Save(genericEntity); idValue = saveResult.id; List<SitecoreVisit> sitecoreVisits; //Get Sitecore contact's visit information if (webToSfEntity.GetContactData(visitorid, numVisits, out sitecoreVisits)) { try { //Get a list of GenericSalesforceEntity objects which has been created using Sitecore visit information. This list includes Sitecore visits, goals, profiles and patterncards as GenericSalesforceEntity objects 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) { … } |