From 8770998fc408581c2f553a4be7efa24aa389306c Mon Sep 17 00:00:00 2001 From: Svetlana Pelevina Date: Sat, 15 Oct 2022 05:46:18 +0300 Subject: [PATCH 1/2] cut text values by length --- .../main/default/classes/TestDataFactory.cls | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/force-app/main/default/classes/TestDataFactory.cls b/force-app/main/default/classes/TestDataFactory.cls index 2badf59..9913f7c 100644 --- a/force-app/main/default/classes/TestDataFactory.cls +++ b/force-app/main/default/classes/TestDataFactory.cls @@ -944,6 +944,23 @@ public class TestDataFactory { return convertedSet; } + /** + * @description cut String value to its length + * @param fieldDesc (Schema.DescribeFieldResult): field describe information + * @param textValue (String): String field value + * @return String field value with its length + */ + @TestVisible + private String getSubstringByLength(Schema.DescribeFieldResult fieldDesc, String textValue){ + if (fieldDesc == null || textValue == null) { + return textValue; + } + if (textValue?.length() > fieldDesc?.getLength()) { + textValue = textValue.substring(0, fieldDesc?.getLength()); + } + return textValue; + } + /** * @description test if a field requires a default value * @param fieldDesc (Schema.DescribeFieldResult): field describe information @@ -1191,7 +1208,8 @@ public class TestDataFactory { * @return text default value */ public virtual String getTextDefaultValue(Schema.DescribeSObjectResult sObjectDesc, Schema.DescribeFieldResult fieldDesc, Integer recordIndex){ - return 'test'+recordIndex.format(); + String textValue = 'test' + recordIndex.format(); + return getSubstringByLength(fieldDesc, textValue); } /** * @description get the default value for TextArea field type From 51ac0c652e16da0a0abde52de0760d84b06dc01c Mon Sep 17 00:00:00 2001 From: Svetlana Pelevina Date: Sat, 15 Oct 2022 05:50:48 +0300 Subject: [PATCH 2/2] reverse substring --- force-app/main/default/classes/TestDataFactory.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/main/default/classes/TestDataFactory.cls b/force-app/main/default/classes/TestDataFactory.cls index 9913f7c..aecbec7 100644 --- a/force-app/main/default/classes/TestDataFactory.cls +++ b/force-app/main/default/classes/TestDataFactory.cls @@ -956,7 +956,7 @@ public class TestDataFactory { return textValue; } if (textValue?.length() > fieldDesc?.getLength()) { - textValue = textValue.substring(0, fieldDesc?.getLength()); + textValue = textValue.substring(textValue.length() - fieldDesc?.getLength()); } return textValue; }