0

Below is my controller extention code. i am getting null value for acct.Owner field. Dnt know what i am doing wrong here.

And how can i filter record value like, return only that record 'where createdById =userid'

public class myControllerExtension {



    private final Event_Request__c acct;
    public myControllerExtension(ApexPages.StandardSetController controller) {

                acct = (Event_Request__c)controller.getRecord();
    }


    public String getEvent() {
            return ''+acct.Owner ; }
}

1 Answer 1

0

The field Owner is a reference to a User object; the field OwnerId is the ID of a User that perhaps you could use for filtering (though you would probably need to use addFields too to get the StandardController to query the field).

But if you want to query some SObjects owned by the currently active user you just need a query of this form:

select ... from ... where OwnerId = :UserInfo.getUserId()

See UserInfo.getUserId.

PS

An example of addFields:

public myControllerExtension(ApexPages.StandardController sc) {
    if (!Test.isRunningTest()) {
        sc.addFields(new String[] {String.valueOf(Account.OwnerId)});
    }
    ...

This is using the field token so there is a compile-time check but you can also use a string for the API name of the field i.e. 'OwnerId' instead of String.valueOf(Account.OwnerId).

2
  • can you write an example of addFields to get the Stdcontroller to query the field? Feb 11, 2016 at 17:57
  • @puravthakkar Added as a PS.
    – Keith C
    Feb 11, 2016 at 18:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .