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;     }); }); 
6
  • 2
    What do you mean by minified? Can you include an example of the transformation you're seeing?
    – David Reed
    Commented Jul 27, 2018 at 22:26
  • 1
    I would think the code should work minified or not ......
    – Eric
    Commented Jul 27, 2018 at 23:59
  • @Eric of course not. The minified version will let the single line comment break the code :(
    – Dummy
    Commented Jul 28, 2018 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
    Commented Jul 28, 2018 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
    Commented Jul 28, 2018 at 1:47

1 Answer 1

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.

1
  • Thanks for this update. Will try to write some apex code to acheive this.
    – Dummy
    Commented Jul 30, 2018 at 17:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .