Skip to content

Commit

Permalink
Merge pull request #1453 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
trim leading and trailing whitespace chars in idlookup fields during …
  • Loading branch information
ashitsalesforce authored Jan 15, 2025
2 parents 7aa3e04 + 58a2470 commit d330bc8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ public boolean visit(TableRow row) throws OperationException, DataAccessObjectEx
DynaBean dynaBean = SforceDynaBean.convertToDynaBean(dynaClass, sforceDataRow);
Map<String, String> fieldMap = BeanUtils.describe(dynaBean);
for (String fName : fieldMap.keySet()) {
if (fieldMap.get(fName) != null) {
Object fieldVal = fieldMap.get(fName);
if (fieldVal != null) {
// see if any entity foreign key references are embedded here
Object value = this.getFieldValue(fName, dynaBean.get(fName));
dynaBean.set(fName, value);
Expand Down Expand Up @@ -372,6 +373,13 @@ private synchronized void getHtmlFormattedAndPhoneSforceFieldList() {
}

public Object getFieldValue(String fieldName, Object fieldValue) {
// TODO: this needs to be controlled by a config property.
if (getController().getAppConfig().getBoolean(AppConfig.PROP_LOAD_REMOVE_NONBREAKING_SPACE_IN_IDLOOKUP_FIELD)
&& isIdLookupField(fieldName)) {
String fieldValueStr = (String)fieldValue;
// idLookupFields do not have leading or trailing whitespace chars
return fieldValueStr.strip(); // remove leading and trailing whitespace
}
fieldValue = getHtmlFormattedFieldValue(fieldName, fieldValue);
fieldValue = getPhoneFieldValue(fieldName, fieldValue);
return fieldValue;
Expand Down Expand Up @@ -499,4 +507,26 @@ protected void setLastRunProperties(Object[] results) throws LoadException {
handleException(errMsg, e);
}
}

private HashMap<String, Boolean> fieldTypesMap = new HashMap<String, Boolean>();
private boolean isIdLookupField(String fieldName) {
if (fieldTypesMap.containsKey(fieldName)) {
return fieldTypesMap.get(fieldName);
}
PartnerClient partnerClient = this.getController().getPartnerClient();
DescribeSObjectResult describeSObjectResult;
try {
describeSObjectResult = partnerClient.describeSObject(this.getConfig().getString(AppConfig.PROP_ENTITY));
Field[] fields = describeSObjectResult.getFields();
for (Field field : fields) {
if (field.getName().equalsIgnoreCase(fieldName)) {
fieldTypesMap.put(fieldName, field.isIdLookup());
return field.isIdLookup();
}
}
} catch (ConnectionException e) {
logger.warn(fieldName + " field type not found in describeSObjectResult");
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ public class AppConfig {
public static final String PROP_EXTRACT_ALL_CAPS_HEADERS="sfdc.extraction.allCapsHeaders";
public static final String PROP_EXTRACT_CSV_OUTPUT_BOM="sfdc.extraction.outputByteOrderMark";
public static final String PROP_LOAD_PRESERVE_WHITESPACE_IN_RICH_TEXT = "sfdc.load.preserveWhitespaceInRichText";
public static final String PROP_LOAD_REMOVE_NONBREAKING_SPACE_IN_IDLOOKUP_FIELD="sfdc.load.removeNonBreakingSpaceInIdLookupField";

//
// process configuration (action parameters)
Expand Down Expand Up @@ -787,7 +788,7 @@ private void setDefaults(Map<String, String> cliOptionsMap) {
setDefaultValue(PROP_SAVE_ALL_PROPS, false);
setDefaultValue(PROP_EXTRACT_ALL_CAPS_HEADERS, false);
setDefaultValue(PROP_EXTRACT_CSV_OUTPUT_BOM, true);

setDefaultValue(PROP_LOAD_REMOVE_NONBREAKING_SPACE_IN_IDLOOKUP_FIELD, true);
}

/**
Expand Down

0 comments on commit d330bc8

Please sign in to comment.