-
Notifications
You must be signed in to change notification settings - Fork 557
Description
The issue: UnitOfWork does not resolve the relationship at update. Here is the problem description:
Use "registerDirty" with a relationship to a parent record which will be inserted (updated?).
Method to use:
public void registerDirty(SObject record, Schema.sObjectField relatedToParentField, SObject relatedToParentRecord)
Example:
create a new transaction "tranNew" record, set the new transaction Id in an existing record "updTran". Code snippet:
mUow.registerNew(tranNew);
mUow.registerDirty(updTran, Transaction__c.NewTransaction__c, tranNew);
After UnitOfWork is committed, the parent field is not filled in record "updTran". The implementation of "updateDmlByType" does not have relationship resolution:
private void updateDmlByType()
{
for (Schema.SObjectType sObjectType : m_sObjectTypes)
{
m_dml.dmlUpdate(m_dirtyMapByType.get(sObjectType.getDescribe().getName()).values());
}
}
It should resolve the relationship before update. The updated implementation will have "m_relationships.get(sObjectType.getDescribe().getName()).resolve();" before update is performed.
private void updateDmlByType()
{
for (Schema.SObjectType sObjectType : m_sObjectTypes)
{
m_relationships.get(sObjectType.getDescribe().getName()).resolve();
m_dml.dmlUpdate(m_dirtyMapByType.get(sObjectType.getDescribe().getName()).values());
}
}
The modification is similar to the resolution applied in method "private void insertDmlByType()".
private void insertDmlByType()
{
for (Schema.SObjectType sObjectType : m_sObjectTypes)
{
m_relationships.get(sObjectType.getDescribe().getName()).resolve();
m_dml.dmlInsert(m_newListByType.get(sObjectType.getDescribe().getName()));
}
}