0

The system.debug shows that the id for TempAcct is associated with the correct id after a.get('Franchise__c'), but NewAcct = null. The debug shows that the id was mapped correctly to filterIds, and it's the same id in the aggregateResult.

So why does TempAcct = IdAccount.get((Id)(a.get('Franchise__c'))); work but NewAcct = filterIds.get((Id)(a.get('Franchise__c'))); not work?

Controller:

public with sharing class inspectionsDashboard {

    public inspectionsDashboard() {

        soql = 'SELECT Name,BillingState FROM Account WHERE Id IN : Ids';

        for(AggregateResult a : Result) {
            Ids.add((Id)a.get('Franchise__c'));
        }

        runQuery();

        for(Account a : AcctList) {
            IdAccount.put(a.Id, a);            
        }

        for(AggregateResult a : Result) {
            Account TempAcct = new Account();            
            TempAcct = IdAccount.get((Id)(a.get('Franchise__c')));
            SummaryList.add(new Summary(a, TempAcct.Name, TempAcct.BillingState)); 

        }
    }


    public void runQuery() {

          AcctList = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    }


    public PageReference runSearch() {

        Account NewAcct = new Account();
        filterIds = new Map<Id,Account>();
        soql = 'SELECT Name,BillingState FROM Account WHERE Id In: Ids';

        runQuery();

        for(Account a : AcctList) {
            filterIds.put(a.id, a);            
        }

        for(AggregateResult a : Result) {  

            system.debug('Result is ' +a);
            NewAcct = filterIds.get((Id)(a.get('Franchise__c')));
        }

        return null;
    }
}
  • 1
    can you clean up unnecessary code which is not relevant to your question – Santanu Boral Aug 9 '18 at 14:01
  • Yes I believe the above is necessary. – Sebastian Aug 9 '18 at 14:08
  • Your query contains a limit 20 clause. There's a possibility that your query does not return Accounts whose Ids are in filterIds for that reason. – David Reed Aug 9 '18 at 14:08
  • I changed the limit to 120 and the result was the same – Sebastian Aug 9 '18 at 14:09
  • I would push you, like Santanu, to cut this down to a minimum reproduction. It's a lot of code to wade through and your description is not entirely clear. – David Reed Aug 9 '18 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.