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

Convert a STRING Select statement output to JSON format APEX class
Hi,
Can anyone please help me convert the below to JSON:
@AuraEnabled
public static List<Energy_Plan__c> getRatePlans(
String brand,
String priceBook,
String commodity,
String utility,
Boolean showPoints
) {
System.debug('Inside getRatePlans');
List<Energy_Plan__c> String query =
'SELECT Id, Name, TermInMonths__c, REP_Per_Usage_Charge1__c, MonthlyFee__c, jurisdiction__c, ProductName__c, ' +
'EFL_ENGLISH_LINK__c, EFL_SPANISH_LINK__c, PenaltyAmount__c, PlanType__c, Price_Units__c, Rateplan_Points__c, ' +
'Monthly_Fee_Total__c, ReportGroupID__c, Commodity__c, Brand__c, EnergyProvide__c,Active__c, UtilityName__c, Total_Fee__c, REPKey1__c, ExternalId__c, ' +
'TOSLINKSTATIC_English__c, TOSLINKSTATIC_Spanish__c,External_Plan_Key__c ' +
'FROM Energy_Plan__c ' +
'WHERE ' +
'Active__c = true ' +
'AND IsCustomPriced__c = False ' +
'AND Brand__c = :brand ' +
'AND RateName__c = :priceBook ' +
'AND Commodity__c = :commodity ' +
'AND UtilityName__c = :utility ';
if (showPoints) {
query += 'ORDER BY Rateplan_Points__c DESC';
} else {
query += 'ORDER BY Name';
}
System.debug('getRatePlans >> ' + Database.query(query));
return Database.query(query);
Can anyone please help me convert the below to JSON:
@AuraEnabled
public static List<Energy_Plan__c> getRatePlans(
String brand,
String priceBook,
String commodity,
String utility,
Boolean showPoints
) {
System.debug('Inside getRatePlans');
List<Energy_Plan__c> String query =
'SELECT Id, Name, TermInMonths__c, REP_Per_Usage_Charge1__c, MonthlyFee__c, jurisdiction__c, ProductName__c, ' +
'EFL_ENGLISH_LINK__c, EFL_SPANISH_LINK__c, PenaltyAmount__c, PlanType__c, Price_Units__c, Rateplan_Points__c, ' +
'Monthly_Fee_Total__c, ReportGroupID__c, Commodity__c, Brand__c, EnergyProvide__c,Active__c, UtilityName__c, Total_Fee__c, REPKey1__c, ExternalId__c, ' +
'TOSLINKSTATIC_English__c, TOSLINKSTATIC_Spanish__c,External_Plan_Key__c ' +
'FROM Energy_Plan__c ' +
'WHERE ' +
'Active__c = true ' +
'AND IsCustomPriced__c = False ' +
'AND Brand__c = :brand ' +
'AND RateName__c = :priceBook ' +
'AND Commodity__c = :commodity ' +
'AND UtilityName__c = :utility ';
if (showPoints) {
query += 'ORDER BY Rateplan_Points__c DESC';
} else {
query += 'ORDER BY Name';
}
System.debug('getRatePlans >> ' + Database.query(query));
return Database.query(query);
You can try anyone of the below way:
List<Energy_Plan__c> engList = Database.query(query);
1. use JSON.serialize(engList );
===== or =====
2. Create a wrapper class to build your wrapper. Loop the query list then populate and serialize the wrapper.
Ex: for populate the wrapper from records : https://developer.salesforce.com/forums/?id=9062I000000g9UYQAY
Thanks,
Maharajan.C