1

I need to store Javascript onto a object field and execute it later. However, when I create a record on the developer console and fetch it again. I found the text is minified and the JS code is not executeable. Any thought to prevent Salesforce keep doing this?

Object: Dynamic run
Field: code (long text area)

Sample code

$Lightning.use("c:lightningLoginApp", function () {
    $Lightning.createComponent("c:LoginForm" + "", {
        "aura:id": "FormId"
    }, 
        "customLogin", 
        function (cmp) {
        // this peice of JS code will be broken if minify it.
        compHdlr = cmp;
    });
}); 

Output

Salesforce will minify the multi-line content into one.

$Lightning.use("c:lightningLoginApp", function () {     $Lightning.createComponent("c:LoginForm" + "", {         "aura:id": "FormId"     },          "customLogin",          function (cmp) {         // this peice of JS code will be broken if minify it.         compHdlr = cmp;     }); }); 
  • 2
    What do you mean by minified? Can you include an example of the transformation you're seeing? – David Reed Jul 27 '18 at 22:26
  • 1
    I would think the code should work minified or not ...... – Eric Jul 27 '18 at 23:59
  • @Eric of course not. The minified version will let the single line comment break the code :( – Dummy Jul 28 '18 at 0:22
  • 3
    @Dummy - If you are handling the comment properly / doing it right it should not - that's my point - Without seeing an example that breaks it there is not much we can do to help. When done properly minified or not it should work just fine.... – Eric Jul 28 '18 at 0:36
  • What is the source of this JavaScript? Is it under your control? Why don't you simply remove // style comments? – David Reed Jul 28 '18 at 1:47
1

It's not minified, just the line breaks are removed. The problem is how you're saving the data, as long text area fields don't naturally strip out new lines. If you're using the Developer Console, that may very well be the problem; it doesn't handle certain types of data very well. Try saving the record using an Execute Anonymous script, Data Loader, something else.

  • Thanks for this update. Will try to write some apex code to acheive this. – Dummy Jul 30 '18 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.