3

This is similar to the problem here

Lightning Components in Visualforce

but is slightly different in that the page is being loaded in the context of a community.

We are in the process of developing some extensions to an existing VF-based community using lightning and LC4VF. Everything works in a dev org, the VF page is served from the xxx.force.com community domain and the LO app is picked up from the same domain:

https://conseq-df1-developer-edition.eu5.force.com/c/DfcLoader.app?aura.format=JSON&aura.formatAdapter=LIGHTNING_OUT

In a sandbox or in production this fails 404 though:

https://dfuat-dfuat.cs17.force.com/c/DfcLoader.app?aura.format=JSON&aura.formatAdapter=LIGHTNING_OUT 404 (Not Found)

There is no obvious difference between the two, though the dev org does have a My Domain and the production org doesn't (though adding one to the sandbox seems to make no difference).

1

My Domain is required to use Lightning Components in any container currently even if that container is not my domain savvy. Can you first validate that you can access a simple .app that uses you component completely outside of LC4VF? Did you activate your My Domain in sandbox after creating a domain for it?

1

I just happened to look at the attached source for your VF page:

<h1>Test</h1>

<apex:includeScript value="{!$Site.BaseUrl}/lightning/lightning.out.js"/>

<div id="ltng" />

<script>
var baseUrl = '{!$Site.BaseUrl}';
var sessionId = '{!$Api.Session_ID}';
$Lightning.use('c:LSample', function(){
  $Lightning.createComponent('ui:button', {sessionId: sessionId}, 'ltng');
}, baseUrl, null);
</script>

and there are a couple of things that stand out:

  • use of ui:button without the required label= attribute should never work (independent from the communities parts)

  • the style of invocation you are using for $Lightning.use() where you are passing in a value for the lightning end point URI is causing LO to switch into full cross domain mode (LO XD) and might be part of the way to a workaround but 2 things stand in our way:

    1. CORS Whitelist needs to be setup with an entry for $Site.BaseUrl (not hard to do)
    2. LO XD is only available in Developer Preview in Winter'16 which means it only works in a Dev Edition org without a pilot perm that requires paperwork etc

Our best option is to get this foxed for LC4VF to automatically do what it normally does and switches to serving all LC resources and endpoints from the same domain as the conatiner page which avoids both #1 and #2. You will then just have to remove the manual baseURL setting logic you have in place.

  • Its great if a fix is coming for this. The button could do with a label of course but a blank button gets created. The endpoint is passed to $Lightning.use() mainly for the case where the community base url includes a path. (As it happens I had tried LO XD as a workaround, passing the org's lightning.force.com domain as the endpoint to $Lightning.use() and setting up cors, but the request for the app on the lightning domain comes back with a redirect to xxx.my.salesforce.com/visualforce/session?url=... and because cors headers are not added to that 302 response everything dies there.) – Martin Lewis Nov 5 '15 at 13:15
0

Heads up for folks using Lightning Components for Visualforce that have not been able to use their pages with Communities/Sites:

The fix for this should be on all instances now. We've also released a new Visualforce component to make this even easier (no need to worry about sessionID or base URLs). Documentation update will be out next week but this is the short version: just change:

<apex:includeScript value="/lightning/lightning.out.js" />

to:

<apex:includeLightning/>

and you should be good to go for all contexts where your Visualforce page can be used.

NOTE: you should never have to specify baseURL or sessionID when using LC4VF from this point forward as long as you leverage <apex:includeLightning/>

  • Following up on this, I still get the 404 error in my sand box even with <apex:lightningOut/> VF page lives on shore--staging--c.cs87.visual.force.com/apex/testLab?token=... When lightning.use is called I get the 404, its trying to load shore--staging--c.cs87.visual.force.com/c/… Whereas shore--staging.lightning.force.com/c/… Works as expected and serves a JSON of the cmp – Christian Szandor Knapp Feb 5 '16 at 17:52
  • What is apex:lightningOut? Did you mean apex:includeLightning? – Doug Chasman Feb 5 '16 at 23:36
  • Can you try accessing the VF page directly from your sandbox org and see if that does not yield the 404? Folks have been running fine with VF in Communities since the patch fix back in November '15 - no open bugs or cases on this so I am unsure what the specific issue is you are encountering. – Doug Chasman Feb 5 '16 at 23:39
  • Doug, sorry for the confusion. Yes, I was talking about apex:includeLightning. Accessing the public site gives me a 401. Accessing the VF Page directly from sandbox, I get a 404. All URLs are found in my comment above, see also developer.salesforce.com/forums/ForumsMain?id=906F00000005Gg2 – Christian Szandor Knapp Feb 7 '16 at 12:53
  • 1
    OK - from looking at the developer.salesforce.com forum post you linked in above I see you are trying to use LC in a guerst user/non authenticated container and that is not currently supported. This is on the roadmap and I had hoped to see it be part of Summer'16 but safe harbor and all that. I can say that when it does surface publicly there will simply be a lightning interface that you will add to your ltng:outApp - something like implements="ltng:allowGuestAccess". – Doug Chasman Feb 8 '16 at 13:37

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.