0

i had a component a testComponent.

<aura:component>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>

its controller is

doInit : function(component, event, helper) {
        console.log(typeof sforce != 'undefined');
}

when i embed this component in my detail page of contacts. it is given sforce as undefined. i am excepting that in lightning it should return as true.

5
  • sforce === undefined would return true is sforce is undefinde
    – itsmebasti
    Oct 23, 2017 at 9:13
  • You are writing the code in a lightning component itself. I didn't get the rationale behind checking whether its a lightning page or not. I suppose for this component, typeof sforce will always be true Oct 23, 2017 at 9:17
  • @HemantJain this component can be in embeded in visualforce Page to use it in classic. Oct 23, 2017 at 9:18
  • Added a answer, see if it helps Oct 23, 2017 at 9:34
  • 1
    sforce returns true if the device is mobile and false if it is desktop.
    – Sikha Baid
    Oct 23, 2017 at 9:46

1 Answer 1

2

You can use UserContext variable to check whether the component is being used in Salesforce1/Classic/LEX.

Refer the link of a blog here, which explains the usage and implementation of this.

Another detailed, example of managing the Visualforce and Lightning experience is here

Also, here is a similar question answered.

You can use this Usercontext UI theme value to detect the type of page.

See if this helps

1
  • actually i have 4-5 levels of components. So i donot want to pass attribute from visualforce down to eacha nd every component. I want to check within component . Oct 23, 2017 at 13: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.