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
Saravana RavikumarSaravana Ravikumar 

How to debug the following code to determine why Leads are not being created. Lead l = new Lead(Name = ‘A’); Database.insert(l, false); How should the code be altered to help debug the issue?

prakash SFprakash SF
try{
Lead l = new Lead(Name = ‘A’);
    Database.insert();
}catch(Exception Exp){
    System.debug('Insert Failed Due To ' +Exp.getMessage());
}

 
Arun Kumar 1141Arun Kumar 1141
Hi @Saravana,

Try using Try Catch so that any exception will fall into the catch block and you could check why the insertion failed .
For e.g. in your code the below exception is coming: 

User-added image

Therefore please also add the required field Company .

Hope this is helpful.

Thank  you.