1

im creating SObject("Attachment") the problem is depends on how big is the file usually it take some amount of seconds do get the results. I want to find a away to alert me when the result comes back so i can stop the spinner.

<script src="/soap/ajax/34.0/connection.js" type="text/javascript"></script> <script> var AttachmentList = []; var att = new sforce.SObject("Attachment"); att.Name = this.file.name; att.ContentType = this.file.type; att.Body = (new sforce.Base64Binary(e.target.result)).toString(); AttachmentList.push(att); var attachmentListJSON = JSON.stringify(AttachmentList); console.log('attachmentListJSON'); console.log(attachmentListJSON); </script> 

1 Answer 1

1

I am sure you can use asynchronous methods in AJAX Toolkit which provide you with a callback whenever the result is returned:

Example:

var account = new sforce.SObject("Account"); account.Name = "my new account"; sforce.connection.create([account], { onSuccess: function(result) { if (result[0].getBoolean("success")) { spinner(hide); } else { showError(); } }, onFailure: function(error) { showError(); } }); 
1
  • It's the AJAX Toolkit. Calling it connection js is a bit off the mark. You should also declare your function variables as const so they are locally scoped. Or just make them anonymous as part of your parameters. Commented Mar 12, 2018 at 17:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.