Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 16 Next »

Overview

Booker25 contains an internal ID system to reduce query consumption. This system uses the B25__Booker25_Id__c and B25__Materialized_Path__c fields on the Resource object. Every Resource in Booker25 that triggers the Resource Trigger during creation, will have a value for these fields.

The only ways that those fields are not set are:

  • the Resource has the B25__IsVirtual__c checkbox set to true (you should never use this as it's an internal-use only checkbox)

  • the Resource creation somehow did not trigger the Resource Trigger (perhaps the trigger was disabled)

Ideally, you should always make sure the Booker25 Resource Trigger is run when creating Resources. If for any reason a Resource is missing values in either of the B25__Booker25_Id__c and B25__Materialized_Path__c fields, you will need to rebuild the ID structure. How to do this is explained below.

Please be aware that the scripts below should be run exactly as they are written here. You should not limit scripts to run for a subset of Resources, other than the WHERE clauses already present in the scripts.

Step-by-step guide

  1. Go to the Developer Console

  2. Open an Execute Anonymous window

  3. Run the following script to remove all existing values:

    // Reset all ids and paths
    List<B25__Resource__c> allResources = [SELECT Id, B25__Materialized_Path__c, B25__Booker25_Id__c FROM B25__Resource__c WHERE B25__Booker25_Id__c != null];
    for (B25__Resource__c resource : allResources) {
    	resource.B25__Booker25_Id__c = null;
    	resource.B25__Materialized_Path__c = null;
    }
    B25.Trigger_Resource_c.blockExecution = true;
    Database.update(allResources);
    B25.Trigger_Resource_c.blockExecution = false;

  4. After successfully running the first script, run the following script. If any errors occur, such as validation errors, fix these first. You need to fix all the errors in order to successfully run the script. Although errors should most likely relate to custom work in your org, such as validation errors, you can always reach out to support@booker25.com if you need help.

    public static String incrementBase64Local(String base64Number) {
    	String encodeTable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_';
    	Integer indexOfLastChar = base64Number.length() - 1;
    	Integer lastCharOfBase64Number = base64Number.charAt(indexOfLastChar);
    	Integer index = encodeTable.indexOfChar(lastCharOfBase64Number);
    	if (index == 63) {
    		if (base64Number.length() == 1) {
    			return '10';
    		}
    		String firstCharacters = incrementBase64Local(base64Number.left(indexOfLastChar));
    		return firstCharacters + '0';
    	}
    	base64Number = base64Number.left(indexOfLastChar) + encodeTable.substring(index + 1, index + 2);
    	return  base64Number;
    }
    
    // Reset the resource numbering.
    B25__System_Setting__c resourceIdSetting = [SELECT B25__String_Value__c FROM B25__System_Setting__c WHERE Name = 'ResourceIdNumber' FOR UPDATE];
    resourceIdSetting.B25__String_Value__c = '00000';
    
    Set<Id> parentIds = new Set<Id>{null}; // first layer
    while (!parentIds.isEmpty()) {
    	List<B25__Resource__c> resources = [SELECT B25__Materialized_Path__c, B25__Booker25_Id__c, B25__Parent__r.B25__Materialized_Path__c, B25__Parent__r.B25__Booker25_Id__c FROM B25__Resource__c WHERE B25__Parent__c IN:parentIds AND B25__IsVirtual__c = false];
    
    	// Update resource ids
    	String currentResourceId = resourceIdSetting.B25__String_Value__c;
    	for (B25__Resource__c resource : resources) {
    		resource.B25__Booker25_Id__c = currentResourceId;
    		currentResourceId = incrementBase64Local(currentResourceId);
    		if (currentResourceId.length() > 5) {
    			System.assert(false, 'Too many resources');
    		}
    	}
    	resourceIdSetting.B25__String_Value__c = currentResourceId;
    
    	for (B25__Resource__c resource : resources) {
    		if (resource.B25__Parent__c == null) {
    			resource.B25__Materialized_Path__c = '';
    			continue;
    		}
    		resource.B25__Materialized_Path__c = resource.B25__Parent__r.B25__Materialized_Path__c != null
    			? resource.B25__Parent__r.B25__Materialized_Path__c + resource.B25__Parent__r.B25__Booker25_Id__c
    			: resource.B25__Parent__r.B25__Booker25_Id__c;
    	}
    
    	B25.Trigger_Resource_c.blockExecution = true;
    	Database.update(resources);
    	B25.Trigger_Resource_c.blockExecution = false;
    	parentIds = new Set<Id>(new Map<Id, B25__Resource__c>(resources).keySet());
    }
    Database.update(resourceIdSetting);

If the script ran successfully, the Booker25 ID system has been reset correctly. You can ignore the next steps if this was not part of an upgrade.

After upgrading to v4.3.2

Booker25 introduces a new ID on the Resource object after the v4.3.2 upgrade to improve performance. This means that a batch job is run on all the Resources of an org when upgrading to v4.3.2. This job can fail due to various reasons, for example older Resources having a required field that is empty. This needs to be fixed in order to upgrade to a newer version.

Steps required when fixing Materlialized Path in order to upgrade

You can ignore these if you are not upgrading

  1. After having successfully run the last script, Grant login access to Gen25 and reach out to support@booker25.com:

    1. State that you have fixed your Materialized Paths and want to upgrade

    2. Provide your Org ID

  2. The team will do a final check and needs to approve the fix in your settings to allow you to proceed with a next upgrade.



On this page


  • No labels