You need to sign in to do that
Don't have an account?
Arpit Goyal
Test Try Catch block
I have written a try catch block but dont know how to unit test it .Below is the code .
try{
Schema.SObjectField extField = Order.Fields.id__c;
List<Database.upsertResult> listOfResults = Database.upsert(listOfOrder,extField,false);
}
catch(Exception e)
{
for(Order listOrder: listOfOrder)
{
Error_Log__c error = new Error_Log__c();
System.debug('Error'+e);
}
}
Please help me to see if my upsert works fine or not in this logic.
try{
Schema.SObjectField extField = Order.Fields.id__c;
List<Database.upsertResult> listOfResults = Database.upsert(listOfOrder,extField,false);
}
catch(Exception e)
{
for(Order listOrder: listOfOrder)
{
Error_Log__c error = new Error_Log__c();
System.debug('Error'+e);
}
}
Please help me to see if my upsert works fine or not in this logic.
You can see upsert operation status using following methods.
getErrors()
If an error occurred, returns an array of one or more database error objects providing the error code and description. If no error occurred, returns an empty set.
getId()
Returns the ID of the sObject you were trying to update or insert.
isCreated()
A Boolean value that is set to true if the record was created, false if the record was updated.
isSuccess()
Returns a Boolean value that is set to true if the DML operation was successful for this object, false otherwise.