function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
itstaff1.3920641347534116E12itstaff1.3920641347534116E12 

View the 'Return' Results in Apex

We have a class that handles lead inserts from a 3rd party source. Within the class, we have created an inner class called LeadDetailResponseData which handles the lead insert responses.

global class LeadDetailResponseData {
    public Integer MessageId;
    public String Status;
    public String ErrorMessage;
  }

We have then created a list of 'LeadDetailResponseData' types that will store the results of the lead import:

List<LeadDetailResponseData> ResponseMsg = new List<LeadDetailResponseData>();

Upon insertion, if there are any errors, it is getting stored to the ErrorMessage variable. The message then gets added to the list of Lead Detail Responses. Note that l is an instance of a Lead object and lr is an instance of the LeadResponseDetail class.

   try {
            l.setOptions(dmo);
            insert l;
          } catch (DmlException e) {
            lr.Status = '-1'; //Insert Error
            lr.ErrorMessage = e.getMessage();
          }  

   ResponseMsg.Add(lr);
   return ResponseMsg;

My question is where does the Return go? Is it returned to the process that's calling this class? Or is it stored somewhere within the instance of Salesforce.

Any feedback is much appreciated.

Thanks.
Bhanu PartapBhanu Partap
Hi 

Yes you are on right track it returned to the process that's calling this class method.Process will get the list of Errors i.e ResponseMsg.
itstaff1.3920641347534116E12itstaff1.3920641347534116E12
Thanks for the response Bhanu. Would I be able to create an email within the class that has the ResponseMsg in the body and send it to me, as the administrator, so that I can review when an error occurs?
Since the class is being invoked by a third party, I am not able to see the error message generated by the call.

Thanks.
Bhanu PartapBhanu Partap
Yes you can generate email functionality with in class to get errors email where ever third party call generate error.
if possible share working code for Class.