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
Kajal Singh 36Kajal Singh 36 

How to write a trigger with using handler to fetch web-to-lead from my custom lead object and how i assign a predefined owner to my custom lead

AnudeepAnudeep (Salesforce Developers) 
You can't create a Lead with a null OwnerId, through Web-to-Lead, or in Apex. Lead.OwnerId is defaultedOnCreate, and so will be set when the object is created, before any triggers are run. For custom lead you should use lead.ownerId

Unless set through a hidden form field (which is a bad idea anyway, as you'd be putting a User Id in public web forms), Lead.OwnerId will be set to the Default Lead Creator specified in Web-to-Lead settings. You could set that to a user that should never own Leads, and then base your trigger logic on that user owning the Lead. Or you could set another field on Lead with a hidden form field, and base your trigger logic on that.

If you want to take a look at sample trigger code you can check this post. However, as per this documentation, currently, there is no automated feature to identify how a lead is created, however, there's a way to show that a lead has been created using Web-to-Lead.

To show that a Lead has been created using Web-to-Lead:
  • Adding the Lead Source field when creating the Web-to-Lead code
  • With the assistance of the web master or web developer, auto-populate the field with the value of the Lead Source by modifying the generated HTML code and set the field to hidden.
Let me know if this helps, if it does, please close the query by marking it as solved. It may help others in the community. Thank You!
ANUTEJANUTEJ (Salesforce Developers) 
Hi Kajal,

By default there is an option of web to lead using which you can generate a form and in there is an option to have a default lead generator have you checked this?

User-added image
Under Default lead creator you can choose one user as the default creator.

In case if you are looking for a way to implement web to any object there is a way that is mentioned in the below link :

>> https://trailblazers.salesforce.com/answers?id=90630000000Ze4CAAS

Additionally, there is an idea for web to any object that you can upvote so that it can be considered in the future if it reaches the necessary threshold so that the feature is OOB:

>> https://trailblazer.salesforce.com/ideaView?id=08730000000Bri0

Does this help and in case if this comes in handy can you please choose this as the best answer so that it can be useful for others in the future.

Thanks.