You need to sign in to do that
Don't have an account?

How to get Particular field value from Json Response in Salesforce lightning Component
Actually when i selected Template i am getting the Data from apex class in Json Format. But the Problem here is, i want only Subject from the response from Apex class.
The Code is :
getTemplate : function(component, event) {
var tempName= component.get("v.selTempl");
var action = component.get("c.getTemplateDetails");
action.setParams({"templteId":tempName});
action.setCallback(this,function(response){
var responseVal = JSON.stringify(response.getReturnValue());
component.set("v.subjTxt",responseVal.Subject);
console.log('Subject--',subjTxt);
component.set("v.templDetail",responseVal);
});
$A.enqueueAction(action);
},
Actual Output is:
Selected Template Name: Scheduled Letter
Response in JSON Format - [{"Id":"00X2v000001H8xjEAC","Name":"Scheduled Letter","Subject":"Interview Scheduled","TemplateType":"visualforce"}]
Subject -- undefined
But Expected Output--
Subject -- Interview Scheduled
Can anyone pls Suggest the Solution for this....
The Code is :
getTemplate : function(component, event) {
var tempName= component.get("v.selTempl");
var action = component.get("c.getTemplateDetails");
action.setParams({"templteId":tempName});
action.setCallback(this,function(response){
var responseVal = JSON.stringify(response.getReturnValue());
component.set("v.subjTxt",responseVal.Subject);
console.log('Subject--',subjTxt);
component.set("v.templDetail",responseVal);
});
$A.enqueueAction(action);
},
Actual Output is:
Selected Template Name: Scheduled Letter
Response in JSON Format - [{"Id":"00X2v000001H8xjEAC","Name":"Scheduled Letter","Subject":"Interview Scheduled","TemplateType":"visualforce"}]
Subject -- undefined
But Expected Output--
Subject -- Interview Scheduled
Can anyone pls Suggest the Solution for this....
Apex controller returning in list< EmailTemplate> format and here in javascript you are accessing that list without specifying index.Try this one Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
All Answers
use JSON.parse() to convert it into javascript object format if your are serializing while returning from controller and then you can access properties of it.
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
Thank you for u r response,But when i use JSON.parse() the data is not visible in console.log it self.
Thanks!
@AuraEnabled
public static List<EmailTemplate> getTemplateDetails(string templteId){
System.debug('templteId--'+templteId);
List<EmailTemplate> emailTempLst = [SELECT Id,Name,Subject,TemplateType,body FROM EmailTemplate WHERE Name =: templteId];
System.debug('emailTempLst--'+emailTempLst);
return emailTempLst;
}
Apex controller returning in list< EmailTemplate> format and here in javascript you are accessing that list without specifying index.Try this one Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards