0

I have a list of 1132 records and the record at 646 breaks and threw an exception when it tries to convert a invalid string to double. And the code halts and my pageblocktable displays 645 records. Is that possible to continue the execution after an exception thrown just omitting the error records in the way?

In the below screen shot, it stops at 645th record though it is having 1132 in total.

enter image description here

  • Is the exception occurring during the VF rendering or is it something that can be caught by try-catch in the controller? – cropredy Apr 29 '14 at 19:02
  • Thanks @crop1645. the exception caught by try catch block in the controller – Bforce Apr 29 '14 at 19:05
2

Not sure if you are using a wrapper class or not but why not just build the pageBlockTable list within a for loop that has a try catch - if an exception, the row in error is ignored

List<Account> aList = new List<Account> ();

for (Account a : [select id, name, fooStringFld__c from Account])
   try {
       Account workA = new Account();
       workA.doubleFld__c = a.fooStringFld__c; // your string conversion here
       workA.fldY__c = // other fields as needed  
       aList.add(workA);
    }
   catch(Exception e) {//do nothing or build up a list of errors for later resolution}


<apex:pageBlockTable value="{!aList}" var="a">
  ... columns
</apex:pageBlockTable>
  • well, the above can be adapted to a wrapper class - the point is to do the try catch within the for loop that builds the list of wrapper class objects – cropredy Apr 29 '14 at 19:21
  • would it work even if the rows in the middle of recordset thrown exception? – Bforce Apr 29 '14 at 19:21
  • For instance, if i am having a 10 records and if 5th one is problematic and thrown an exception, would i get other 9 records displayed in the pageblocktable? – Bforce Apr 29 '14 at 19:22
  • give it a try -- I'm working blind here about what you're doing but the SFDC data will correctly populate SObjects and then you can copy fields from the SObject to a wrapper class; as you copy fields the try catch will catch string to double conversion errors as presumably, the database field is type String but the corresponding wrapper field is double – cropredy Apr 29 '14 at 19:24
  • Hi crop1645. i have tried your approach and it worked for me. Thanks a lot. – Bforce Apr 29 '14 at 19:46

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.