Skip to content

Commit

Permalink
Merge pull request #1254 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
Fix for issue #1244
  • Loading branch information
ashitsalesforce authored Sep 9, 2024
2 parents 8df283d + f297b97 commit c28eccb
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main/java/com/salesforce/dataloader/dyna/SforceDynaBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.salesforce.dataloader.exception.RelationshipFormatException;
import com.sforce.soap.partner.*;
import com.sforce.soap.partner.sobject.SObject;
import com.sforce.ws.ConnectionException;

/**
* Salesforce DynaBean utilities
Expand Down Expand Up @@ -368,8 +369,24 @@ public static Map<String, Object> getCompositeRESTSObject(Controller controller,
// see if any entity foreign key references are embedded here
Object value = dynaBean.get(fName);
if (value instanceof SObjectReference) {
SObjectReference sObjRef = (SObjectReference)value;
if (!sObjRef.isNull()) sObjRef.addReferenceToSObject(controller, null, restSObj, fName);
try {
ParentIdLookupFieldFormatter idLookupFieldFormatter = new ParentIdLookupFieldFormatter(fName);
DescribeSObjectResult parentSObjectDescribe = controller.getPartnerClient().describeSObject(idLookupFieldFormatter.getParent().getParentObjectName());
DynaProperty[] parentDynaProps = createDynaProps(parentSObjectDescribe, controller);
BasicDynaClass parentDynaClass = getDynaBeanInstance(parentDynaProps);
Row parentDataRow = new Row();
parentDataRow.put(idLookupFieldFormatter.getParentFieldName(), value);
DynaBean parentDynaBean = convertToDynaBean(parentDynaClass, parentDataRow);
Map<String, Object> parentRESTSObject = getCompositeRESTSObject(controller, idLookupFieldFormatter.getParent().getParentObjectName(), parentDynaBean);
SObjectReference sObjRef = (SObjectReference)value;
if (!sObjRef.isNull()) {
restSObj.setField(idLookupFieldFormatter.getParent().getRelationshipName(),
parentRESTSObject);
}
} catch (Exception e) {
e.printStackTrace();
logger.error("Unable to convert " + fName + " to parent reference");
}
} else {
restSObj.setField(fName, value);
}
Expand Down

0 comments on commit c28eccb

Please sign in to comment.