• Gerald George
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
I want to post form fields from my web page into salesforce via web to lead and also in my local database.  Can anyone show me how to do this with .Net mvc c# ? I have common fields like user name,email,phone etc 
Please look at my code here



my code
<script type="text/javascript">
        function submitPractice() {
            webToLead({
                oid: '00D20000000l2qZ'
                //,debug:1
                //, debugEmail: 'gerald@ghanafx.com'
 , first_name: $("#PracticeUserDetail_FirstName").val()
 , last_name: $("#PracticeUserDetail_LastName").val()
 , email: $("#Email").val()
 , country_code: $("#PracticeUserDetail_Country").val()
 , lead_source: 'web demo'
 , description: 'This is an automated transparent lead'
            });

            //practiceform
            var formData = JSON.stringify($("#practiceform").serializeArray());
            $.ajax({
                type: "POST",
                url: "/Account/Practice",
                data: formData,
                success: function () { },
                dataType: "json",
                contentType: "application/json"
            });

        }
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://166.62.127.6/';//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>


 
Below is the code I am using ... I am not sure if this is right.


int debug = 1; // 1 = true
            string debugEmail = "erald@ghanafx.com";
            StringBuilder data = new StringBuilder();
            data.Append("oid=[00D20000000l2qZ]");
            data.Append("&retURL=" + HttpContext.Current.Server.UrlEncode("https://secure.ghanafx.com/open-live-account-thanks"));
            data.Append("&first_name=" + HttpContext.Current.Server.UrlEncode("Mohsin"));
            data.Append("&last_name=" + HttpContext.Current.Server.UrlEncode("Ali"));
            data.Append("&email=" + HttpContext.Current.Server.UrlEncode("mohsin_ali_nisar@yahoo.com"));
            data.Append("&country_code=" + HttpContext.Current.Server.UrlEncode("AX"));
            data.Append("&00N0O00000ALjKl=" + HttpContext.Current.Server.UrlEncode("50"));
            data.Append("&00N0O00000ALj57=" + HttpContext.Current.Server.UrlEncode("S/E"));
            data.Append("&00N0O00000ALj52=" + HttpContext.Current.Server.UrlEncode("7PM"));
            data.Append("&00N0O00000ALj4n=" + HttpContext.Current.Server.UrlEncode("Expert"));
            data.Append("&mobile=" + HttpContext.Current.Server.UrlEncode("03319337096"));
            data.Append("&phone=" + HttpContext.Current.Server.UrlEncode("05453534"));
            data.Append("&title=" + HttpContext.Current.Server.UrlEncode("MOSS"));
            data.Append("&debug=" + debug);
            data.Append("&debugEmail=" + HttpContext.Current.Server.UrlEncode(debugEmail));
            // Post the data
            byte[] buffer = Encoding.UTF8.GetBytes(data.ToString());
            string url = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            buffer = Encoding.UTF8.GetBytes(data.ToString());
            req.ContentLength = buffer.Length;
            using (Stream reqst = req.GetRequestStream())
            {
                reqst.Write(buffer, 0, buffer.Length);
                
            }


 

Hello,

        I need bulk api code in C#.net.The developer guide gives the code for client java application.I need it for C#.net.or can i convert the same code to C#.I tried it using IKVM,buit couldnot do it successfully.Please help.