I am trying to insert 2 objects and catch the error and show it in visualforce page but when I catch the error of second object first object I insert do not get rollback.
lead objlead = new lead();
objlead = data;
try{
upsert objlead;
}
catch(DMLException e){
ApexPages.addMessages(e);
return null;
}
test__c objtest = new test__c();
objtest = objWrap.objeoi;
objtest.Lead__c = objlead.id;
try{
insert objeoi;
}
catch(DMLException e){
ApexPages.addMessages(e);
return null;
}
i use roll-back but it is not good solution. i want alternative.