Thanks suresh sanneboina 4 this is what i was looking for!! Another silly doubt in this, inorder to assign those fields from object A to object B, i need to have those fields in Object B(similar to object A) Am i right or wrong?
if you use upsert lstobj2 then it will check for the id as external field and updates based on the id. if you use upsert lstobj2 externalField then upserts based on the externalField field.
I have a dount in this Suresh. First I save a record in object A without checking the checkbox, that record will not be reflected in Object B. Secondly, I update the same record in object A with checkbox "Checked" at that time record will be displayed in object B(ie update operation) .thirdly if i try to update the same record by unchecking the checkbox in object A, the record which is already being copied to Object B must get deleted? how can i achieve the third condition? and finally when i delete a record in object A, those records in object B must also get deleted?
how to achieve these last two conditions? First two conditions are working perfectly fine as per your code.
All Answers
List<customobj2> lstobj2=new List<customobj2>();
for(customobj1 obj1:Trigger.new)
{
if(obj1.checkboxField)
{
customobj2 obj2=new customobj2();
obj2.Name=obj1.Name;
obj2.externalField=obj1.Id;
lstobj2.add(obj2);
}
}
if(!lstobj2.isEmpty())
{
upsert lstobj2 externalField;
}
}
Thanks
Sharath T
upsert lstobj2 externalField then upserts based on the externalField field.
how to achieve these last two conditions? First two conditions are working perfectly fine as per your code.
Thanks,
Sharath T