• Alejandro Iquira
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I want to authenticate using only JavaScript in a HTML page. The objective is to do something similar to web to lead: an html file that could be used to create records in a custom object without using any server application. Off course I know is not totally possible to have a web-to-lead because the authentication is needed to do any transactions in SF and I understand the risk of security hardcoding the credentials access in the page ( that part of security on that HTML is something that it will be managed).
So I've created the next example, using JSFORCE documentation but it is not working. I set some alerts to know which code parts are being executed, but the from alert("step 3" ) nothing happens:
 
<!DOCTYPE html>
<html>
<head>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jsforce/1.6.3/jsforce.min.js"></script>
    <script>    
      alert("step 1" );
      initialize();
      function initialize(){
         alert("step 2" );
         var jsforce = require('jsforce');
         alert("step 3" );
         var conn = new jsforce.Connection({
          oauth2 : {
            // you can change loginUrl to connect to sandbox or prerelease env.
            loginUrl : 'https://login.salesforce.com',
            clientId : '3weweweweweweweweweXX.EIqGx5wXExlptPkkF6alVtMlFmjFeXFpPb76N_p6puepP70VpDfjviFl3bqcIegvj',
            clientSecret : '555555767236744359',
            redirectUri : 'https://www.google.com.co'
           }
         });
        conn.login('user@domain.com', 'pasw1234POpoNARTSERxCY1rtMVf3G0QNq', function(err, userInfo) {
          if (err) { return console.error(err); }
          // Now you can get the access token and instance URL information.
          // Save them to establish connection next time.
          console.log(conn.accessToken);
          console.log(conn.instanceUrl);
          // logged in user property
          console.log("User ID: " + userInfo.id);
          console.log("Org ID: " + userInfo.organizationId);
          // ...
        });
         alert("step 4" );
      }
</script>

</head>

 <body>
    <div>
        Javascript and salesforce  Example
    </div>
 </body>
</html>
I don't need sites, because the client has to adapt to the implementation of the site meanwhile with something like web to lead, the client could integrate easy to their own sites.
Please, anybody could help what I am doing wrong?
 
I want to authenticate using only JavaScript in a HTML page. The objective is to do something similar to web to lead: an html file that could be used to create records in a custom object without using any server application. Off course I know is not totally possible to have a web-to-lead because the authentication is needed to do any transactions in SF and I understand the risk of security hardcoding the credentials access in the page ( that part of security on that HTML is something that it will be managed).
So I've created the next example, using JSFORCE documentation but it is not working. I set some alerts to know which code parts are being executed, but the from alert("step 3" ) nothing happens:
 
<!DOCTYPE html>
<html>
<head>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jsforce/1.6.3/jsforce.min.js"></script>
    <script>    
      alert("step 1" );
      initialize();
      function initialize(){
         alert("step 2" );
         var jsforce = require('jsforce');
         alert("step 3" );
         var conn = new jsforce.Connection({
          oauth2 : {
            // you can change loginUrl to connect to sandbox or prerelease env.
            loginUrl : 'https://login.salesforce.com',
            clientId : '3weweweweweweweweweXX.EIqGx5wXExlptPkkF6alVtMlFmjFeXFpPb76N_p6puepP70VpDfjviFl3bqcIegvj',
            clientSecret : '555555767236744359',
            redirectUri : 'https://www.google.com.co'
           }
         });
        conn.login('user@domain.com', 'pasw1234POpoNARTSERxCY1rtMVf3G0QNq', function(err, userInfo) {
          if (err) { return console.error(err); }
          // Now you can get the access token and instance URL information.
          // Save them to establish connection next time.
          console.log(conn.accessToken);
          console.log(conn.instanceUrl);
          // logged in user property
          console.log("User ID: " + userInfo.id);
          console.log("Org ID: " + userInfo.organizationId);
          // ...
        });
         alert("step 4" );
      }
</script>

</head>

 <body>
    <div>
        Javascript and salesforce  Example
    </div>
 </body>
</html>
I don't need sites, because the client has to adapt to the implementation of the site meanwhile with something like web to lead, the client could integrate easy to their own sites.
Please, anybody could help what I am doing wrong?
 
Hi Guys,
When i click on custom button it will generate zipfile with attachments which i selected records. Everthing was fine but, if i try more than 4.3 MB it was throwing an error message. Here i used 2 Apex classes not used any visualforce page. I think the problem for apex class as of i queried the body from attachments. If we reduce the body length, may it come.I have been working on this issue for so many days. Could you please solve this issue.

Thanks,
Gopi.