You need to sign in to do that
Don't have an account?
Ridhima Saxena 21
I want to calculate sum of fields dynamically in lwc??
Hii Team,
As I have written one apex method for sum rollup functionality which is working fine when i call from anonymous window.
Apex
sumRecordType() {
console.log("2 sum");
sumRollup({
recordObject: this.selectedObjectValue,
recordField: this.selectedFieldValue,
})
.then((result) => {
console.log("Hello Sum" + result);
this.recordCountTypeValue = result;
})
.catch((error) => {
this.error = error;
});
}
How to resolve it Please help This is LWC question
As I have written one apex method for sum rollup functionality which is working fine when i call from anonymous window.
Apex
@AuraEnabled
public static object sumRollup(String recordObject,String recordField) {
System.debug(recordObject);
Object recordSum;
//String sum = [select sum(annualrevenue) from account];
String sum = 'select' +' '+ 'SUM'+ '('+recordField+')' + ' from ' + recordObject;
AggregateResult[] groupedResults = database.query(sum);
for (AggregateResult ar : groupedResults) {
recordSum=ar.get('expr0');
System.debug('Sum amount -- ' + recordSum);
}
return recordSum;
}
But when i select field from picklist dynamically it is not pritting result only run till console.log("2 sum") You can see this console below.
Here is my JSpublic static object sumRollup(String recordObject,String recordField) {
System.debug(recordObject);
Object recordSum;
//String sum = [select sum(annualrevenue) from account];
String sum = 'select' +' '+ 'SUM'+ '('+recordField+')' + ' from ' + recordObject;
AggregateResult[] groupedResults = database.query(sum);
for (AggregateResult ar : groupedResults) {
recordSum=ar.get('expr0');
System.debug('Sum amount -- ' + recordSum);
}
return recordSum;
}
But when i select field from picklist dynamically it is not pritting result only run till console.log("2 sum") You can see this console below.
sumRecordType() {
console.log("2 sum");
sumRollup({
recordObject: this.selectedObjectValue,
recordField: this.selectedFieldValue,
})
.then((result) => {
console.log("Hello Sum" + result);
this.recordCountTypeValue = result;
})
.catch((error) => {
this.error = error;
});
}
How to resolve it Please help This is LWC question
sumRollup is the auraenabled function, so it has to imported in lwc.
If its not imported, sumRollup cannot be recognized in javascript layer. Check the below code in js file.
in JS file,
import sumRollup from '@salesforce/apex/<Apexclassname>.sumRollup';
If it solves the problem, mark it as resolved.
Thanks