You need to sign in to do that
Don't have an account?
SHAIK MOULALI369
Page not navigate To SObject
While clicking button here the page is not navigate to SObject.
Apex Class :
public class ContactListController {
@auraEnabled
public static List<contact> getContactList(String accountId){
List<Contact> ContactList = New List<Contact>([Select Id, FirstName, LastName, Name, Email, phone
from contact where Email != null AND AccountId =: accountId ]);
return ContactList;
}
}
Component Class :
<aura:component Controller="ContactListController"
implements="force:hasRecordId,flexipage:availableForAllPageTypes" >
<aura:attribute name="ContactList" type="Contact[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<div class="slds-p-around_xxx-small">
<div class="slds-grid slds-wrap">
<aura:iteration items="{!v.ContactList}" var="con">
<div class="slds-col slds-size_1-of-3 slds-p-around_xxx-small">
<lightning:card footer="{!con.Email}" title="{!con.LastName}" iconName="action:add_contact">
<aura:set attribute="actions">
<lightning:button name="{!con.Id}" variant="brand" label="View Details" onclick="{!c.DoRedirect}"/>
</aura:set>
<p class="slds-p-horizontal_xxx-small">
{!con.FirstName} {!con.LastName} <br/>
{!con.phone}
</p>
</lightning:card>
</div>
</aura:iteration>
</div>
</div>
</aura:component>
Controller Class :
({
doInit : function(component, event, helper) {
/* Step 1 */
var action = component.get('c.getContactList');
/* Step 2 */
action.setParams({
accountId : component.get('v.recordId'),
});
/* Step 4 */
action.setCallback(this, function(response){
var responseValue = response.getReturnValue();
console.log('responseValue', responseValue);
component.set('v.ContactList',responseValue)
}, 'SUCCESS');
/* Step 4 */
$A.enqueueAction(action, true);
},
DoRedirect : function(component, event, helper) {
var eventsource = event.getsource();
var id = eventsource.get('v.name');
var navEvt = $A.get("e.force:navigateToSObject");
navEvt.setParams({
"recordId": "id",
"slideDevName": "detail"
});
navEvt.fire();
},
})
Here c.DoRedirect is working or not, plsease suggest me is there any error in the above code.
Apex Class :
public class ContactListController {
@auraEnabled
public static List<contact> getContactList(String accountId){
List<Contact> ContactList = New List<Contact>([Select Id, FirstName, LastName, Name, Email, phone
from contact where Email != null AND AccountId =: accountId ]);
return ContactList;
}
}
Component Class :
<aura:component Controller="ContactListController"
implements="force:hasRecordId,flexipage:availableForAllPageTypes" >
<aura:attribute name="ContactList" type="Contact[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<div class="slds-p-around_xxx-small">
<div class="slds-grid slds-wrap">
<aura:iteration items="{!v.ContactList}" var="con">
<div class="slds-col slds-size_1-of-3 slds-p-around_xxx-small">
<lightning:card footer="{!con.Email}" title="{!con.LastName}" iconName="action:add_contact">
<aura:set attribute="actions">
<lightning:button name="{!con.Id}" variant="brand" label="View Details" onclick="{!c.DoRedirect}"/>
</aura:set>
<p class="slds-p-horizontal_xxx-small">
{!con.FirstName} {!con.LastName} <br/>
{!con.phone}
</p>
</lightning:card>
</div>
</aura:iteration>
</div>
</div>
</aura:component>
Controller Class :
({
doInit : function(component, event, helper) {
/* Step 1 */
var action = component.get('c.getContactList');
/* Step 2 */
action.setParams({
accountId : component.get('v.recordId'),
});
/* Step 4 */
action.setCallback(this, function(response){
var responseValue = response.getReturnValue();
console.log('responseValue', responseValue);
component.set('v.ContactList',responseValue)
}, 'SUCCESS');
/* Step 4 */
$A.enqueueAction(action, true);
},
DoRedirect : function(component, event, helper) {
var eventsource = event.getsource();
var id = eventsource.get('v.name');
var navEvt = $A.get("e.force:navigateToSObject");
navEvt.setParams({
"recordId": "id",
"slideDevName": "detail"
});
navEvt.fire();
},
})
Here c.DoRedirect is working or not, plsease suggest me is there any error in the above code.
Replace this following method with your DoRedirect method
Let me know, if it's helps you marking it solved so that it can help to others.
Thank You