You need to sign in to do that
Don't have an account?

Getting '$A is not defined' error while doing VF Trailhead
Hello,
I'm doing a 'Visualforce Basics' module and I'm stuck at 'Use Standard Controllers' Unit (link here).
I created a page with the following code:
I'm doing a 'Visualforce Basics' module and I'm stuck at 'Use Standard Controllers' Unit (link here).
I created a page with the following code:
<apex:page> <apex:pageBlock title="Account Summary"> <apex:pageBlockSection> </apex:pageBlockSection> </apex:pageBlock> </apex:page>
Then I opened a page via the "Preview" button in a Developer Console and opened a JavaScript console in Chrome where I typed:
$A.get("e.force:navigateToURL").setParams({"url": "/apex/AccSum"}).fire();And I got the following error:
Uncaught ReferenceError: $A is not defined at <anonymous>:1:1
Both the snippets are copied from the Unit's sections, I didn't change anything except the page's name - 'AccSum'. I tried all of the above in a Firefox which also did not work.
Does anyone know what's going on?
All Answers
It's said there "To preview your page in the context of Lightning Experience, open your browser’s JavaScript console and enter the following code. Don’t forget to replace pageName with your page’s name:", so I thought it would be done by the SF to show me the page in the Lightning Experience.
Anyway, when I normally visit my instance, it's Lightning, not Classic, so I assume I'm in the Lightning Experience.
Screenshot below. This is Chrome 62 on a Mac, nothing special.
What browser are you in?
Here's what I did:
1) Used the dev console to create the page.
2) in my browser, went back to the main screen where I could see the standard salesforce ui. (NOT the dev console)
3) Used Chrome's menu to go to Developer tools, Javascript console
4) Entered the $A text
Is that what you did?
I'm starting to wonder if it's tied to this "clickjack" settings - but these appear to be things only Salesforce themselves can change? And I'm now stuck in an infinite loop of sorts trying to get into a login that actually lets me contact SF support... fun.
1) Called in Dev Console from my SF sandbox Setup (in Lightning mode). $A is NOT undefined here.
2) Called from same domain as above but from my custom VisualForce Page: $A IS undefined here.
1) Created a page with the Developer Console

2) In DE Setup page: Custom Code -> Visualforce Pages -> Clicked my page's name -> Clicked "Preview"
3) Opened Developer Tools (Ctrl + Shift + I) in Chrome and clicked a Console tab
4) Typed $A
Either way - very frustrating! We just want $A to work! =/
Yup, it does but I think it actually does not matter in this particular case.
ReidC
I checked "$A" on my DE instance's main page and it works - I don't get any error.
1. The jQuery Mobile zip I downloaded had a different file structure than the lesson did so my CSS and image paths weren't loading right until I discovered this and fixed it. So now the basic Visualfoce Page is at least loading itself and the Static Resources correctly now (I can move on to the next course).
2. Handful of Chrome Dev Console errors about MIME types, X-Frames, $A undefind etc (Remain unresolved but not blocking course progression). I still hope to get this resolved but moving on for now.
Ok, now I fully understood how to cope with the problem. It works of course :) Thank you!
PS If you really think it's not clear enough, there are more places in the module where it's not mentioned that a JS console should be opened while being in a Lightning Experience.
I got obviously the same errors than anybody there,
I'm using the Lighning Sandbox, but when I use the preview button I got this URL coming :
https://curious-moose-283525-dev-ed--c.eu12.visual.force.com/apex/HelloWorld
That's why, listening to what said @ReidC, I tried to change the visual.force.com into .lightning.force.com/
That said, I tried :
https://curious-moose-283525-dev-ed.lightning.force.com/apex/HelloWorld
instead of
https://curious-moose-283525-dev-ed--c.eu12.visual.force.com/apex/HelloWorld
It works but redirect to the URL endding with visual.force.com ...
If anyone could help, thanks by advance ;
I've to admit I'm not really comfortable with Salesforce ...
Thanks !
Got the anwser from here (https://developer.salesforce.com/forums/?id=9060G000000BiGtQAK)
Thanks guys !!
I got the same error : "Uncaught ReferenceError: $A is not defined at <anonymous>:1:1"
It has been resolved now.
So you need to follow the steps given below to resolve the issue.
1. login on salesforce using your username and password.(if not already logged in or playground is not opened) Url:(https://login.salesforce.com/), use your trailhead credentails or dev org credential.
2. Above will open your dev org or palyground. (if it is not ligthtning then switch to lightning experience.).
3. press F12 in chrome window.
4. click on console tab.
5. put the $A.get("e.force:navigateToURL").setParams(
{"url": "/apex/AccountSummary"}).fire();
//(Replace AccountSummary with the page/url you want to open).
6. press return/enter.
Note: $A is not recognized on the other pages because it's resources(libraries/assemblies/jars..) are not available there.
Even i was facing this issue, followed steps given by you and it worked. Many thanks
It worked for me after enabling the flag "Available for Lightning Experience, Lightning Communities, and the mobile app" on the visual force page and then following the procedure specified by Mrutyunjaya above.
The step says "The rendered page opens in a new window. Note that this page preview shows your page without Salesforce styling. To see your page in the context of Lightning Experience, return to your main browser window. Open your browser’s JavaScript console and enter the following code. Don’t forget to replace pageName with your page’s name:
$A.get("e.force:navigateToURL").setParams( {"url": "/apex/pageName"}).fire(); "
If you try to do this in the browser window where the visual force page is previewed, it will throw error $A is not defined
To fix that, go to the browser window/tab where the Saleforce home page is open (you should ofcourse login to see the Salesforce Home page). Press F12 in chrome to open the developer window. There is a tab called Console, click on it and copy paste the code there. Hit enter and you will be able to see the Visual force page in your saleforce home page/header.
Just a bit later in 2021, and I can't even get it to work in Lightning. (Chrome Version 91.0.4472.124 (Official Build) (64-bit)) It's not as dramatic an error, though, it simply returns "undefined".

This is where I begin my adventure -- home page of my playgrond org, with the console open.
What you can see but not read is this:


DevTools failed to load source map: Could not parse content for https://empathetic-moose-fc8459-dev-ed.lightning.force.com/javascript/1515605724000/ui-sfdc-javascript-impl/source/RecordGVP.js.map: Unexpected end of JSON input
DevTools failed to load source map: Could not load content for https://static.lightning.force.com/auraFW/javascript/1622757889931/aura_prod.js.map: HTTP error: status code 503, net::ERR_HTTP_RESPONSE_CODE_FAILURE
DevTools failed to load source map: Could not parse content for https://empathetic-moose-fc8459-dev-ed.lightning.force.com/javascript/1595964957000/canvas/source/CanvasRendering.js.map: Unexpected end of JSON input
DevTools failed to load source map: Could not parse content for https://empathetic-moose-fc8459-dev-ed.lightning.force.com/javascript/1571087976000/ui-analytics-reporting/source/EclairNG.js.map: Unexpected end of JSON input
Which suggests to me that we're already in trouble. And that is what I suspect is causing the later problem:
Which is described as:
And since it's still too small to read:
$A.get("e.force:navigateToURL").setParams(
{"url": "/apex/AccountSummary?&id=00141000004jkU0AAI"}).fire();
undefined
I assume this is the more graceful version of :
VM75:1 Uncaught ReferenceError: $A is not defined
at eval (eval at <anonymous> (AccountSummary:1), <anonymous>:1:1)
at <anonymous>:1:1
eval @ VM75:1
(anonymous) @ VM30:1
I had actually guessed that you had to start from somewhere in Lightning (or at least Salesforce) in order to make that work so that everythign would be properly instantiated, but it seems that the problem begins well before we even mention $A.
I've managed to use the URL manipulation trick to get around this and continue working, but if there's anything later in the Unit that can't be done without the broswer console, I'm up the creek.