Note |
---|
The reparenting Reparenting of resources is currently not supported at this moment. |
Before Reparenting
Disable any custom logic (process builders/flows/apexProcess Builder/ Lightning Flows/ Apex) on the resource object.Resource object
Go to Custom Settings
Click Manage next to System Setting
Click New
Create a custom setting value in the System Setting custom setting named: Disable ResourceType with boolean value true. This disables the resource type setting as follows:
Name: Disable ResourceType
Boolean Value: TRUE
This will disable the Resource Type trigger in GoMeddo.Run
Reparenting Resources
You may now either manually reparent your Resources. Alternatively, you can run this script with the correct
...
Resource Type and
...
Resource names
...
. This will adjust the type tree and move the resource to their new parent.
Note |
---|
The changes that are being made make to the type Resource Type tree and resource Resource tree need to match (A child of a resource Resource needs to have a type Resource Type that is a child of the resources typeparent Resource’s Resource’s Type). Normally the resource Resource and resource type Resource Type triggers validate this but because they are , but as those have been disabled during this process, you could create an invalid configuration. Reenabling the trigger after this process will not correct any incorrect parent relationships or other errors introduced. |
Code Block |
---|
String moveType = '<The type of the resources that should be move>'; String newParentName = '<The new parent resource for these resources>'; B25__Resource_Type__c toMoveType = [SELECT Id, Parent__c FROM B25__Resource_Type__c WHERE Name = :moveType]; B25__Resource__c newParent = [SELECT Id, B25__Resource_Type__c FROM B25__Resource__c WHERE Name = :newParentName]; Id oldParentType = newParent.B25__Resource_Type__c; // Set the type of the new parent so that it has the type that the records we want to move have as parent right now newParent.B25__Resource_Type__c = toMoveType.Parent__c; Database.update(newParent); // Move the resource type tree toMoveType.Parent__c = oldParentType; Database.update(toMoveType); // Reparent the resources List<B25__Resource__c> resourcesToMove = [SELECT Id FROM B25__Resource__c WHERE B25__Resource_Type__r.Name = :moveType]; for (B25__Resource__c resource : resourcesToMove) { resource.Parent__c = newParent.Id; } Database.update(resourcesToMove); // Set the type back to the old value newParent.B25__Resource_Type__c = oldParentType; Database.update(newParent); |
...
After Reparenting
Remove the
...
Custom Setting, or set the boolean value to false for Disable ResourceType to reenable the
...
Resource Type triggers
...
This process might have broken the materialised path in the org run, so please run Fix Materialized Path
...
Re-enable any custom logic on the resource