2

The visualforce which we are working now shows the list of opportunities based on the account Id in the query string parameter. So we are using the standard set controller for the list view filtering, but list view filter results are not showing the results based on the account id in the query string parameter? Is it possible to write a soql query based on the list view filter id in where condition along with the account id?

1 Answer 1

2

Tricky. You could pull out all IDs from the listview (up to 10K) and then use them in your own query filtered by Account Id. Not sure if there's a better way, Listviews have IsSoqlCompatible field but I don't think there's a way to generate SOQL out of them? Not unless you want some Metadata API hackery of trying to compose the SOQL based on listview's definition...

So - watch out. Maybe the end result will be enough for your users but it won't be "real". If 50K records meet the listview's criteria - you're limiting yourself to 10K right away and then filtering that even further.

StandardSetController ssc; // skipping the initialisation of this variable
// ...
Set<Id> allIds = new Set<Id>();
ssc.first();
ssc.setPageSize(1000);
while(hasNext){
    allIds.addAll(new Map<Id, sObject>(ssc.getRecords()).keySet());
    hasNext = ssc.getHasNext();
    ssc.next();
}

List<Opportunity> opps = [SELECT Id
    FROM Opportunity
    WHERE Id IN :allIds AND AccountId = :accId];

All in all - I don't think it's a good idea. If you have > 10K opps that meet the listview's criteria you probably will hide data. Think about using Report REST API instead? You could have a report (so still something that Administrator can configure as easily as a listview) and pass some parameters to it in runtime... But that's 2K rows max as opposed to 10K from StandardSetController. And it'll be a callout, to same SF org but still.

You must log in to answer this question.

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