Introduction
Prior to TaroWorks 7.3.X, mobile record assignment data was stored in the SobjectContactAssociation Object. Starting 7.3.X, it will be stored in the SobjectUserAssociation Object.
To view the assigned records on the TaroWorks Mobile User View page and also on the mobile application, you will need to perform an additional step to migrate SObjectContactAssociation records to the new SObjectUserAssociation object.
This article describes the steps to do this.
- Go to Setup > Developer Console.
- Click Debug >Open Execute Anonymous Window.
- Copy and paste the below script on the Enter Apex Code pane.
String query =
'SELECT ' +
'Id,' +
'Name,' +
'gfsurveys__AssociatedIds__c,' +
'gfsurveys__Instance__c,' +
'gfsurveys__NumberOfRecords__c,' +
'gfsurveys__SObjectApiName__c,' +
'gfsurveys__SObjectFieldApiName__c,' +
'gfsurveys__UniqueKey__c,' +
'gfsurveys__Contact__c ' +
'FROM ' +
'gfsurveys__SObjectContactAssociation__c';
List<gfsurveys__SObjectContactAssociation__c> sObjectContactAssociationRecords = Database.query(query);
if(sObjectContactAssociationRecords != null && sObjectContactAssociationRecords.size() > 0){
// IDALMSA-11852 better error logging
String failedRecordCSV = '';
// List to store all the SObject User Association records to be inserted
List<gfsurveys__SObjectUserAssociation__c> sObjectUserAssociationList =
new List<gfsurveys__SObjectUserAssociation__c>();
//Set of Contact ids
Set<Id> contactIds = new Set<Id>();
for(gfsurveys__SObjectContactAssociation__c soca: SObjectContactAssociationRecords) {
if(soca.gfsurveys__Contact__c != null)
contactIds.add(soca.gfsurveys__Contact__c);
}
//IDALMSA-11852: changed the query to get user id from TMU record instead of User object directly
//List to store all users associated to contacts
List<gfsurveys__TaroWorks_Mobile_User__c> userList = [Select Id, gfsurveys__User__c, gfsurveys__Contact__c from gfsurveys__TaroWorks_Mobile_User__c Where gfsurveys__Contact__c in :contactIds];
//Map to store UserId against ContactId
Map<Id, Id> mapOfContactUser = new Map<Id, Id>();
for(gfsurveys__TaroWorks_Mobile_User__c u: userList){
mapOfContactUser.put(u.gfsurveys__Contact__c, u.gfsurveys__User__c);
}
// iterate through the list of SObjectContactAssociationRecords and create new SObjectUserAssociation__c records
for(gfsurveys__SObjectContactAssociation__c soca: SObjectContactAssociationRecords){
gfsurveys__SObjectUserAssociation__c soua = new gfsurveys__SObjectUserAssociation__c();
if (Schema.sObjectType.gfsurveys__SObjectUserAssociation__c.fields.gfsurveys__AssociatedIds__c.isCreateable()) {
soua.gfsurveys__AssociatedIds__c = soca.gfsurveys__AssociatedIds__c;
}
if (Schema.sObjectType.gfsurveys__SObjectUserAssociation__c.fields.gfsurveys__Instance__c.isCreateable()) {
soua.gfsurveys__Instance__c = soca.gfsurveys__Instance__c;
}
if (Schema.sObjectType.gfsurveys__SObjectUserAssociation__c.fields.gfsurveys__NumberOfRecords__c.isCreateable()) {
soua.gfsurveys__NumberOfRecords__c = soca.gfsurveys__NumberOfRecords__c;
}
if (Schema.sObjectType.gfsurveys__SObjectUserAssociation__c.fields.gfsurveys__SObjectApiName__c.isCreateable()) {
soua.gfsurveys__SObjectApiName__c = soca.gfsurveys__SObjectApiName__c;
}
if (Schema.sObjectType.gfsurveys__SObjectUserAssociation__c.fields.gfsurveys__SObjectFieldApiName__c.isCreateable()) {
soua.gfsurveys__SObjectFieldApiName__c = soca.gfsurveys__SObjectFieldApiName__c;
}
if(soca.gfsurveys__Contact__c != null && mapOfContactUser.containsKey(soca.gfsurveys__Contact__c)){
if (Schema.sObjectType.gfsurveys__SObjectUserAssociation__c.fields.gfsurveys__User__c.isCreateable()) {
soua.gfsurveys__User__c = mapOfContactUser.get(soca.gfsurveys__Contact__c);
}
}
// add new records in the list to be inserted
sObjectUserAssociationList.add(soua);
}
// insert the list into the database
if(sObjectUserAssociationList.size() > 0) {
// insert sObjectUserAssociationList; IDALMSA-11852
Database.SaveResult[] saveResultList = Database.insert(sObjectUserAssociationList,false);
}
} - Click Execute.
Note:
Failure to run the script to migrate mobile record assignment records will result in:
- The existing TaroWorks Mobile Users not being able to get assigned records in the Drill Down Hierarchy on the mobile application.
- The records that were already assigned will not be visible on the TaroWorks Mobile User View page.
Conclusion
Congratulations you've successfully migrated Mobile Record Assignments for TaroWorks Mobile Users. Please continue to 06. Update Record Type in existing TaroWorks Mobile Users records.
Comments
0 comments
Please sign in to leave a comment.