Skip to content

Commit

Permalink
Updates TestingUtils class to properly account for share/history Id g…
Browse files Browse the repository at this point in the history
…eneration
  • Loading branch information
jamessimone committed Sep 25, 2023
1 parent 626cbf0 commit 80eb1ce
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions force-app/utils/TestingUtils.cls
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
public abstract class TestingUtils {
@IsTest
public class TestingUtils {
private static Integer startingNumber = 1;

public static String generateId(Schema.SObjectType sObjectType) {
String result = String.valueOf(startingNumber++);
return sObjectType.getDescribe().getKeyPrefix() + '0'.repeat(12 - result.length()) + result;
String keyPrefix = sObjectType.getDescribe().getKeyPrefix();
if (keyPrefix == null) {
switch on sObjectType.getDescribe().getAssociateEntityType() {
when 'History' {
keyPrefix = '017';
}
when 'Share' {
keyPrefix = '02c';
}
}
}
return keyPrefix + '0'.repeat(12 - result.length()) + result;
}

public static SObject generateId(SObject objectInstance) {
Expand All @@ -20,4 +32,14 @@ public abstract class TestingUtils {
}
}
}

@IsTest
static void generates_fake_history_ids() {
Assert.isNotNull(generateId(LeadHistory.SObjectType));
}

@IsTest
static void generates_fake_share_records() {
Assert.isNotNull(generateId(LeadShare.SObjectType));
}
}

0 comments on commit 80eb1ce

Please sign in to comment.