Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cut text values by length #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion force-app/main/default/classes/TestDataFactory.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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(textValue.length() - fieldDesc?.getLength());
}
return textValue;
}

/**
* @description test if a field requires a default value
* @param fieldDesc (Schema.DescribeFieldResult): field describe information
Expand Down Expand Up @@ -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
Expand Down