0

We have created a custom object where we store our Product Pricing. We want our users to change the prices of our products (through in-line editing) in list views. However for our users to make a good decision on a price increase we need to show the average price of all the records in each List View.

Is it possible to calculate this in a controller? I've already created the view but I can't find anywhere how I can fetch records depicted in a list view to do any calculations on.

Because we have 100+ List views (and we need this view to be flexible) I don't want to hard code any queries in the controller outside the List View dropdown.

Hope anyone can help!

enter image description here

1 Answer 1

2

On a standard list view page, you cannot add some custom field like that on the top(like you showed).As an alternative I have created a custom list view button which calculates the average on basis of records selected in the list view.Below is the javascript code:

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} 
var checked = {!GETRECORDIDS($ObjectType.Account)}; 
var q = "Select id,NumberofLocations__c From Account Where Id In " + "('" + checked.toString().replace(/,/g, "','") + "')";
var result = sforce.connection.query(q); 
var records = result.getArray("records"); 

var average=0,sum=0;

for (var i=0; i < records.length; i++) { 
var record = records[i];
sum=+sum + +(record.NumberofLocations__c);

}

average = sum/(records.length);
alert("average of selected records is "+average);

Using GETRECORIDS, i got the id of selected records,i queried on basis of those Ids,then i added up the values of a specific field and caculated their average.Finally i showed them as a popup on my page.This button has to be added to your list view FYI

1
  • Glad to know.Request you to upvote it so that others can also benefit from this :)
    – Abhijeet
    Commented Aug 8, 2016 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .