+ Start a Discussion
sathishsfdcsathishsfdc 

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

Thanks
sathish
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.
try{
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. 

Thanks
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
Thanks
D Naveen Rahul.