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

capture records that were not inserted

Is it possible to capture records that were not inserted inside the visualforce page.

If for ex: in Lead object 
User-added image

I have a custom controller that inserts lead record,now sometimes the lead does not get inserted and exception is thrown
now can i fetch the Company name or some field value that i entered into the  vfpage but was not inserted as a record

John Pipkin 14John Pipkin 14
wrap the DML statement in a try-catch block. In the catch, add a page message and then return null.
insert newlead;
catch(Exception e){
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,e.getMessage()));
return null;

If the return data type of the method is "void" then change "return null;" to "return;"

The data you enter into the VF page should remain as long as you are using apex:inputField

Hope that helps. 

Navee RahulNavee Rahul
Hello sathish,

May be ,you add the expection email in settings and so when ever exception happened,
you will be received an email.

see the attached image
User-added image
D Naveen Rahul.