diff --git a/force-app/main/default/classes/TeamService.cls b/force-app/main/default/classes/TeamService.cls index 1e1fb2e3..663e00d4 100644 --- a/force-app/main/default/classes/TeamService.cls +++ b/force-app/main/default/classes/TeamService.cls @@ -18,7 +18,7 @@ public with sharing class TeamService { Boolean found = false; // add client to the type if not already there for (DogRelationShip__c relationShip : relationShips) { - if (relationShip.Type__c.contains('Client')) { + if (relationShip.Type__c != null && relationShip.Type__c.contains('Client')) { found = true; break; } @@ -28,11 +28,16 @@ public with sharing class TeamService { } // otherwise, add Client to the first relationship (should be the only one) DogRelationShip__c relationShip = relationShips[0]; - relationShip.Type__c = relationShip.Type__c + ';Client'; + if (String.isBlank(relationShip.Type__c)) { + relationShip.Type__c = 'Client'; + } + else { + relationShip.Type__c = relationShip.Type__c + ';Client'; + } update relationShip; } } - + // Update client status. This is meant to be called from the team update trigger. public static void updateClientStatus(Team__c team) { List clients = [SELECT ClientStatus__c, ClientCertificationValidUntil__c FROM Contact WHERE Id = :team.Client__c]; diff --git a/force-app/main/default/objects/DogRelationship__c/fields/Type__c.field-meta.xml b/force-app/main/default/objects/DogRelationship__c/fields/Type__c.field-meta.xml index 3795cfae..0c4f8bb9 100644 --- a/force-app/main/default/objects/DogRelationship__c/fields/Type__c.field-meta.xml +++ b/force-app/main/default/objects/DogRelationship__c/fields/Type__c.field-meta.xml @@ -4,7 +4,7 @@ Relationship types between a dog and contact false - false + true false MultiselectPicklist diff --git a/force-app/main/default/permissionsets/AtlasSuperUser.permissionset-meta.xml b/force-app/main/default/permissionsets/AtlasSuperUser.permissionset-meta.xml index 344ea821..46910352 100644 --- a/force-app/main/default/permissionsets/AtlasSuperUser.permissionset-meta.xml +++ b/force-app/main/default/permissionsets/AtlasSuperUser.permissionset-meta.xml @@ -650,11 +650,6 @@ DogRelationship__c.Dog__c true - - true - DogRelationship__c.Type__c - true - true Dog__c.ActivationDate__c @@ -1116,6 +1111,10 @@ Team__c true + + Account.Default + true + Account.HH_Account true diff --git a/force-app/main/test/TestTeamTrigger.cls b/force-app/main/test/TestTeamTrigger.cls index 3d300399..70c573c4 100644 --- a/force-app/main/test/TestTeamTrigger.cls +++ b/force-app/main/test/TestTeamTrigger.cls @@ -38,6 +38,35 @@ public with sharing class TestTeamTrigger { System.assertEquals('Client', relationship.Type__c); } + @isTest + public static void triggerUpdatesRelationship_WhenTypeNull() { + setup(); + DogRelationShip__c dr = new DogRelationShip__c( + Contact__c = joe.Id, + Dog__c = boomer.Id + ); + insert dr; + Team__c team = new Team__c( + Name = 'Joe_Boomer', + Client__c = joe.Id, + Dog__c = boomer.Id + ); + + // Act + Test.startTest(); + Database.SaveResult result = Database.insert(team, false); + Test.stopTest(); + + // Assert + System.assert(result.isSuccess()); + DogRelationShip__c relationship = [ + SELECT Type__c + FROM DogRelationShip__c + WHERE Dog__c = :boomer.Id AND Contact__c = :joe.Id + ]; + System.assert(relationship.Type__c.contains('Client')); + } + @isTest public static void triggerUpdatesRelationship_WhenNotClient() { setup();