What records sync to your website

When you install the StoreConnect package, a StoreConnect External ID (SCID) field is added to many standard and custom objects used by the package. This field is required on some objects to assist synchronisation between Salesforce and your website.

For standard objects where records could be created from the website, the SCID gets populated on creation, regardless of if created from the website or from in Salesforce. To avoid triggering flows unexpectedly, pre-existing records in these objects will not have an SCID populated on install so won't sync down to the website initially.

The objects include:

  • Account
  • Contact
  • Order
  • Order Item
  • Campaign Member
  • Asset
  • Lead

All other objects used by StoreConnect sync to and are made available to your website

Populating scid on standard objects

For all objects with an SCID field, the SCID is populated automatically on record creation.

Other than for Contacts, existing records in standard objects have their SCID auto populated when the record is next updated after installing the StoreConnect package.

For contacts, there are ways for you to populate this field if required

  1. Inviting or triggering a password reset from the contact record will automatically populate SCID
  2. Via a Quick Action provided by our package
  3. In Bulk via Dataloader or any similar tool

Note: Any action that adds an SCID to a contact will also add an SCID to the primary account if it doesn't already have one. This will ensure that contacts are never synced without their account.

Quick action

The Contact object has a Quick Action that auto populates the SCID field if it is empty. It can be added to your page layout if you want to use it.

  • Go to the contact's detail page
  • Find and select the quick action 'Sync to SC'
  • It will populate the SCID with a confirmation message

For other objects, such as Account, we don't supply this quick action but you could add your own if it is desired.

  • Go to Setup > Object Manager > Account (or any other desired object)
  • On the sidebar, select 'Button, Links, and Actions'
  • On the top right hand corner of the panel, select 'New Action'
  • Select Action Type 'Lightning Component'
  • Select Lightning Component 's_c:ApplyScIdActionWrapper'
  • Add a label, like "Sync to SC"
  • Then add the action to your page layout

Bulk update

If there are many records, the objects SCID's should be populated in bulk.

  • Use a tool like UUID Generator to generate multiple SCIDs at the same time
    • Add these IDs to your CSV
    • Import via Dataloader or similar
  • Use the below APEX to genrate and populate the SCID for your Contacts.

SCID's must be unique within each object and made up of 36 characters.

/*
How to generate a version 4 GUID (random)

1. Generate 128 random bits
2. Set the version: Take the 7th byte perform an AND operation with 0x0f followed by an OR operation of 0x40.
3. Set the variant: Take the 9th byte perform an AND operation with 0x3f followed by an OR operation of 0x80.
4. Convert the data to hex and add dashes
*/

public class GuidUtil {
    static List hexMap = new List {
        '0', '1', '2', '3', '4', '5', '6', '7',
        '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
    };

    public static String newGuid() {
        String randomStringAsHex = EncodingUtil.ConvertTohex(Crypto.GenerateAESKey(128));

        String versionHexBits = randomStringAsHex.SubString(14,16); // 7th bit
        String variantHexBits = randomStringAsHex.SubString(18,20); // 9th bit

        Integer versionIntBits = convertHexToInt(versionHexBits);
        Integer variantIntBits = convertHexToInt(variantHexBits);

        Integer versionShiftedIntBits = versionIntBits & 15 | 64;  // (i & 0x0f) | 0x40
        Integer variantShiftedIntBits = variantIntBits & 63 | 128; // (i & 0x3f) | 0x80

        String versionShiftedHexBits = convertIntToHex(versionShiftedIntBits); // Always begins with 4
        String variantShiftedHexBits = convertIntToHex(variantShiftedIntBits); // Always begins with one of 8,9,a,b

        String guid = randomStringAsHex.SubString(0,8) + '-' + randomStringAsHex.SubString(8,12) + '-' + versionShiftedHexBits + randomStringAsHex.SubString(14,16) + '-' + variantShiftedHexBits + randomStringAsHex.SubString(18,20) + '-' + randomStringAsHex.substring(20);

        return guid;
    }

    static Integer convertHexToInt(String hex) {
        Integer d0 = hexMap.IndexOf(hex.Substring(1,2));
        Integer d1 = hexMap.IndexOf(hex.Substring(0,1));

        Integer intval = d0 + (d1*16);
        return intval;
    }

    static String convertIntToHex(Integer intval) {
        // https://stackoverflow.com/a/13465128
        String hs0 = hexMap.Get(intval & 15); // i & 0x0f
        String hs1 = hexMap.Get(((intval >> 4) & 15)); //(i >> 4) & 0x0f
        return hs1+hs0;
    }
}
@isTest
public class GuidUtil_Test {
    @isTest
	private static void test() {
        Pattern p = Pattern.compile('[\\w]{8}-[\\w]{4}-4[\\w]{3}-[89ab][\\w]{3}-[\\w]{12}');
        for(Integer x = 0; x < 100; x++) {
            Matcher m = p.matcher(GuidUtil.newGuid());
            System.assert(m.matches() == true);
        }
    }
}