+ Start a Discussion
priyanshipriyanshi 

how to display the owner standard field

i have this custom controller and when i try to retrieve the owner field it shows an error.

 

public class postscontroller {

public list<post__c> getMyposts() {

return [select name,owner,id,subject__c,posted_on__c,category__c from post__c];
}

}

 

can anyone help me know why i am getting an error?

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below query as reference:

 

[select id,subject__c,posted_on__c,category__c,owner.name from post__c]

 

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

 

All Answers

Shailesh DeshpandeShailesh Deshpande

Its OwnerId and not Owner.

priyanshipriyanshi

thanks

but then how can i display the owner name? because owner id field will display the id and not name...

SRKSRK

if u use <apex:inputfield vlaue="{!obj.ownerid}"/> it automatically bring the name

or u can fetch the like [select ownerid.name in selesct querty & assing in a stirng property & can use on VF page

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below query as reference:

 

[select id,subject__c,posted_on__c,category__c,owner.name from post__c]

 

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

 

This was selected as the best answer
priyanshipriyanshi

thanks :)