You need to sign in to do that
Don't have an account?
sahi
Merging records
How to get the fields from child record to master record.I have done
merging records using merge statement.Like merge c1 c2;
But I am unable to get the child record fields in to master record(c1),
the fields that are not present in master record after merging.
If any one know the solution,tell me.
you can describe the object and get all the fields at once and then loop through it.
you can use the following :
Map<String, Schema.SObjectField> M = Schema.SObjectType.ObjectName.fields.getMap();
for(String fieldName : M.keySet())
{
if(masterRecord.get(fieldName) == null && childRecord.get(fieldName) != null)
{
masterRecord.put(fieldName, childRecord.get(fieldName));
}
}
this code will process all the field at once.
All Answers
you can use masterObject.get('fieldName') method to check that if parent record's field is having a null value and if it's true then you can get the child record value using the same method childRecord.get('fieldName') and put in the master one masterRecord.put('fieldName',fieldValue);
I am very thankful for your reply,
But is there any way to get them with a single step,because if i have 100 fields
then it becomes difficult to get all those field and put. Is it possible with mergeresult[ ]?
you can describe the object and get all the fields at once and then loop through it.
you can use the following :
Map<String, Schema.SObjectField> M = Schema.SObjectType.ObjectName.fields.getMap();
for(String fieldName : M.keySet())
{
if(masterRecord.get(fieldName) == null && childRecord.get(fieldName) != null)
{
masterRecord.put(fieldName, childRecord.get(fieldName));
}
}
this code will process all the field at once.
Thanku,
I got the fields in master record.