• Abhishek Sagar 1
  • NEWBIE
  • 15 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 17
    Replies
Can any one help me on this....
In classic  while passing object record id in the URL will get the field values on the page ,how can we achieve this in the lightning.
Here am tryng same but unable to get field values and where can I pass the id in the lightning,below is my component and app.



<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
    <aura:attribute name="expense" type="expense__c"/>
<p>Amount:<ui:outputCurrency Value="{!v.expense.Amount__c}"/></p>
<p>Client:<ui:outputtext value="{!v.expense.Client__c}"/> </p>
<p>Date:<ui:outputdate value="{!v.expense.Date__c}"/></p>
<p>Reimbursed?: <ui:outputcheckbox value="{!v.expense.Reimbursed__c}"/></p>
    <ui:outputText class="form-control" aura:id="recid" value="{!v.recordId}" />
</aura:component>


<aura:application >
  
    <c:expense/>
        
</aura:application>


Thanks in advance.

I am basically diving into Lightning Component Development as I generally learn faster applying examples to real-world problems. In this case, I am trying to replace a javascript button that launched a window with a Visualforce page that has its own styling, Unfortunately adding the launch as a quickAction will open the window, but I can't get the size to match the content, making it largely unusable, even with scroll bars. 

Instead, I figure since Lightning Components are so Javascript heavy anyway, why can't I just build a Lightning Component featuring a UI button, an APEX controller providing a method to return the record ID, and a js controller with a doInit()function that queries the record data, while the button click launches the newInterview() method which contains the original Javascript that opens the Visualforce page using the parameters from the current record. That's the idea anyway...

Here is how I tried to build it:

COMPONENT
<aura:component controller="AuraMethods" implements="flexipage:availableForAllPageTypes,force:lightningQuickAction,force:hasRecordId" access="global" >
	<aura:attribute name="opp" type="Opportunity"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <ui:button label="New Interview" press="{!c.newInterview}"/>
</aura:component>

JS CONTROLLER
({
	doInit : function(component, event) {
		var action = component.get(c.findOppById("v.recordId"));
        action.setCallback(this, function(a) {
            component.set("v.opp", a.getReturnValue());
        });
        $A.enqueueAction(action);
	}
})

({
    newInterview : function(component, event){
        if(component.get("v.opp.School_Interview_Type__c")== '3W' || component.get("v.opp.School_Interview_Type__c") == '3W+School'){ 
        	window.location.href = "/apex/AM_Time_Slots2?id="+component.get("v.opp.Id")+"&Name="+component.get("v.opp.Name"); 
        } 
        else{ 
        	alert('please do not make an appointment AM time when the School Interview Type not equals 3W,only need to confirm the following AM given in the school time.'); 
        }
    }  
})

APEX CONTROLLER
public with sharing class AuraMethods {
    @AuraEnabled
    public static Opportunity findOppByID(String OppId){
        return [Select id, Name, School_Interview_Type__c from Opportunity where Id = :OppId];
    }
}


That's pretty much it. The Component appears in the Custom Components section of my Lightning Page Layout for the Opportunity in the App Builder, but when I try to place it I get the following error:

'Action failed: c:InterviewScheduling$controller$doInit [c is not defined] doInit()@components/c/InterviewScheduling.js:10:30'

I know I'm still a bit green to JS, as well so I may have missed something. More important, I've seen several posts about the difficulty of getting a javascript button's functionality to work in Lightning. I really just want to be able to launch this Visualforce page from within the Opportunity and have it appear in all its glory rather than in some dinky popup window where I can't adjust the width in the settings. 

I appreciate all responses. Kindness and patience is appreciated. I will learn this. 

Thanks!

V

Hello,

I need to know the opener of a lightning application. for this, I would use window.opener. The value of window.opener is not managed by javascript (execution of code stops) when the current window have been opened by another one.

What is the reason why this regular environment variable is not useable in ligthning ?

Hello. I am more of an admin than a developer. Anyway I'm working on a community, and trying to figure out how to customize the apex controller that is automatically created for the Self Registration lightning component that is also created when communities are activated. This class is called LightningSelfRegisterController and it's code is included.

All, I want to do is put some system.debugs into the code so that I can get an understanding of how a portion of it is working. So, putting the debug statements in is no problem. The problem is that I now expect a log to be generated when I use the Self-Registration page, but no logs are generated. I suppose this is because the code is not executed in the context of any user that I have a trace flag on. So, I tried putting a trace flag on the class itself, but that hasn't worked either. 

Can anybody point me in the righ direction?

Thanks!!

 

global class LightningSelfRegisterController {

    public LightningSelfRegisterController() {

    }

    @TestVisible 
    private static boolean isValidPassword(String password, String confirmPassword) {
        return password == confirmPassword;
    }
    
    @TestVisible 
    private static boolean siteAsContainerEnabled(Id networkId) {
        Auth.AuthConfiguration authConfig = new Auth.AuthConfiguration(networkId,'');
        return authConfig.isCommunityUsingSiteAsContainer();
    }
    
    @TestVisible 
    private static void validatePassword(User u, String password, String confirmPassword) {
        if(!Test.isRunningTest()) {
        Site.validatePassword(u, password, confirmPassword);
        }
        return;
    }
    
    @AuraEnabled
    public static String selfRegister(String firstname ,String lastname, String email, String password, String confirmPassword, String accountId, String regConfirmUrl, String extraFields, String startUrl, Boolean includePassword) {
        Savepoint sp = null;
        try {
            sp = Database.setSavepoint();
            
            if (lastname == null || String.isEmpty(lastname)) {
                return Label.Site.lastname_is_required;
            }
            
            if (email == null || String.isEmpty(email)) {
                return Label.Site.email_is_required;
            }
            
            User u = new User();
            u.Username = email;
            u.put('Email',email);
            
            u.FirstName = firstname;
            u.LastName = lastname;
            
            String networkId = Network.getNetworkId();

            // If using site to host the community the user should not hit s1 after logging in from mobile.
            if(networkId != null && siteAsContainerEnabled(networkId)) {
                u.put('UserPreferencesHideS1BrowserUI',true);
            }
            
            String nickname = ((firstname != null && firstname.length() > 0) ? firstname.substring(0,1) : '' ) + lastname.substring(0,1);
            nickname += String.valueOf(Crypto.getRandomInteger()).substring(1,7);
            u.put('CommunityNickname', nickname);
                     
            if (extraFields != null) {
                List<Object> extraFieldsList = (List<Object>) JSON.deserializeUntyped(extraFields);        
                for (Object thisFieldObject : extraFieldsList) {
                    system.debug('thisFieldObject '+thisFieldObject);
                    Map<String,Object> thisField = (Map<String,Object>) thisFieldObject;
                    Schema.SObjectField sof = Schema.SObjectType.User.fields.getMap().get((String) thisField.get('fieldPath'));
                    u.put(sof, thisField.get('value'));
                }
            }
                        
            if (includePassword) {    
                if (!isValidPassword(password, confirmPassword)) {
                    return Label.site.passwords_dont_match;
                }
             validatePassword(u, password, confirmPassword);
            }
            else {
                password = null;
            }
            
            // lastName is a required field on user, but if it isn't specified, we'll default it to the username
            String userId = Site.createPortalUser(u, accountId, password);
            // create a fake userId for test.
            if (Test.isRunningTest()) {
                userId = 'fakeUserId';           
            }
            if (userId != null) { 
                if (password != null && password.length() > 1) {
                    ApexPages.PageReference lgn = Site.login(email, password, startUrl);
                    if(!Test.isRunningTest()) {
                     aura.redirect(lgn);
                    }
                }
                else {
                    ApexPages.PageReference confirmRef = new PageReference(regConfirmUrl);
                    if(!Test.isRunningTest()) {
                    aura.redirect(confirmRef);
                   }

                }
            }
            return null;
        }
        catch (Exception ex) {
            Database.rollback(sp);
            return ex.getMessage();            
        }
    }
    
    @AuraEnabled
    public static List<Map<String,Object>> getExtraFields(String extraFieldsFieldSet) { 
        List<Map<String,Object>> extraFields = new List<Map<String,Object>>();
        Schema.FieldSet fieldSet = Schema.SObjectType.User.fieldSets.getMap().get(extraFieldsFieldSet);
        if(!Test.isRunningTest()) {
        if (fieldSet != null) {
            for (Schema.FieldSetMember f : fieldSet.getFields()) {
                Map<String, Object> fieldDetail = new Map<String, Object>();
                fieldDetail.put('dbRequired', f.getDBRequired());
                fieldDetail.put('fieldPath', f.getFieldPath());
                fieldDetail.put('label', f.getLabel());
                fieldDetail.put('required', f.getRequired());
                fieldDetail.put('type', f.getType());
                fieldDetail.put('value', '');   // client will populate
                extraFields.add(fieldDetail);
            }}}
        return extraFields;
    }
}

https://success.salesforce.com/ideaview?id=08730000000BqX6AAK

According to this^ thread it isnt possible to sort activity feed... pretty much at all.

This seems insane to me, but before I try to hunt down a solution I wanted to see if anyone here has experience (or a solution!) to share.

 
Keep getting this error below in the App Manager panel and have been seeing werid behavior in other places.  Some apps I did for trailheads no longer function correctly either, some produce Aura.loadComponent(): Failed to initialize application errors while others are not displaying any data.

Uncaught TypeError: Cannot read property 'b' of null throws at https://geowil-dev-ed.lightning.force.com/auraFW/javascript/hS-U-Sm-fapuqhqczmdv5g/aura_prod.js:345:219


Aura.loadComponent(): Failed to initialize application. An internal server error has occurred Error ID: 1999217911-47099 (713029975)
Hi - I have a lightning component that is working on Desktop with lightning experience. The same component is not working on Mobile browser  (Salesforce1).

Here is the error.
https://www.screencast.com/t/yrmvmyx2SC

No idea what the problem is. Thanks, JD
I am implementing lightning:tabset and lightning:tab to display tabs in a lightning component -- I am trying to conditionally display one particular tab based on a value returned by the controller -- but it is not rendering the tab. Does anyone have any insight into how to achieve this functionality? Also, when I try to set the selectedTabId in the init function, I get an error saying the tab does not exist.

Controller:
({
	doInit : function(component, event, helper) {
        var action = component.get("c.getSearchFromId");
        action.setParams({
            "recordId": component.get("v.recordId")
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === "SUCCESS"){
                if(response.getReturnValue().Candidates_Visible__c == true){
                    component.set('v.displayCandidates',true);
                } else {
                    component.set('v.displayCandidates',false);
                }
                component.set('v.search',response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
	}
})
Component:
 
<aura:component controller="SecureSiteController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >

    <ltng:require styles="/resource/slds_2_1_3/assets/styles/salesforce-lightning-design-system-vf.css" />
    
    <aura:attribute name="recordId" type="String" access="global" />
    <aura:attribute name="search" type="Search__c" access="global" />
    <aura:attribute name="displayCandidates" type="Boolean" default="false" />

    <aura:handler name="init" value="{!this}" action="{!c.doInit}" access="global" />
    
    <!-- Display secure site tabs -->
    <lightning:tabset variant="default" selectedTabId="{!v.selTabId}">
		<aura:if isTrue="{!v.displayCandidates == true}">
            <lightning:tab aura:id="candidates" tabindex="1" id="candidates" title="Candidates" label="Candidates">
                <c:CandidateViewer recordId="{!v.recordId}" />
            </lightning:tab>
        </aura:if>
        <lightning:tab aura:id="searchmaterials" tabindex="2" id="searchmaterials" title="Search Materials" label="Search Materials">
            <c:SearchMaterials recordId="{!v.recordId}" />
        </lightning:tab>
        <lightning:tab aura:id="keydates" tabindex="3" id="keydates" title="Key Dates" label="Key Dates">
            <c:SearchKeyDates recordId="{!v.recordId}" />
        </lightning:tab>
        <lightning:tab aura:id="consultants" tabindex="4" id="consultants" title="Consultants" label="Consultants">
            <c:SearchConsultants recordId="{!v.recordId}" />
        </lightning:tab>
        <lightning:tab aura:id="securemessage" tabindex="5" id="securemessage" title="Send a Message" label="Send a Message">
            <c:SecureSiteMessage recordId="{!v.recordId}" />
        </lightning:tab>
    </lightning:tabset>
    
</aura:component>


 
Hi All , 

I have requirment where i need to display the dynamic table in lightning based on the Object , fileds paased from the Components and display it in vf page.

Please see the code that i am trying here:
===Application====
<aura:application access="GLOBAL" extends="ltng:outApp"    >
 <c:PMD_LightningHomepage object="Opportunity" fields="Id" limit="5" tableId="table1"/>
      <aura:dependency resource="c:PMD_LightningHomepage "  /> 
 </aura:application>

===Component==

<aura:component controller="controller" implements="force:appHostable,flexipage:availableForAllPageTypes">
    <ltng:require styles="/resource/SDLC212/assets/styles/salesforce-lightning-design-system-vf.min.css" />
    <aura:attribute name="object" type="String" />
    <aura:attribute name="limit" type="String" default="5" />
    <aura:attribute type="sObject[]" name="latestRecords" />
    <aura:attribute name="fields" type="String[]" default="Id,Name" />
    <aura:attribute name="tableId" type="String"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">    
        <head>
        </head>    
        <body> 
            <div class="wrapperscoop">                
                <div class="slds-card__header slds-grid">
                    <div class="slds-media slds-mcate">
                        <div class="slds-media__figure">                           
                        </div>
                        <div class="slds-media__body">
                            <h2 class="slds-text-heading--small slds-truncate">Recently Viewed</h2>
                        </div>
                    </div>                   
                </div>
                <div class="slds-card__body">                    
                    <section class="slds-card__body">
                        <div class="slds-scrollable--x">
                            <table class="slds-table slds-table--bordered slds-max-medium-table--stacked-horizontal">
                                <thead>
                                    <tr class="slds-no-hover">
                                        <aura:iteration items="{!v.fields}" var="field" >
                                            <th class="slds-text-heading--label slds-size--1-of-6" scope="col">{!field}</th>
                                        </aura:iteration>
                                    </tr>
                                </thead>
                                <tbody id="{!v.tableId}">
                              </tbody>
                                    
                            </table>
                        </div>
                    </section>
                </div>
            </div>            
        </body>
    </html>
</aura:component>

===Js-controller=====
({
    doInit  : function(component, event, helper) {
        var action = component.get("c.getRecords");
        var fields = component.get("v.fields");  
        var tableId = component.get("v.tableId"); 
        action.setParams({
            ObjectName : component.get("v.object"),
            limits : component.get("v.limit"),
            //alert('Check1' + fields);
            fieldstoget : fields.join()
        });
        
        action.setCallback(this,function(response){
            var delayMillis = 1000;
            var state = response.getState();
            if(state === 'SUCCESS'){
                component.set("v.latestRecords",response.getReturnValue());
                var retRecords = response.getReturnValue();
                retRecords.forEach(function(s) {
                    var tableRow = document.createElement('tr');
                    fields.forEach(function(field){ 
                        var tableData = document.createElement('td');
                        var tableDataNode = document.createTextNode(s[field]);
                        tableData.appendChild(tableDataNode);
                        tableRow.appendChild(tableData);
                    });
                    // alert(tableId);
                    //alert('tableval' + document.getElementById(tableId) );
                    setTimeout(function() {
                       
                        alert(document.getElementById(component.get("{!v.tableId}")));
                   document.getElementById(component.get("{!v.tableId}")).appendChild(tableRow);
                 }, delayMillis);
                    
                });
            }else if (state === "ERROR") {
                console.log('Error');
            }          
        });
       $A.enqueueAction(action);
        
    }
})

But when i try calling it from Vf page its not able to take the div id and reads it null and hence shows below error , can anybody help me on this,thanks..

Error:
This page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'appendChild' of null] Callback failed: apex://PMD_DispRecordsController/ACTION$getRecords Failing descriptor: {markup://c:PMD_LightningHomepage}

Please suggest .

Note : This coponnent Works fine when i do not call it from Vf page i.e preview it directly.



 
Hi All,

Is it Safe to use document.getElementById(id) in Lightning Controller.

In recent release they mentioned that we cannot modify DOM objects .

Like using 
1.document.getElementById(id).checked
2.document.getElementById(id).Value

Etc Etc.???

Thanks
Arjun.M

 
Getting the error "A.getCallback(): 'callback' must be a valid Function : false" while running my component. when such error occurs ?
How does map type of attribute work? How can I receive the list of keys and list of values from the map in JavaScript?

I receive data from apex method, and I would like to use aura:attribute with map type to keep Id and Quantity, Is it possible to keep it on the client side using map type of attribute?
<aura:attribute name="OpportunityLineItem" type="Map" default="{ '0065800000CINW0': 'name1', '0065800000CINWP': 'name2' }" />