• DIEHARD
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies

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>

I would like to develop a Trigger that first checks if a Lead record is already in the system.  If it is not  then go ahead and allow the system to create a new Lead with new campaign.  Otherwise update the existing Lead by including it in a new campaign.

 

The trigger below parses the Description field to obtain an email address.  It then associates the email address with a contact using a query, and then finally inserts the contact into the invitee list of the event.   It then loops back to parse new addresses and continue the process. The trigger works but I  need to modify it to create a list of contacts instead of invitees when shared activities is enabled..  Does anyone have an idea?  I know it's not a good idea to include a query inside a for loop but since we are dealing with multiple invitees then I don't know a way around it. 

 

Trigger ParseAndAddInvites on Event(after insert) {

    List<string> elist;

    LIST<Contact> contacts;  

    EventRelation er;

    string qemail;

    String input;

    String[] splitInput;

 

 

    for(Event e: Trigger.new) {

   

            // Create a list of emails by using ';' as delimeter      

            input = e.Description;

            if(input != null){

                input = input.replace('\r',' ');

                input = input.replace('\n',' ');

                input = input.replace('\t',' ');

                splitInput = input.split(' ');

            }         

            elist = new List<String>( splitInput );

           

            // Iterate through the list if not empty

            if (!elist.isEmpty())

                for(Integer j = 0; j < elist.size(); j++){

                   

                    if(elist[j].contains('@') && elist[j].contains('.')){

                        qemail = elist[j].trim();

                        contacts = null;

            // Query for contact name and  contact ID, associated with recipient email address

                        contacts = new List<Contact>([Select ID,Email,Name from Contact where Email = :qemail]);

                       

            // Create and insert new attendee using queried contact and event info

                        if(!contacts.isEmpty()){

                            er = new EventRelation(EventId = e.ID, RelationId = contacts[0].ID);

                            insert er;                      

                        }

                    }

                }                      

    }

}

I am unable to assign the WhoId field to a contact ID in the trigger below. I do actually get the ID from the query statement in trigger.  I have verified that already, but when I assigned it to WhoId for the event that's firing the trigger, nothing seems to happen.  Any clues?

 

trigger ContactList on Event (before insert) {
    List<string> elist;
    LIST<Contact> contacts;   
    EventRelation er;
    string qemail;
    String input;
    String[] splitInput;

    for(Event e: Trigger.new) {
    
            // Create a list of emails by using ';' as delimeter       
            input = e.Description;
            if(input != null){
                input = input.replace('\r',' ');
                input = input.replace('\n',' ');
                input = input.replace('\t',' ');
                splitInput = input.split(' ');
            }          
            elist = new List<String>( splitInput );
            
            // Iterate through the list if not empty
            if (!elist.isEmpty())
                for(Integer j = 0; j < elist.size(); j++){
                    
                    if(elist[j].contains('@') && elist[j].contains('.')){
                        qemail = elist[j].trim();
                        contacts = null;
            // Query for contact name and  contact ID, associated with recipient email address
                        contacts = new List<Contact>([Select ID,Email,Name from Contact where Email = :qemail]);
                        if(!contacts.isEmpty())
                            e.WhoId = contacts[0].ID;                    
                        }
                    }
    }
}

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>

 

The trigger below parses the Description field to obtain an email address.  It then associates the email address with a contact using a query, and then finally inserts the contact into the invitee list of the event.   It then loops back to parse new addresses and continue the process. The trigger works but I  need to modify it to create a list of contacts instead of invitees when shared activities is enabled..  Does anyone have an idea?  I know it's not a good idea to include a query inside a for loop but since we are dealing with multiple invitees then I don't know a way around it. 

 

Trigger ParseAndAddInvites on Event(after insert) {

    List<string> elist;

    LIST<Contact> contacts;  

    EventRelation er;

    string qemail;

    String input;

    String[] splitInput;

 

 

    for(Event e: Trigger.new) {

   

            // Create a list of emails by using ';' as delimeter      

            input = e.Description;

            if(input != null){

                input = input.replace('\r',' ');

                input = input.replace('\n',' ');

                input = input.replace('\t',' ');

                splitInput = input.split(' ');

            }         

            elist = new List<String>( splitInput );

           

            // Iterate through the list if not empty

            if (!elist.isEmpty())

                for(Integer j = 0; j < elist.size(); j++){

                   

                    if(elist[j].contains('@') && elist[j].contains('.')){

                        qemail = elist[j].trim();

                        contacts = null;

            // Query for contact name and  contact ID, associated with recipient email address

                        contacts = new List<Contact>([Select ID,Email,Name from Contact where Email = :qemail]);

                       

            // Create and insert new attendee using queried contact and event info

                        if(!contacts.isEmpty()){

                            er = new EventRelation(EventId = e.ID, RelationId = contacts[0].ID);

                            insert er;                      

                        }

                    }

                }                      

    }

}