Handling different types to map to Salesforce

I recently had a requirement that I was building upon which requires me to store couple additional fields on my xConnect Facet. I had to also show them on Experience profile, push this data when available from Sitecore to Salesforce and back. This additional information should also be available on SFMC when it is available. I knew the drill and did what I had to make this happen. String fields mapping was pretty straight forward and had done it couple times before this drill, so, will not focus on that, you can have a look at my other blog posts which should cover this information.

So, with this requirement we had different types of data that we had to map. For example, we had Boolean, DateTime, Currency and Number to new a few. For every single type of this, we need different handling to ensure the data maps to Salesforce and back successfully. Let’s see how its done:

Step 1: Extend your Facet with all the additional information

        public bool HasDonated { get; set; }
        public DateTime? MostRecentGiveLivelDonationDate { get; set; }
        public DateTime? MostRecentVoicifyDonationDate { get; set; }
        public int EngagementScore { get; set; }
        public decimal GiveLivelyDonationAmount { get; set; }
        public decimal VoicifyDonationAmount { get; set; }

As you can see we have bool, datetime (ensure this is defined nullable, if not, you will be in deep shit and mappings wont work to CRM and SFMC). Now, next up, lets see how mappings should be handled differently and special use of transformers might be needed. Let’s see on each case, how to properly handle. Do note this also depends on data direction, that is, if mapping is from Sitecore to Salesforce or from Salesforce to Sitecore. I will not cover steps needed to ensure this new additional fields are available to be utilized by updating custom collection model json and items. There is a whole different blog post for that.

Boolean Mapping:

This is the easiest one. 🙂 No special handling needed, it should simply work with same process we followed before here

DateTime Mapping:

I would like to stress again how important it is to define this property as nullable. See code snippet above and follow that. Do not waste hours of debugging like I did. 🙂

From Salesforce to Sitecore – See highlighted, it is available OOTB, just ensure you add this to ensure mapping works
From Sitecore to Salesforce – See highlighted, it is available OOTB, just ensure you add this to ensure mapping works

Int mapping:

From Salesforce to Sitecore – See highlighted, this is a new value reader that I had to add to ensure the mapping works and data flows properly.
Definition of value reader that is used as transformer in the step above. It is very important that Target type entered matches .Net type exactly as format shown. If you give just Int or Int32, it will not work.

Note: No special handling is needed to push this type from Sitecore to Salesforce, it just works just fine.

Decimal Mapping:

Very similar to int mapping noted above. I will add few screenshots for reference.

Note: No special handling is needed to push this type from Sitecore to Salesforce, it just works just fine.

Now this might seem pretty straight forward, but, this took me hours to figure out why something is not working as expected. Because there multiple point of failures and I was not able to put a finger on to why. When mappings fail, the logs were not very helpful, so, this required lot of trial and error to actually come up with solution for each of this use case. Hope this helps some one doing some gymnastics with Salesforce and SFMC.