You need to sign in to do that
Don't have an account?
The new Learner
How to fetch current Record id in lighting and pass to controller
HI Experts,
I am new to Lighting , i have requirment i need to update Account fields by creating button , i have created component and helper and controller its working fine when i pass id in my controller but i need to make my code dyanmic means what ever account record i pick randomly that account field has to update. can anyone help me pls below is my code. Thanks in advace
Component :
<aura:component controller="AccountFieldupdats" implements="force:lightningQuickActionWithoutHeader,flexipage:availableForRecordHome,force:hasRecordId,force:hasSObjectName">
<!--<aura:attribute name="updateCheckBox" type="Account" default="{'sobjectType':'Account'}"/>-->
<lightning:button variant="brand" label="Update A Checkbox" onclick="{!c.updateCheck11}" />
</aura:component>
Controller :
({
updateCheck11 : function(component, event, helper) {
alert('inside controller');
helper.updateCheck11_helper(component, event, helper);
}
})
Helper :
({
updateCheck11_helper : function(component, event, helper) {
alert('inside helper');
var save_action = component.get("c.updateCheck");
save_action.setParams({ });
$A.enqueueAction(save_action);
}
})
Apex controller:
public class AccountFieldupdats {
@AuraEnabled
public static void updateCheck(){
list<Account> Act_list = new list<Account>();
Act_list = [select id,Call_List__c from Account where id=''];
Account ACC =new Account();
ACC.id=Act_list[0].id;
ACC.Call_List__c=False;
update ACC;
}
}
I am new to Lighting , i have requirment i need to update Account fields by creating button , i have created component and helper and controller its working fine when i pass id in my controller but i need to make my code dyanmic means what ever account record i pick randomly that account field has to update. can anyone help me pls below is my code. Thanks in advace
Component :
<aura:component controller="AccountFieldupdats" implements="force:lightningQuickActionWithoutHeader,flexipage:availableForRecordHome,force:hasRecordId,force:hasSObjectName">
<!--<aura:attribute name="updateCheckBox" type="Account" default="{'sobjectType':'Account'}"/>-->
<lightning:button variant="brand" label="Update A Checkbox" onclick="{!c.updateCheck11}" />
</aura:component>
Controller :
({
updateCheck11 : function(component, event, helper) {
alert('inside controller');
helper.updateCheck11_helper(component, event, helper);
}
})
Helper :
({
updateCheck11_helper : function(component, event, helper) {
alert('inside helper');
var save_action = component.get("c.updateCheck");
save_action.setParams({ });
$A.enqueueAction(save_action);
}
})
Apex controller:
public class AccountFieldupdats {
@AuraEnabled
public static void updateCheck(){
list<Account> Act_list = new list<Account>();
Act_list = [select id,Call_List__c from Account where id=''];
Account ACC =new Account();
ACC.id=Act_list[0].id;
ACC.Call_List__c=False;
update ACC;
}
}
I trust you are doing very well.
You'll need to get the record Id in the lightning component, which is what the force:hasRecordId interface is for. It is automatically initialized from the context if you declare the interface force:hasRecordId.
Please try the below code. Kindly modify the code as per your requirement.
Component:
Controller:
Apex:
Finally, add this component on the Account record page.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Khan Anas
All Answers
I trust you are doing very well.
You'll need to get the record Id in the lightning component, which is what the force:hasRecordId interface is for. It is automatically initialized from the context if you declare the interface force:hasRecordId.
Please try the below code. Kindly modify the code as per your requirement.
Component:
Controller:
Apex:
Finally, add this component on the Account record page.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Khan Anas
How would I add this into my existing string?
@AuraEnabled
public static void updateRecord(List <String> lstRecordId) {
List<Opportunity> lstUpdate = new List<Opportunity>();
for(Opportunity Opp : [SELECT Id, Name, SyncedQuoteId, RecordTypeId, Trip_File_LEAD__c FROM Opportunity WHERE Id IN : lstRecordId]){
lstUpdate.add(Opp);
}
if(lstUpdate.size() > 0){
update lstUpdate;
Thank you!