+ Start a Discussion
DIEHARDDIEHARD 

How do I Integrate Apex Code in Web-to-Lead Form?

Good Morning Folks,

Do any of you know how to incorporate Apex code in a HTML Web-to-Lead form so that it execute when the "submit" button is pressed?   Down below  is a Web-to-Lead form that was generated by SF that I would like to modify so that apex code fires up when pressing the "submit" button.  The Apex code will then check if the Lead we are trying to enter already exists in the SF.  If it does exist, then it will update the existing Lead record accordingly.  Any help will be greatly appreciated.  And I will give kudos.  I promise

 

<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: Please add the following <META> element to your page <HEAD>.      -->
<!--  If necessary, please modify the charset parameter to specify the        -->
<!--  character set of your HTML page.                                        -->
<!--  ----------------------------------------------------------------------  -->

<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">

<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: Please add the following <FORM> element to your page.             -->
<!--  ----------------------------------------------------------------------  -->

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

<input type=hidden name="oid" value="00DE0000000c06c">
<input type=hidden name="retURL" value="http://">

<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: These fields are optional debugging elements. Please uncomment    -->
<!--  these lines if you wish to test in debug mode.                          -->
<!--  <input type="hidden" name="debug" value=1>                              -->
<!--  <input type="hidden" name="debugEmail"                                  -->
<!--  value="jsiller@ucinnovation.com">                                       -->
<!--  ----------------------------------------------------------------------  -->

<label for="first_name">First Name</label><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>

<label for="last_name">Last Name</label><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>

<label for="email">Email</label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br>

<label for="company">Company</label><input  id="company" maxlength="40" name="company" size="20" type="text" /><br>

<label for="city">City</label><input  id="city" maxlength="40" name="city" size="20" type="text" /><br>

<label for="state">State/Province</label><input  id="state" maxlength="20" name="state" size="20" type="text" /><br>

<input type="submit" name="submit">

</form>

ryanjuptonryanjupton

There's really no easy to way to accomplish this is as you would have to authenticate in order to execute the VF page and and Apex behind it.

It is possible to do something like this (functionality wise) with Sites but it involves a tiny, tiny bit of hacking. Usually web 2 lead and executing Apex are two separate things. What exactly are you trying to accomplish? There might be a better way.

CaptainObviousCaptainObvious

As long as your code doesn't need any further interaction from the user, you could consider writing your APEX in a Lead Trigger.

 

Just make sure that the trigger looks for some value on a field that can only be set from a web-to-lead form (so that the trigger doesn't run when entering a lead from Salesforce).

 

Hope this makes sense...

DIEHARDDIEHARD

I am trying to process the lead to be entered via web-to-lead form by  first checking if the lead already exists.  If the lead already exists then we just need to update the Campaign History by adding a new entry.  If the lead does not exist then just add the record to the Lead object as usual.  I could probably accomplish this behaviour by writing an APEX trigger, but we are  using the professional edition, which does not support APEX triggers development.

 

I appreciate your response.  Thank you.

 

 

ryanjuptonryanjupton

Diehard. If that's the case Apex won't help as you can't run Apex in Professional Edition unless it's part of an ISV managed package.