+ Start a Discussion
Manu KM 9Manu KM 9 


Lets say we have an object and on the lightning component we are displaying its details. when ever i click on the button i need to pass record id to the controller.

This how my code look like:-
<aura:iteration items="{! v.vegs}" var="veg">
            <div class='tile' aura:id="test1" press="{! c.tester}" >              
                <img src='{! veg.Image__c}'  onClick="{! c.tester}" aura:id="imgId" value="{! veg.Name }"> </img>
                Name: {! veg.Name } <br></br>             
                price: {! veg.Price__c }   <br></br>
                <ui:button label="Add to cart" press="{! c.addToCart}"  aura:id="btn1" >      </ui:button>               

I want something similer to :-
<aura:iteration items="{!v.newCases}" var="case">
<button type="button" onclick="{!c.showCaseDeleteModal(case.Id)}">Delete</button>

How can I pass the id to a component controller when the  button gets clicked?

Thank you!
Best Answer chosen by Manu KM 9
Veenesh VikramVeenesh Vikram
You can get ID in the JS controller directly, no need to assign to another attribute,

Do like this:
In your component, assign the record Id to the button's Id
<aura:iteration items="{!v.newCases}" var="case">  
<button type="button" onclick="{!c.showCaseDeleteModal}" id={!case.Id}>Delete</button> 
In your JS controller, capture the ID as as source of event:
showCaseDeleteModal: function(component, event, helper) {
var idx = event.target.id;
alert(idx);                       //here is your ID

Kindly mark as solved if it helps.

Suresh MeghnathiSuresh Meghnathi 
How can we display thousands of records on the VF page without using the StandardSetController or Pagination?
Best Answer chosen by Suresh Meghnathi
Ajay K DubediAjay K Dubedi
Hi Suresh,

If your purpose is to display the records only, then you can set the readOnly='true' in apex:page tag. Using this, the SOQL limit will be relaxed from 50000 to 100000.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Ajay Dubedi


I am a beginner to Salesforce development.


By default, from the Partner related list on the Opportunity, you can create OpportunityPartner junction objects between an Opportunity and a Partner Account. We want to modify this page. Unfortunately this object is not very easy to customize.


We have come up with a solution that works for us though.

I am going to create a Visualforce page with standardController 'Opportunity' and with an extension class.

The Visualforce page should be built up to look similar to the current Partner Edit page. 


So we are going to have five rows of partners where you can choose if its primary or not, the AccountToId and the Role. You don't have to fill in information on all rows.


I am not at all done with this yet and many things are not working as I would like them too (the radio buttons for instance). But currently I am stuck with the problem that the getters for the partner variables work but the setters does not. In other words I know that the getPartner methods have been run since I have seen this in the debug logs. The setters are never run though and this becomes obvious and also a problem when I try to insert one of the defined partners in the save method . I get an error that the field 'AccountToId' is a required field and should have a value:



Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [AccountToId]: [AccountToId]



Furthermore as you can see I have chosen to use the Partner object since I am not allowed to create OpportunityPartner objects. But when a Partner object gets created an OpportunityPartner object also does so that shouldn't be a problem.


VisualForce page:


<apex:page title="Partners: {!Opportunity.Name}" standardController="Opportunity" extensions="PartnerEditExt" showheader="true" sidebar="true" id="thePage"> <apex:sectionHeader title="Partners" subtitle="{!Opportunity.Name}" id="partnerEditSectionId" help="javascript:openPopupFocusEscapePounds(%27/help/doc/user_ed.jsp?loc=help&target=partners_edit.htm&section=Partners&showSplash=true%27, %27Help%27, 700, 600, %27width=700,height=600,resizable=yes,toolbar=yes,status=no,scrollbars=yes,menubar=yes,directories=no,location=no,dependant=no%27, false, false);"></apex:sectionHeader> <apex:pageMessages /> <apex:form id="theForm"> <apex:pageBlock title="Partners Edit"> <apex:pageBlockSection columns="3"> <!-- Headings --> <apex:outputText value="Primary" style="font-weight:bold" /> <apex:outputText value="Partner" style="font-weight:bold" /> <apex:outputText value="Role" style="font-weight:bold" /> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner0.isPrimary}" id="fromPartnerPrimary0"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText value="No Partner" id="noPartnerAccount"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem /> <!-- Partner 1 row --> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner1.isPrimary}" id="fromPartnerPrimary1" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner1.AccountToId}" id="fromPartner1" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner1.Role}" id="fromPartnerRole1" /> </apex:pageBlockSectionItem> <!-- Partner 2 row --> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner2.isPrimary}" id="fromPartnerPrimary2"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner2.AccountToId}" id="fromPartner2"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner2.Role}" id="fromPartnerRole2"/> </apex:pageBlockSectionItem> <!-- Partner 3 row --> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner3.isPrimary}" id="fromPartnerPrimary3"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner3.AccountToId}" id="fromPartner3"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:inputField value="{!Partner3.Role}" id="fromPartnerRole3"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom"> <apex:commandButton action="{!save}" value="Save" immediate="true" /> <apex:commandButton action="{!Cancel}" value="Cancel" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>


The Apex extension class:


public with sharing class PartnerEditExt { final Opportunity opp; Partner partner0 = null; Partner partner1 = null; Partner partner2 = null; Partner partner3 = null; ID oppId; ID accId; ID noPartnerAccId = [select id from Account where Name = 'no partner'].Id; /* Constructor */ public PartnerEditExt(ApexPages.StandardController controller) { opp = (Opportunity)controller.getRecord(); oppId = controller.getRecord().Id; accId = [select AccountId from Opportunity where Id = :oppId].AccountId; partner0 = new Partner(OpportunityId=oppId); partner1 = new Partner(OpportunityId=oppId); partner2 = new Partner(OpportunityId=oppId); partner3 = new Partner(OpportunityId=oppId); } /* Save action Insert the specified partners */ public void save() { // Currently no intelligent logic here // I just want to test that partner1 can be inserted insert partner1; } /* Cancel action Redirect user back to opportunity */ public PageReference cancel() { String curr = '/'+ApexPages.currentPage().getParameters().get('id'); PageReference pageref = new Pagereference(curr); return pageref; } /* Getters and Setters for the partner variables */ public Partner getPartner0() { return partner0; } public void setPartner0(Partner p) { partner0 = p; } public Partner getPartner1() { return partner1; } public void setPartner1(Partner p) { partner1 = p; } public Partner getPartner2() { return partner2; } public void setPartner2(Partner p) { partner2 = p; } public Partner getPartner3() { return partner3; } public void setPartner3(Partner p) { partner3 = p; } }


 Some of you might wonder why we didn't choose to use a custom object instead. We though of this but made the assumption that this work would take less time and also be less risky.


What have I done wrong?

I think I might miss some basic understanding here. A solution to my problem with a good explanation would be very welcome!



Thanks / Niklas



Best Answer chosen by Admin (Salesforce Developers) 

Your button has the immediate attribute set to 'true' - this not only skips validation (well document) but also doesn't update any user inputs from the page (not so well documented).


Remove this attribute (which will give you the default value of 'false') and your setters will be invoked. 

Albert van GinkAlbert van Gink 

Trailhead: https://trailhead.salesforce.com/projects/quickstart-lightning-components/steps/quickstart-lightning-components3

Problem saving MyContactList.cmp.
Field_Integrity_Exception: Failed to save MyContactList.cmp: Invalid definition for null:MyContactListComponent: null: Source

public class MyContactListController {
public static List<Contact> getContacts(Id recordId) {
   return [Select Id, FirstName, LastName, Email, Phone From Contact Where AccountId = :recordId];

<aura:component controller="MyContactListComponent" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="Account" type="Account" />
<aura:attribute name="Contacts" type="Contact" />
<aura:attribute name="Columns" type="List" />
<force:recordData aura:id="accountRecord"
<lightning:card iconName="standard:contact" title="{! 'Contact List for ' + v.Account.Name}">
    <!-- Contact list goes here -->

User-added image

Anyone any idea or suggestion to help?

Thank you, regards, albert
Best Answer chosen by Albert van Gink
hi albert ,
use below component code :
use  controller="MyContactListController"​ not controller="MyContactListComponent"​
<aura:component controller="MyContactListController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="Account" type="Account" />
<aura:attribute name="Contacts" type="Contact" />
<aura:attribute name="Columns" type="List" />
<force:recordData aura:id="accountRecord"
<lightning:card iconName="standard:contact" title="{! 'Contact List for ' + v.Account.Name}">
    <!-- Contact list goes here -->
i hope it helps you.
 Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others

Kahlil DozierKahlil Dozier 
In Objective C, I follow the steps as outlined here and it works fine: https://developer.salesforce.com/docs/atlas.en-us.noversion.mobile_sdk.meta/mobile_sdk/ios_rest_apis_using_methods.htm?search_text=forceios

But when following the same steps translating the code into Swift, I run into an issue with the SFRestRequest initializer, whose signature is below:
Public convenience init(method: SFRestMethod, path: String, queryParams: [String : String]?)

As you can see, queryParams takes a Swift Dictionary with a key and value of the String type.  But when you follow the example, it seems you end up with a Dictionary with a key of the String type and value of the Dictionary type; and thus we have a type mismatch.

This doesn't seem to be a problem in Objective C, because upon inspection of the method signature in SFRestRequest.m, queryParams appears to be able to take a generic NSDictionary: 
+ (instancetype)requestWithMethod:(SFRestMethod)method path:(NSString *)path queryParams:(NSDictionary *)queryParams

For reference here is the Swift code I'm trying out:
//build the queryParams dictionary from a JSON String
let body: String = "{ \"body\" :{\"messageSegments\" :[{ \"type\" : \"Text\",\"text\" : \"My Comment\"}]}}"
        let queryParams = SFJsonUtils.objectFromJSONString(body) as! [String:AnyObject] 
//construct and send the request
        let request = SFRestRequest(method: SFRestMethod.POST, path: "/services/data/v36.0/connect/communities/my_community_ID/chatter/feed-elements/my_element_ID/capabilities/comments/items", queryParams: queryParams as? [String:String])
        SFRestAPI.sharedInstance().send(request, delegate: self)

But unwrapping queryParams fails and resolves to nil.  Trying to forcefully cast queryParams to [String:String] does not work either, and just causes a crash.

How might I get around this?
Best Answer chosen by Kahlil Dozier
Kahlil DozierKahlil Dozier
So what I did was to follow the directions outlined in http://stackoverflow.com/questions/24002369/how-to-call-objective-c-code-from-swift to create an Objective-C file that my Swift code could call.  

Below are my Objective-C interface/implementation files:

//  SFRestRequestSending.h

#import <Foundation/Foundation.h>
#import <SalesforceRestAPI/SalesforceRestAPI.h>
#import <SalesforceSDKCore/SalesforceSDKCore.h>
/*This is an Objective-C wrapper class that exists to allow swift classes to use the requestWithMethod:path:queryParams: method of the SFRestRequest class whenever we have a non-nil value for queryParams.  Currently, this method plays fine accepting generic NSDictionaries in Objective-C, but requires a Dictionary specifically typed [String:String] in Swift.  This might be a bug in the SalesforceRestAPI framework, because we need to pass generic swift dictionaries to this method to form some requests.*/
@interface SFRestRequestSending : NSObject

@property(nonatomic,strong) SFRestRequest* restRequest;
 parameter "method" is an NSInteger which refers to the http request method:
 GET = 0
 POST = 1
 PUT = 2
 HEAD = 4
 PATCH = 5 */

//standard SFRestRequest
-(id)initWithMethod:(NSInteger)method path:(NSString*)path queryParams:(NSDictionary*)queryParams;

//  SFRestRequestSending.m

#import "SFRestRequestSending.h"
#import "My_Project_Name-Swift.h"

@implementation SFRestRequestSending

-(id)initWithMethod:(NSInteger)method path:(NSString *)path queryParams:(NSDictionary *)queryParams{
    self = [super init];
        self.restRequest = [SFRestRequest requestWithMethod:method path:path queryParams:queryParams];
    return self;

Replace "My_Project_Name" with the name of your Xcode project, as specified in the stack overflow directions. 

Then, from swift, I would call this class like:
//compose and execute a GET request
let requestWrapper = SFRestRequestSending(withMethod: 0, path: myPath, queryParams: paramDict);

let request = requestWrapper.restRequest;

SFRestAPI.sharedInstance().send(request, delegate: myDelegate);

Timothy SmithTimothy Smith 
Attempting to access the variables MIlestone1_Project__c has a Lookup relationship to Account with relationship name: `Projects__r'.
List<Account> accList = [SELECT Id, Name, EHR_Status__c, PM_Status__c,
                                    Project_Imp_Status__c, Other_Status__c,(select Client_Advisor_Email__c,
                                                                                 from Projects__r) 

                             FROM Account
                             WHERE Id IN :AcctIds];
List<String> emailAdds = new List<String>();
                 for (Account al: accList) {

Any help is greatly appreciated.
Best Answer chosen by Timothy Smith
Boss CoffeeBoss Coffee
Projects__r will be a list for each Account, so it'll be something like the following.
for(Account al : accList) {
  for(Project__c proj : al.Projects__r) {
    // ...etc
Naoki Kitaarashi 4Naoki Kitaarashi 4 
It's a basic question. How to rename Lightning component once created?  I couldn't find any menu on Devloper console and any buttons on Setup|Develop|Lightning Components. Is it necessary to delete and create new one with new name?
Best Answer chosen by Naoki Kitaarashi 4
Himanshu ParasharHimanshu Parashar
Hi Naoki,

Yes that is correct. You need to delete the component and create new one with new name.

Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Stuart Miles 25Stuart Miles 25 
Hi, can anyone please help me with creating a test class and js controller to display a simple banner on a lightning page? Complete novice here :-)

<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
    <img src="{!$Resource.Discussion_Banner}"/>

thanks everyone
Best Answer chosen by Stuart Miles 25
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi Stuart,
No need to write test classes for lightning components.In salesforce we need to write test classes for apex classes and triggers  to test your business logic  and to ensure that your Apex classes and triggers work as expected.

Pleas  refer below link which might help you further

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards
YiQin HeYiQin He 

I created a lightning component as a quick action button. In the component, I have a cancel button that I want it closed when user clicks.
User-added image

But the problem is that I cannot find any document explain how to close the modal dialog. This is the ui code:
<aura:component controller="ContactController" implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" >
        .changeRecordTypeRow {
        margin-top: 1.5rem;
        margin-bottom: 0;
        margin-left: 0;
        margin-right: 0;
        .changeRecordTypeLeftColumn {
        float: left;
        text-align: right;
        padding-right: 1.5rem;
        width: 35%;
        font-size: .8125rem;
        color: rgb(84, 105, 141);
        .changeRecordTypeRightColumn {
        float: right;
        text-align: left;
        width: 65%;
        	height:auto !important;
        .forceChatterLightningComponent .bodyWrapper{height:100%;width:100%;padding:0;box-sizing:border-box}
    <div class="modal-header slds-modal__header">
        <h2 class="title slds-text-heading--medium" >Change Contact Type</h2>
    <div class="scrollable slds-modal__content slds-p-around--medium">
        <div class="changeRecordTypeRow">
            <fieldset class="slds-form-element">
                <div class="changeRecordTypeLeftColumn">
                    <legend class="form-element__legend slds-form-element__label">Select a record type</legend>
                <div class="changeRecordTypeRightColumn slds-form-element__control">

                    <span class="slds-radio">
                        <input type="radio" id="radio_PrimaryContact" name="recordType" />
                        <label class="slds-radio__label" for="radio_PrimaryContact">
                            <span class="slds-radio--faux"></span>
                            <span class="slds-form-element__label">Primary Contact</span>
                    <span class="slds-radio">
                        <input type="radio" id="radio_SecondaryContact" name="recordType" />
                        <label class="slds-radio__label" for="radio_SecondaryContact">
                            <span class="slds-radio--faux"></span>
                            <span class="slds-form-element__label">Secondary Contact</span>
    <div class="modal-footer slds-modal__footer">
    	<div class="forceChangeRecordTypeFooter">
        	<button type="button" class="slds-button slds-button--neutral .slds-modal__close" aura:id="btnCancel" >
            <button type="button" class="slds-button slds-button--brand" aura:id="btnSave">
Does anyone have similar experience? Thanks in advance.
Best Answer chosen by YiQin He
YiQin HeYiQin He
Hi Karthik,

Thanks for the reply. I've already found the solution.
Call this method $A.get("e.force:closeQuickAction").fire() will close the modal dialog.

Example select id from account where id iN:accList 
Best Answer chosen by Praveenchandu
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi praveen,
list<list<sobject>> acc = new list<list<sobject>>();
acc = [FIND 'test' RETURNING Account(id,name WHERE id in :ids),contact(id,name WHERE id in :ids)];
list<id> ids1 = new list<id>();
for(sobject a : acc[0]){
for(sobject c:acc[1]){
//you can use this way to get ids in seperate lists
Account [] accounts = ((List<Account>)acc[0]);
Contact [] contacts = ((List<Contact>)acc[1]);


Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards