1

I've a generic class which detects the type of exception and redirects to another utility class for displaying specific message for exceptions. Now for a certain scenario I want to display a different message rather than the generic one for DML exception. So, i've put a condition on the class name from the exception log , but I'm getting this error. any idea as to how i can solve this?

public static void ExceptionHandling(Exception e,List<ExceptionLog__c> eLog)
{

if(e.getTypeName()=='System.DMLException') {

    for(List<ExceptionLog__c> eL : eLog){
        if(eL.ClassName__c = 'myclassName')
            ExceptionUtility.reWriteDisplayDmlExceptionMessage2UI(LABEL.Errormessage,e, eLog);  
        else   
            ExceptionUtility.reWriteDisplayDmlExceptionMessage2UI(LABEL.ErrorDmlException,e, eLog); 
          }                                     
      }  
1

This is a simple typo; you want to get each individual element from the list, so the type of the iterator element should be simply ExceptionLog__c, not a List:

for(ExceptionLog__c eL: eLog) {

As a side note, you're also confusing assignment (=) with equality (==), so the following line is an error:

if(eL.ClassName__c = 'myclassName')

This will actually try to assign the value of 'myclassName' to eL.ClassName__c, and since the result type is not a Boolean value, you'll get another compiler error here. Change it to == so you get a Boolean value. Watch out for this syntax, because it can cause errors (e.g. if you try to assign a Boolean value to a checkbox field).

There are times when you want to use a List<SObject> type iterator type, and that's when you are using a query as the list to iterate over; this has the effect of giving you 200 records at once for processing, which can save memory:

for(Account[] records: [SELECT Name FROM Account]) {
    // We get 200 records at a time for processing.

This syntax doesn't skirt any limits, such as the 50,000 row limit, but internally uses a QueryLocator to grab 200 records at a time efficiently, reducing the memory cost of a large query for inline processing. The list to iterate over must be some sort of query result, not an existing list of records either constructed in memory or from a prior query.

| improve this answer | |
  • Got it, made the changes and it's working. – Sagnik Nov 27 '15 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.