I am a bit new to salesforce, so kindly help.
I have different recordsIDS like from contacts, opportunities,leads and other sections, I need to use SQL Query and return the Name and Email.
My code follows as this, kindly help how to create a custom list and return based on ID.
I am getting errors such as unexpected Name and email,so how to create a custom SOQL query or which can work here.
@AuraEnabled
public static List <Contact> getAccountDetails(String recordId){
// List<Contact> results = [SELECT Name, Email
//FROM Contact
If (recordId.startsWith('003')){
return [SELECT Name, Email FROM Contact WHERE id = :recordId];
}
If (recordId.startsWith('00Q')){
return [SELECT Name, Email FROM Lead WHERE id = :recordId];
}
If (recordID.startsWith('006')){
return [SELECT 'Name', 'Email' FROM 'OpportunityContactRole' WHERE 'OpportunityId'= :recordId];
}
If (recordID.startsWith('0Q0'){
return [SELECT Name, Email FROM Quote WHERE id = :recordId];
}
If (recordID.startsWith('001')){
return [SELECT Name, Email FROM Contact WHERE id = :recordId];
}
If (recordID.startsWith('003'))
return [SELECT Name, Email FROM Contact WHERE id = :recordId];
}
}
Adding controller code as well for reference
getCurrentPageDetails : function(component, event, helper) {
var action = component.get("c.getAccountDetails");
console.log(action,"action")
action.setParams({
'recordId' : component.get("v.recordId")
});
action.setCallback(this, function(response){
debugger
var status = response.getState();
if(status === "SUCCESS"){
component.set("v.name",response.getReturnValue()[0].Name )
component.set("v.email",response.getReturnValue()[0].Email)
}
});
$A.enqueueAction(action);
},