1

I would like to be able to do something like this:

$A.localizationService.WallTimeToUTC(d, timezone, function(utc) {
    displayDate = $A.localizationService.formatDateTime(utc, format, langLocale);
})

from a VisualForce page. I would like to be able to access the aura lightning $A global instance namespace from the VisualForce page, use components like <ui:outputCurrency>, or at least the localization service. If possible, what is the easiest workaround/way to accomplish this?

  • By using lightning out and converting you VF page to a lightning component. It's the only way $A is accessible AFAIK. You could always use JS localization methods I believe – Eric May 4 '17 at 3:32
  • I would if I could, but I can't. Might have to use JS library. Any best suggestions for SF? I have looked at a few. – amanda fouts May 4 '17 at 3:42
1

You should be able to make an empty lightning app and component and call your localizationservice function in the callback of that component creation.

Something like this:

<apex:page >

    <!--rest of your page stuff -->

    <apex:includeLightning />

    <div style="display: none !important; id="lightning" />
    <script>
    var displayDate;

    $Lightning.use("c:EmptyApp", function () {
      $Lightning.createComponent("c:EmptyComponent", {},
         lightning, function (cmp) {
             $A.localizationService.WallTimeToUTC(d, timezone, function(utc) {
                 displayDate = $A.localizationService.formatDateTime(utc, format, langLocale);
                     console.log(displayDate);
             })
         });
    });
    </script>
</apex:page>

You could even try saving a reference to $A so you can call it again without instantiating a dummy component - ie in the callback, do something like:

window.$A = $A;

I don't know if this will work, but it might be worth a try.

  • Works. Probably can't do any better workaround... – amanda fouts May 4 '17 at 17:30
  • It's a bit naughty, but I'm glad it works. – Caspar Harmer May 4 '17 at 17:31

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.