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
It just me!It just me! 

Unexpected Token 'FROM'

Hi! Im trying resolve a search issue in opportunity to search records for a particular object custom object.  When I press the search I get this error.
User-added image

I looked at the APEX code and it looks fine using the FROM syntax.  
 
public void searchSpace2() {
        try {
            String spacesSearchQueryString = 'select Id, Name, Term_Months__c, Used__c, from Space2__c where RecordTypeId = :SpaceRecordType and {{condition}}';
            String spacesSearchCountQueryString = 'select count() from Space2__c where RecordTypeId = :SpaceRecordType and {{condition}}';
            String spacesSearchQueryConditionString = '';
            
            mapHoldingSelectedRecords.clear();
            
            if(spa.Term_Months__c != null) {
                spacesSearchQueryConditionString += 'Term_Months__c = ' + '\'' + spa.Term_Months__c + '\'' + ' and ';    
            }
            
            if(spa.Used__c != null) {
                spacesSearchQueryConditionString += 'Used__c = ' + '\'' + spa.Used__c + '\'' + ' and ';    
            }
            
            if(String.isBlank(spacesSearchQueryConditionString)) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select the suitable filters to search for pSpaces.'));
                return;
            }
            
            spacesSearchQueryConditionString = spacesSearchQueryConditionString.removeEnd(' and ');
            spacesSearchQueryConditionString = spacesSearchQueryConditionString.trim();
            
            spacesSearchQueryString = spacesSearchQueryString.replace('{{condition}}', spacesSearchQueryConditionString + ' order by Name ASC limit ' + QUERY_LIMIT);
            spacesSearchCountQueryString = spacesSearchCountQueryString.replace('{{condition}}', spacesSearchQueryConditionString);
            
            System.debug('------------------- spacesSearchQueryString: ' + spacesSearchQueryString);
            
            setController = new ApexPages.StandardSetController(Database.getQueryLocator(spacesSearchQueryString));
            setController.setPageSize(PAGE_SIZE);
            noOfRecords = Database.countQuery(spacesSearchCountQueryString);
            totalPages = getTotalPages();
            
            populateWrapperList();
            
        } catch(Exception e) {
            System.debug('------------------- ERROR: ' + e.getStackTraceString());
            System.debug('------------------- ERROR MESSAGE: ' + e.getMessage());
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error while searching for pSpaces.' + e.getMessage()));
            return;
        }
    }

The recordType is "Space".  Thanks in advance.


 
Best Answer chosen by It just me!
Nayana KNayana K
String spacesSearchQueryString = 'select Id, Name, Term_Months__c, Used__c, from Space2__c where RecordTypeId = :SpaceRecordType and {{condition}}';

should be
try {
            String spacesSearchQueryString = 'select Id, Name, Term_Months__c, Used__c from Space2__c where RecordTypeId = :SpaceRecordType and {{condition}}';

There was a comma after Used__c before from (Used__c,) ​

All Answers

Nayana KNayana K
String spacesSearchQueryString = 'select Id, Name, Term_Months__c, Used__c, from Space2__c where RecordTypeId = :SpaceRecordType and {{condition}}';

should be
try {
            String spacesSearchQueryString = 'select Id, Name, Term_Months__c, Used__c from Space2__c where RecordTypeId = :SpaceRecordType and {{condition}}';

There was a comma after Used__c before from (Used__c,) ​
This was selected as the best answer
It just me!It just me!
Thanks Nayana.  I redid the class, added things 1 by 1 and saw that.  Truly appreciate it.