3

I have a trigger on Leads like this:

trigger LeadTrigger on Lead (after insert, after update) {
   // I only see the following line in the logs when I manually insert a new lead   
   system.debug('**** LEAD TRIGGER ****');
   LeadTriggerHandler.handleTrigger();
}

When a lead is created via a Web2Lead form the trigger is not fired. When I create a new lead myself the trigger fires and operates fine.

I have Enforce Validation and Triggers from Lead Convert checked in my Lead settings

How can I get it to work after a web2lead insert?

  • As a point of reference, Web 2 Lead has nothing to do with converting Leads; W2L just creates new Leads based on the web form. Are you sure the W2L is pointing to the correct org? – Mike Chale Jan 6 '14 at 17:33
  • @Mike - Definitely going to the correct org, because the leads are created. – JannieT Jan 6 '14 at 18:31
  • @JannieT What is the context user? Do you reach any logs for that user when posting a web2lead form? What is logging level for that user? Would you mind sharing that log? – endrju Jan 7 '14 at 15:25
  • Thanks @endrju - this log was captured by monitoring the Site Guest User with default logging levels (APEX code is set to DEDUG). Looks fine to me and as I say, the lead is successfully created. – JannieT Jan 7 '14 at 17:01
  • If I run the web2lead capture form as a user with full System Administrator profile, I get a similar log which only logs page controller code up to when the form is submitted and nothing more. – JannieT Jan 7 '14 at 17:15
2

From the comments on your question it appears you are looking at the logs from a Sites user. I assume you are hosting the Web2Lead form in Sites somewhere.

I ran the following test and it seemed to fire the after insert Trigger as expected.

As such, I'd suggest checking the log that gets created for the /servlet/servlet.WebToLead operation to see if there are any errors there.

Step 1

Create a minimal Lead after insert trigger

trigger LeadTrigger on Lead (after insert, after update) {
    system.debug('**** LEAD TRIGGER AFTER INSERT/UPDATE ****');
}

Step 2

Save a minimal version of the Web2Lead form to my local drive.

<HTML>
    <HEAD>
        <META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
    </HEAD>
<BODY>
    <!--  ----------------------------------------------------------------------  -->
    <!--  NOTE: Please add the following <FORM> element to your page.             -->
    <!--  ----------------------------------------------------------------------  -->

    <form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">

    <!-- Rest of Salesforce generated form here -- >
    </form>
</body>
</HTML>

Step 3

Open it in a web browser

Web2Lead opened in browser

Step 4

Set the TraceFlags for the Web-to-Lead Default Lead Creator (Monitored Users/Open the Developer Console/FuseIT SFDC Explorer *). The log should be created for them (unless my existing session cookies are betraying me).

Default Lead Creator

Step 5

Submit the web-to-lead form and capture the log. It will appear with Operation of /servlet/servlet.WebToLead. When I check this log I can see the expected after insert trigger gets invoked and the debug message appears.

enter image description here

* Full Disclosure: I work for the company that makes the FuseIT SFDC Explorer. That said, it is free and applicable here as it can set the TraceFlags to capture the log, as is shown in the last image.

  • Thanks, @Daniel. Your debugging steps helped me to see that my web2lead lead entries are actually triggering the insert script. The trigger was failing silently, because I was monitoring the wrong user in the logs. – JannieT Jan 11 '14 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.