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
EzmoEzmo 

Query Owner Id using Current User Id

Hi there, I'm quite new to coding and to apex so please bare with me. :smileywink:

 

I am trying to create an soql query which I essentially want to work like this:

 

SELECT Id FROM Log_Book__c WHERE Owner Id = Current User Id 

 

Does anyone know how I can achieve this?

 

Thank you for your time.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
PatcsPatcs

Try this

 

SELECT Id FROM Log_Book__c WHERE OwnerId =:UserInfo.getUserId();

 

Patcs

All Answers

PatcsPatcs

Try this

 

SELECT Id FROM Log_Book__c WHERE OwnerId =:UserInfo.getUserId();

 

Patcs

This was selected as the best answer
EzmoEzmo

That worked :smileyhappy:

 

just had to change OwnerId to Owner.Id

 

Thank you very much!!

 

Now I just need to figure out how to implement it where I want it.

 

What I'm trying to do is as follows

 

public List<Log_Book__c> getlogbook(){
        logbook = [SELECT Id FROM Log_Book__c WHERE Owner.Id = :UserInfo.getUserId()];
        return logbook;
}

 

public void addObjective(){

        objective.add(new Objective__c(Log_Book__c =  logbook));

}

 

 

but I get the following

Error: Compile Error: Invalid initial expression type for field Objective__c.Log_Book__c, expecting: Id at line 19 column 54

 

 

sfdcfoxsfdcfox

Use logbook.Id instead of logbook.