function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gwestongweston 

help iterating through soql result

I am trying to iterate through the result of a soql result and I am getting a number of errors.

 

 public ApexPages.StandardSetController accountRecords{
        get {
            if(accountRecords ==null){
                return new ApexPages.StandardSetController(
                         Database.getQueryLocator(
          [SELECT name FROM Service_Region__C WHERE Service_Region__c.Advisor_Account__c NOT IN 
                (SELECT AccountId FROM Opportunity 
                 WHERE IsClosed =false)] ));
            }
            return accountRecords;
            
   Iterator<sObject> accountsIterator = accountRecords.getRecords().iterator();
      while ( accountsIterator.hasNext() ){
        sObject recordEach =  accountsIterator.next();
        recordEach.put('GEOPointe', geopointe.API(id1, accountRecords.Id, geopointe.API.units.MILES));
      }
          
        }   

        
        private set;
    }

 

 

 One error is "Save error: Non-void method might not return a value or might have statement after a return statement."

 

and the second one is related to the geopointe.API :

: Method does not exist or incorrect signature: geopointe.API(Id, Id, geopointe.API.units)

 

Any help would be appreciated.

Ankit AroraAnkit Arora

Write "return null" in the end of method in which you are facing the the "Save error: Non-void method might not return a value or might have statement after a return statement." issue and let me know the code from where you are getting this geopointe :

 

"recordEach.put('GEOPointe', geopointe.API(id1, accountRecords.Id, geopointe.API.units.MILES));"

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Shashikant SharmaShashikant Sharma

Non-void method might not return a value or might have statement after a return statement : This error comes when all part of your method which has a return type does not return some value. In your case your getter does return accountRecords but it has a statement after it as well which means this is an unreachable code. 

 

Method does not exist or incorrect signature : Compiler not able to find any such method in this class or any class which this calss is extenteding. 

 

 

Shashikant SharmaShashikant Sharma

@ankit last night I went to bed cross posting , in morning again the same , I think we should set timings ,like in movies Dons have an area :)

Ankit AroraAnkit Arora

Haha!! Good Idea, we should think over this.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

gwestongweston

Thank you for the quick reply. I am actually further along and got the class to save without errors.

 

"recordEach.put('GEOPointe', geopointe.API(id1, accountRecords.Id, geopointe.API.units.MILES));" was wrong it should have been geopointe.API.getDistance

 

I don't know if it works yet because I can't test it. Because I can not figure out to display temporary field GEOPointe.

 

Here is the updated code

 

public with sharing class AccountPagination {
 private final Service_Region__c acct;
 
 public AccountPagination(ApexPages.StandardSetController controller) {
  this.acct = (Service_Region__c)controller.getRecord();
 }
 
 ID id1 = '00QM0000001feFN';
 ID id2 = '00QM0000001fek';
 public ApexPages.StandardSetController accountRecords {
    get {
      if(accountRecords ==null){
        return new ApexPages.StandardSetController(Database.getQueryLocator( [SELECT name FROM Service_Region__C WHERE Service_Region__c.Advisor_Account__c NOT IN (SELECT AccountId FROM Opportunity WHERE IsClosed =false)] ));
      }


     
Iterator<sObject> accountsIterator = accountRecords.getRecords().iterator();
      while ( accountsIterator.hasNext() ){
        sObject recordEach =  accountsIterator.next();
        recordEach.put('GEOPointe', geopointe.API.getDistance(id1,id2, geopointe.API.units.MILES));
      }


      return accountRecords;
    }


    private set;
  }
  
  public List<Service_Region__c> getAccountPagination(){
    return (List<Service_Region__c>) accountRecords.getRecords();
  }
}

 

 

and here is the page 

 

<

<apex:page standardController="Service_Region__c" recordSetvar="Service_Region__c"
extensions="AccountPagination">
<apex:pageBlock title="Viewing Accounts">
<apex:form id="theForm">
<apex:pageBlockSection >
<apex:dataList var="a" value="{!accountPagination}" type="1">
{!a.name}

{!a[GEOPointe]}

</apex:dataList>
</apex:pageBlockSection>
<apex:panelGrid columns="2">
<apex:commandLink action="{!previous}">
Previous

</apex:commandlink>
<apex:commandLink action="{!next}">
Next

</apex:commandlink>
</apex:panelGrid>
</apex:form>
</apex:pageBlock>
</apex:page>

 

 

Hpandey_ForceLabsHpandey_ForceLabs

I had the same issue, the error showed up was

 

 

Compile Error: Non-void method might not return a value or might have statement after a return statement. at line

 

My method was

 

private PageReference returnToPage(Account cloned)

 

 

Easy fix,  - if not then   'return null' that's it