Contents[Hide]

Debugging

During developement always use PageMessages component:

<apex:pageMessages id="errorMsg" />

or version which shows details also and do not escape HTML code in case that you need this options.

<apex:pageMessages id="errorMsg" showDetail="TRUE" escape="FALSE" />

It can display system errors during execution which are not shows on compile time and are hard to filter from debug log.

Additionally you can pass there your own errors by:

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'errorMsg', 'details'));
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'errorMsg'));

Where details are optional.

Displaying a <list> content inside error message in easy readable form:

Visualforce:

<apex:pageMessages id="errorMsg" escape="FALSE" />

Controller:

List <Package__c> newPackages = new List <Package__c>();
// Some code that will add items to that list like newPackages.add(sObjectName);
String errorMsg = 'List content: <br/>' +  String.valueOf(newPackages).replace('{', '{<br/>').replace('},', '}<p/>').replace(',', '<br/>');
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, errorMsg));

Sample output as a INFO message on VS page:

List content:
(Package__c:{
Order__c=a0ZL000000053VSMAY
Package_Item__c=a0qL0000000gUWkIAM
Is_Active__c=false
Index__c=1}

Package__c:{
Order__c=a0ZL000000053VSMAY
Package_Item__c=a0qL0000000gUWkIAM
Is_Active__c=false
Index__c=2}

Package__c:{
Order__c=a0ZL000000053VSMAY
Package_Item__c=a0qL0000000gUWkIAM
Is_Active__c=false
Index__c=3})

In that way you can read content of the list which will be inserted before insert:

// insert newPackages; //Not inserting just reading content in error message

 

Error messages.

Add error message to field.

objectName.fieldName__c.addError('This value is notvalid.');

Addotional info: Field Level Error Messages with Visualforce - Part 1 / Part 2

 

 

   
© Paweł Woźniak