Hi we are using Javascript Remoting in Visualforce pages. in Javascript function we are using window.open() for opening Case creation page like below.


itis populating values on Case creation page and working fine Classic. But in Lightning it is not populating values which i am passing thorugh URL like above. What i have to do now if i want to populate values in Lightning like it is populating in classic.

    <apex:page >
<apex:stylesheet value="{!URLFOR($Resource.SLDS252, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />
<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"/>

function inLightningExperience() {
    return 'Theme4d' === '{!$User.UIThemeDisplayed}';
function detectionOfTheme(){
        alert('Success....you are in Lex'); 
    }else {
        alert('Success....you are in Classic'); 

    <apex:outputPanel rendered="{!$User.UIThemeDisplayed == 'Theme3'}" id="one">
        <apex:pageBlock title="Visualforce (Using standard Visualforce Components)" mode="detail">
            <apex:outputLabel value="UI Theme Detection using Global Variables: {!$User.UIThemeDisplayed}"/>
    <apex:outputPanel rendered="{!$User.UIThemeDisplayed == 'Theme4d'}" id="two">
       <div class="slds">
    <div class="slds-card slds-card--empty">
  <div class="slds-card__header slds-grid grid--flex-spread">
    <h2 class="slds-text-heading--small slds-truncate">Visualforce (Using HTML + SLDS)</h2>
  <div class="slds-card__body slds-p-horizontal--small">
    <h3 class="slds-text-heading--small slds-p-top--large slds-p-bottom--large">UI Theme Detection using Global Variables: {!$User.UIThemeDisplayed}</h3>
    <apex:form >
    <apex:commandButton value="ThemeDisplay" onclick="detectionOfTheme();"/>
    <div id="classic" style="display:{!if(($User.UIThemeDisplayed != 'Theme4d'),"block","none")}">
    <p> This is Classic</p>  
    <div id="lightning" style="display:{!if(($User.UIThemeDisplayed == 'Theme4d'),"block","none")}">
    <p> This is Lightning</p>  

My Actual code is below, forget about all the above code:

Javascript in Static resource:

function add_Case(){
var phoneStateData = applicationState.read();
var currentActiveCallId = phoneStateData.activeCall;
var currentCall = phoneStateData.map[currentActiveCallId];
var contactId = currentCall.contactId;
var contactNumber = currentCall.contactNumber;
window.open('/500/e?retURL=%2F500%2Fo&cas3_lkid='+contactId+'&cas15='+contactNumber, 'width=200,height=100');


Li for case creation in VF:

 <li><a href="#" onclick="add_Case()">Add Case</a></li>

This is the expected behavior because URL hacks are not supported in Lightning experience.

You need to use sforce.one.createRecord to pass the default value when creating a record.

Navigation with the sforce.one Object

| improve this answer | |
  • Hi @Tushar, what i have to do now. If user is in Classic window.open will works, what if user is in LEX. Do i need to implement navigatetourl method in the same javascript function which i am using for opening contact native form using window.open in visualforce pages. is it possible. – Tulasi May 21 '18 at 7:02
  • @Tulasi You need to check if user is in classic or Lightning and based on that call the respective method. Take reference from here – Tushar Sharma May 21 '18 at 9:14
  • Hi @Tushar, i was used above code for detecting uiTheme. When i am creating visuaforce tab in Lightning then only it is working. Why i dont know. Can you help me in this because i dont need any visulforce page custom tab. – Tulasi May 22 '18 at 6:19
  • @Tulasi Your current code is in Visualforce page. Can you share where are you actually writing your code. – Tushar Sharma May 22 '18 at 7:06
  • i was added my actual code. it is the code for case creation. – Tulasi May 22 '18 at 11:00

As mentioned by Tushar, You can noy auto-populate values from URL while creating any record in Lightning Experience. You need to update your code to use force:createRecord instead of window.open as below:

var createCaseEvent = $A.get("e.force:createRecord");
createCaseEvent     .setParams({
    "entityApiName": "Case",
    "defaultFieldValues": {
        'ContactId' :contactId,
        'AccountId' : '001xxxxxxxxxxxxxxx'

It will open a case new page with auto-populated values in fields.


| improve this answer | |
  • Hi @Ayub and Tushar Can i use this javascript(mentioned by Ayub) code in Javascript function which i am using in visualforce page.Does it works or not. – Tulasi May 21 '18 at 6:41
  • So ..it's going to work in Lightning component not in Visualforce page...but you can create a lightning component and can use that in VF: developer.salesforce.com/docs/atlas.en-us.lightning.meta/… .... – Ayub May 21 '18 at 6:44
  • client wants to open native salesforce forms for creating an object either in Classic and Lightning. Is there any chance for that. – Tulasi May 21 '18 at 6:49

You will have to check if the user is in lightning or classic mode. Depending on that you can use with window.open(for classic) and sforce.one.createRecord (for lightning). You can use the visual force page extension to decide if the user is in classic or lightning mode.

Visual force page extension class

public class VisualforceExtension{
       public Boolean isClassic {get; set;}
       public VisualforceExtension(ApexPages.StandardController controller) {
             //check for classic VS. lightning mode
             if (UserInfo.getUiThemeDisplayed() == 'Theme3' && ApexPages.currentPage().getParameters().get('beLightning') == null){
                  isClassic = true;
                 isClassic = false;   
| improve this answer | |
  • Hi Shubham, i was tried Tushars solution , but it is not working. If i create a tab for that VF page in Lighnting then it is showing Lightning. But we are not creating any tabs for VF pages in Lightning. It is open cti softphone. Please help me. – Tulasi May 21 '18 at 14:03
  • Hi @shubam it is always giving false either in classic and Lightning. function add_Case123(){ var bool = {!isClassic}; alert('hhhhhhhh'+bool); } – Tulasi May 23 '18 at 5:56

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.