Skip to content

Instantly share code, notes, and snippets.

@samuel-alves
Forked from mhamzas/Web2Case.html
Created February 23, 2023 17:12
Show Gist options
  • Save samuel-alves/951efc1bbbe1419d0422182bfb674c1f to your computer and use it in GitHub Desktop.
Save samuel-alves/951efc1bbbe1419d0422182bfb674c1f to your computer and use it in GitHub Desktop.

Revisions

  1. @mhamzas mhamzas created this gist Nov 5, 2019.
    44 changes: 44 additions & 0 deletions Web2Case.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    <script type="text/javascript">

    // Case Data preparation
    var postData = {
    oid: '00D0b000000xxxx', //Put your ORGID here
    name:'John Smith',
    company:'ACME',
    email:'[email protected]',
    origin:'Web',
    subject:'Web2Case using the custom API',
    description:'This is an automated transparent Case sent using our custom API.'
    }


    // Send data to Salesforce
    webToCase(postData);

    // Web to Case function
    function webToCase(fields) {
    var customHiddenIframeName='JLA_API';
    if(!document.getElementById(customHiddenIframeName)){
    var theiFrame=document.createElement("iframe");
    theiFrame.id=customHiddenIframeName;
    theiFrame.name=customHiddenIframeName;
    theiFrame.src='about:blank';
    theiFrame.style.display='none';
    document.body.appendChild(theiFrame);
    }
    fields['retURL']='http://127.0.0.1';//dummy URL
    var form = document.createElement("form");
    form.method = "POST";
    form.action = "https://webto.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8";
    form.setAttribute("target", customHiddenIframeName);
    for (var fieldName in fields) {
    var theInput = document.createElement("input");
    theInput.name=fieldName;
    theInput.value=fields[fieldName];
    theInput.setAttribute("type", "hidden");
    form.appendChild(theInput);
    }
    document.body.appendChild(form);
    form.submit();
    }
    </script>
    42 changes: 42 additions & 0 deletions Web2Lead.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    <script type="text/javascript">

    // Lead Data preparation
    var postData = {
    oid: '00D0b000000xxxx', //Put your ORGID here
    first_name: 'M Hamza',
    last_name: 'Siddiqui',
    email: '[email protected]',
    phone: '1112223333',
    }


    // Send data to Salesforce
    webToLead(postData);

    // Web to lead function
    function webToLead(fields) {
    var customHiddenIframeName='JLA_API';
    if(!document.getElementById(customHiddenIframeName)){
    var theiFrame=document.createElement("iframe");
    theiFrame.id=customHiddenIframeName;
    theiFrame.name=customHiddenIframeName;
    theiFrame.src='about:blank';
    theiFrame.style.display='none';
    document.body.appendChild(theiFrame);
    }
    fields['retURL']='http://127.0.0.1';//dummy URL
    var form = document.createElement("form");
    form.method = "POST";
    form.action = "https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
    form.setAttribute("target", customHiddenIframeName);
    for (var fieldName in fields) {
    var theInput = document.createElement("input");
    theInput.name=fieldName;
    theInput.value=fields[fieldName];
    theInput.setAttribute("type", "hidden");
    form.appendChild(theInput);
    }
    document.body.appendChild(form);
    form.submit();
    }
    </script>