2

I'm new to the coding side of Salesforce and am working on creating a pre-chat page for Live Agent. I've been trying to use all the resources Salesforce provides as well as other questions asked, but have not been successful. Initially I was having issues submitting the data from my pre-chat form and figured out that it was because "getContact()" was not defined, and in trying to fix this part, I now cannot save my Visualforce page with a "Error: Unknown Property 'PreChatController.RemoteAction'.

I have a feeling I'm off in multiple places, so any help will be greatly appreciated!

Apex Controller:

global class PreChatController
{
    @remoteAction
    global static sobject findContactByEmail(string name, string email, string phone)
    {
        sObject returnObject; //the id that will store the contact this chat is related to, seeing if there is a contact with this email
        list<contact> contacts = [select accountid, name, id, email from contact where email = :email limit 1];

     {

        }
        return contacts[0];
     }
}

The Visualforce page with the getContact() function I was attempting to use:

<apex:page showHeader="false" controller="PreChatController">

<script type='text/javascript'>
   (function()
   {
      function handlePageLoad() 
      {
         var endpointMatcher = new RegExp("[\\?\\&]endpoint=([^&#]*)"); 
         document.getElementById('prechatForm').setAttribute('action',
         decodeURIComponent(endpointMatcher.exec(document.location.search)[1])));
      } 
      if (window.addEventListener) 
      {
          window.addEventListener('load', handlePageLoad, false); 
      } 
      else 
      {
          window.attachEvent('onload', handlePageLoad, false);
       }
   })();  

    function getContact()
    {
        console.log('Getting contact');
        var emailAddr = document.getElementById('email').value.trim();
        var fname = document.getElelmentById('name').value.trim();

        /* try
        {*/
            visualforce.remoting.Manager.invokeAction(
            '{!RemoteAction.PreChatController.findContactbyEmail}',
            fname, 
            emailAddr,
            function(result, event)
            {
               if(event.status)
               {
                   console.log(result);
                   if(result.Id.substring(0,3) === '003')
                   {
                        document.getElementById('contactid').value = result.Id;
                    }
                    else if(result.Id.substring(0,3) === '00Q')
                    {
                        document.getElementById('leadid').value = result.Id;
                    }
                    document.forms["prechatform"].submit();
                    return true'
               }
           }, 
           {escape: false}
         );
      /*}
       catch(ex)
       {
          alert (ex.message); 
          console.log(ex);
          return false;
        }*/
        return false;
     }
</script>

<form method='post' id='prechatForm'>

    <style>
       body {
          background-image: url("{!URLFOR($Resource.LiveAgent)}");
          background-size: cover;
          font-family: 'Trebuchet MS', Helvetica, sans-serif;
          font-size: 18px;
          color: #000;    
          line-height: 18px; 
          padding-top: 38px;
          padding-bottom: 78px;
          padding-left: 78px;
          padding-right: 38px;
        }
        input[type="text"] {
            background: transparent;
            border:1px solid #000;}
       #chatFormDiv{
          width:200px;
          padding:25px;
          boarder-style: solid;
       }
       #chatHeader{
          color:#000;
          font-size:26px;
          font-weight:bold;
       }
       label{
          width:150px;
          font-weight:bold;
       }
    </style>   
<div id="chatFormDiv">
   <apex:image url="{!URLFOR($Resource.Logo2)}" width="250" height="125" style="margin-top:5px"/> <br/></div>

   <h1>Pre-Chat Form</h1>
   <br/><br/>
   <br></br>
   First name: <input type='text' name='liveagent.prechat:ContactFirstName' id='firstName' required="required" /> 
   <br />
   <br></br>
   Last name: <input type='text' name='liveagent.prechat:ContactLastName' id='lastName' required="required" />
   <br />
   <br></br>
   Email: <input type='text' name='liveagent.prechat:ContactEmail' id='email' required="required" />
   <br />
   <br></br>
   <input type="hidden" name="liveagent.prechat.name" id="prechat_field_name" />

<input type="hidden" name="liveagent.prechat.findorcreate.map:Contact"
   value="FirstName,ContactFirstName;LastName,ContactLastName;Email,ContactEmail" />

<input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Contact"
    value="Email,true"/>
<input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Contact"
    value="Email,true"/>
<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Contact"
    value="FirstName,true;LastName,true;Email,true" />

<!------Creates an auto-query for a matching Contact record's email based on the value of the prechat email field--->
<input type="hidden" name="liveagent.prechat.query:Email" value="Contact,Contact.Email"/>
<input type="hidden" name="liveagent.prechat.findorcreate.showOnFind:Contact" value="true" />
<input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Contact" value="ContactId" />


<div align="center" draggable="false"> 
<input type='submit' value='Chat Now' onclick="getContact()" id='prechat_submit' style="padding: 6px" />
</div>

<style type="text/css">
p {font-weight: bolder}
</style>
</form>
</apex:page>
0

1 Answer 1

0

It's $RemoteAction, not RemoteAction:

        '{!$RemoteAction.PreChatController.findContactbyEmail}',
3
  • Thanks @sfdcfox! That did remove the initial error message (woohoo!), but now I'm getting "No remoted actions found for 'PreChatController.findContactbyEmail'." Getting closer, I appreciate the help!
    – klunder
    Commented Jul 25, 2017 at 19:54
  • @klunder Your method has three parameters, but you're calling it with only two. I kind of expected a different error, but you might start with fixing that first.
    – sfdcfox
    Commented Jul 25, 2017 at 20:00
  • Yeah, I think that's what ends up happening when I edit the same thing too many times trying to fix it! I ended up making this a lot simpler and using more of the template Salesforce provided. Seems like I have a lot to learn yet - thank you again @sfdcfox!
    – klunder
    Commented Jul 25, 2017 at 22:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .