+ Start a Discussion
Jonathan Osgood 3Jonathan Osgood 3 

Error: Invalid bind expression type of Object for column of type Id

Hi All,

Can't seem to get my WHERE clause correct. Getting Invalid bind expression type of Object for column of type Id error. Here is the full class:
 
public class SubmitPublicationController {
    @AuraEnabled
    public static sObject getObjectById(ID anId) {
        
        system.debug('Entering controller');
        // Get the sObject token from the first ID
        Schema.SObjectType token = anId.getSObjectType();
        
        // Using the token, do a describe 
        // and construct a query dynamically. 
        Schema.DescribeSObjectResult dr = token.getDescribe();
        String queryString = 'SELECT Id, Name, Publication__c, Next_Object__r.Id, Previous_Object__r.Id FROM ' + dr.getName() + 
            ' WHERE Id = :anId Limit 1 ';
        
        system.debug('describe object result' + dr.getName());
        
        sObject objDBResult = Database.query(queryString);
       
      	List <Publication__c> pubsList = [SELECT ID, Publication_Submitted__c
                          	   FROM Publication__c
                               WHERE ID = :objDBResult.get('Publication__c')
                                         ];
        
        pubsList[0].Publication_Submitted__c = true;
        
        system.debug('pub ID='+pubsList);
    
        upsert pubsList;
        
        System.debug('ID is: ' + anId);  
        System.debug('objDBResult: ' + objDBResult); 
        
        return objDBResult;
       
    }
    
    

}

 
Best Answer chosen by Jonathan Osgood 3
UC InnovationUC Innovation
You might need to cast the results of your query since it is an sObject. Try replacing your current where clause with this:
 
WHERE Id = :(Id)objDBResult.get('Publication__c')

Hope this helps!

AM

All Answers

UC InnovationUC Innovation
You might need to cast the results of your query since it is an sObject. Try replacing your current where clause with this:
 
WHERE Id = :(Id)objDBResult.get('Publication__c')

Hope this helps!

AM
This was selected as the best answer
Jonathan Osgood 3Jonathan Osgood 3
That did it! Thanks!