When sorting above records of Object A and Object B in sobject list, i was getting below error. Initially I thought this is some thing related to values in Row_Index__c number type field but now i realized it could be some thing else causing this issue.
System.UnexpectedException: java.math.BigDecimal cannot be cast to java.lang.Integer
Code
public static void getObjAAndLienJudgement(list<documentationClass> lDocs, string formId){
list<SObject> sObjectList = new list<SObject>();
for(DocumentationClass doc :lDocs){
Documentation_Detail__c ld = doc.DocumentationDetail;
ld.Form_Id__c = formId;
sObjectList.add(ld);
}
try{
database.Insert(sObjectList);
sObjectList.clear();
for(DocumentationClass doc :lDocs){
Documentation_Detail__c ld = doc.DocumentationDetail;
for(ObjectA__c ObjA : doc.objATypes){
ObjA.Documentation_Detail__c = ld.Id;
ObjA.Form_Id__c = formId;
sObjectList.add(ObjA);
}
for(ObjectB__c ObjB : doc.ObjBTypes){
ObjB.Documentation_Detail__c = ld.Id;
ObjB.Form_Id__c = formId;
sObjectList.add(ObjB);
}
}
}
catch(exception ex){
system.debug(ex);
}
sObjectList.sort(); // right here system is throwing the exception.
insert sObjectList;
}