I have a Class1 and then there is another Class1_Handle. The Class1 takes a list of OPP, then loops through that and sends Opportunity ID to the Hadelar 1 by 1.
The Handler then does a bunch of stuff, code is up to 500 Lines, I am not going to include everything but the code in there works just fine, I have tested and stepped through every line using checkpoints but nothing there. One thing interesting to note, if I call in the handler directly and pass it an ID of OPP it works just fine, but when I send a LIST with the same ID in it to the Class1 and if it tries to go through there I get an Error ( Error details below);
public class Class1{
public static void GetTheList(List<Opportunity> OPPList)
{
List<Error__c> ErrorList;
For(Opportunity OPP : OPPList)
{
Try{
string CurrentOPPID = OPP.Id;
Class1_Handler.CreateData(CurrentOPPID);
}
catch(exception Ex)
{
Error__c ErrorListData = new Error__c();
ErrorListData.Opportunity__c = OPP.id;
ErrorListData.Error_Details__c = Ex.getMessage();
System.debug('The following exception has occurred: ' + ex.getMessage());
}
}
If(ErrorList.size() > 0)
{
For(Error__c Errors : ErrorList )
{
Insert Errors;
}
}
}
}
2nd Class:
public class Class1_Handler{
public static void CreateData(string OPPID)
{
List<Data> ListOfStuff = new List<Data>();
List<Opportunity> ErrorOps = new List<Opportunity>();
// GET the data we need in this Class, instead of expecting it, use the ID provided per Class Call
//
LIST<Opportunity> CurrentOpp = [SELECT All The Data we need
FROM Opportunity where Id=:OPPID];
}
}
The Erro that only comes when I use the Class1 to pass the individual ID is this:
System.NullPointerException: Attempt to de-reference a null object
I have run through each code line even when it's called from Class1, it shows that everything went as expected. But in the end, it keeps giving me this error, the issue seems to be with Class1 for a reason because if I try to execute the Handler Class on it's on. It works with no issues.
Also as you can see I Am using a Try and Catch but code never goes there, it just breaks, the whole point of me having 2 classes is so it goes through all of them doesn't matter if one breaks or not.
If you have any ideas please let me know, thanks!
what am I missing here?
ErrorsList
. Change thisList<Error__c> ErrorList;
into thisList<Error__c> ErrorList = new List<Error__c>();
and the problem should go away. You probably also want to add errors to this list in thecatch
.