+ Start a Discussion
Paulo CastroPaulo Castro 

Really need help here! How to find a simple error??

Hey guys,

 

 I'm trying to understand what is going wrong with my custom controller method for about 2 hours and just now I realize that the following code is probably my problem:

 

 

act.Private__c = boolean.valueOf(Apexpages.currentPage().getParameters().get('private'));

 

 Private__c is a checkbox (boolean) field type and I was trying to parse a form field string with a 'false'/'true' value.

 

 The problem here was I didn't get any error messages in any place. I turned on the Apex Debug Log and it shows status 'Sucess' and nothing else more. To find that this line is probably my problem I had to put a System.debug() line after every single code line that I wrote!

 I mean, I can't spend 2 hours to find an error for every problem I have!! And I can't put a System.debug() line for every single code line I have. This way I'll take 100 years to finish my project... :(

 

 Another problem is this thing to have to reset my debug log every 20 time... I'm using a development org, so I'll need it every time. Is there any way to change it?

 

 At last, the debug output is soooo large and difficult to read. I saw that someone developed this tool to filter debug logs output, but it works only in Windows and I use Mac (lucky me :) ). Any tips here?

 

 Thank you in advance for any help!! 

 

 Best regards

 

 PH

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
jhenningjhenning
Excellent question. I think you went through all the right steps to debug the Apex. I'm not sure why it did not throw an exception. I tried a similar line of code in a VF page and it threw the exception but our environments are obviously different. The debug log is the best way to see what is happening in your code. Another technique is to create a custom object and have a policy in which all Apex is wrapped in a Try/Catch. Within the Catch you could write additional info to a custom log object to make it easier to track exceptions and to retain them for a longer period.

All Answers

jhenningjhenning

PH:

 

Did the problem throw an exception that you can see in the debug log? Did you have Try/Catch exception handling in the class in which this Apex code resides?

Paulo CastroPaulo Castro

Hi John,

 

 no, it didn't throws any error message into debug log nor in the vf page.

 And it doesn't have try/catch exception handle also... But I think that the correct behavior is throw an error message somewhere, right?

 

 Thanks for your reply.

 

 Best regards

 

 PH

 

jhenningjhenning

yes, it should throw an exception like this:

 

System.TypeException: Invalid boolean: true

 

I don't think the boolean.valueof method is what you want to use. Try the following and let me know if it helps.

 

act.private__c = Apexpages.currentPage().getParameters().get('private').toLowerCase() == 'true' ? true : false;

 

 

Paulo CastroPaulo Castro

Hi John,

 

 yes, I already did exactly the same you suggested and works fine.  

 

 But my point is, why it didn't throw any error message? I mean, I spent 2 hours until realize what is wrong. And to discover it I put one System.debug('passed here') line for every single code line on my custom controller.

 I think I'm missing something here... 

 Anyway, is there some place where I could learn how to be productive when debuging my apex code? Because I'm feeling very difficult to debug code on Force platform.

 

 Once again, thank you for your support.

 

 Best regards

 

 PH

 

 

 

jhenningjhenning
Excellent question. I think you went through all the right steps to debug the Apex. I'm not sure why it did not throw an exception. I tried a similar line of code in a VF page and it threw the exception but our environments are obviously different. The debug log is the best way to see what is happening in your code. Another technique is to create a custom object and have a policy in which all Apex is wrapped in a Try/Catch. Within the Catch you could write additional info to a custom log object to make it easier to track exceptions and to retain them for a longer period.
This was selected as the best answer
Paulo CastroPaulo Castro

Yeah, I like this idea. This way I could build reports and vf pages to inspect this custom object.

 

Thank you!!

 

PH