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
ekarthikekarthik 

access / get Standard object value with user custom object

 

Hi

  I am in need of access Standrad object  value ( from user object need to  get  small photo url)   using standard object query (user object created )

 

  From the below query

 

    select id, Name ,OwnerID ,CreatedByID, Project__r.Project_Color__c  from Project_Task__c where List__c = 'Holding' AND Project__c = :projectRetainId

 

I need to get Image  by using CreatedByID from user object . how to write query ,

 

I tried this way 

 

    select id, Name ,OwnerID ,CreatedByID, Project__r.Project_Color__c ,( select SmallPhotoUrl from User) from Project_Task__c where List__c = 'Holding' AND Project__c = :projectRetainId

 

 

@anilbathula@@anilbathula@
Hi ekarthik ,

you cant do a inner query for user object.
The best one will be having two soql queries.
1. Project_Task__c pt=[ select id, Name ,OwnerID ,CreatedByID, Project__r.Project_Color__c from Project_Task__c where List__c = 'Holding' AND Project__c = :projectRetainId];
2.user u=[select id,SmallPhotoUrl from user where id=:pt.CreatedByID];

In "U" you can get the smallphotoUrl of the Createdby user of Project_Task__c.
ekarthikekarthik

Hi

   My requirement is to  show project task values and project assigned user image in a repeater 

 

say 

 


<apex:repeat value="{!taskHold}" var="t">


            <div>{!t.name}<br /> 
             <div>{!t.id}<br /> 

 

and i need to display user photo url from project task CreatedByID  

 

         <div>{!t.image}    </div>
         
</apex:repeat>

 

here i need to place the values with in a single repeat control .. Here i am unable to calll two separate action function (Is it any posssibility to call more  than one action function)

Prafull G.Prafull G.

You can use

[select id, Name ,OwnerID ,CreatedByID, CreatedBy.SmallPhotoUrlProject__r.Project_Color__c from Project_Task__c where List__c = 'Holding' AND Project__c = :projectRetainId]

 

Since SmallPhotoURL is a field on User object so you will be able to access it in query as above.

 

Then you can use it on vf page as

<div><apex:image value="{!t.CreatedBy.SmallPhotoUrl}"/></div>

 

Let me know if it helps.

 

-Prafull

ekarthikekarthik
Hi thanks for your reply .

My requirement is also need to get owner.smallphotourl - but unable to get .
I got the following error

No such column 'SmallPhotoUrl' on entity 'Name'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name.


select id, Name ,OwnerID ,CreatedByID, CreatedBy.SmallPhotoUrl, Project__r.Project_Color__c from Project_Task__c where List__c = 'Holding' AND Project__c = :projectRetainId
Prafull G.Prafull G.
I thought you have a custom field on User object which is named as SmallPhotoUrl (API: SmallPhotoUrl__c).

Could you please confirm what is "SmallPhotoUrl" is actually?
ekarthikekarthik


Hi

I thought you have a custom field on User object which is named as SmallPhotoUrl (API: SmallPhotoUrl__c).

Could you please confirm what is "SmallPhotoUrl" is actually?

No . I careated an object to store task details . in that owner field is lookup field object  of owner .

Actually i am storing details about owner manually and neeed to refer that owner image that is , it may fullphotourl or small photourl. I need to display image.

Emilio BEmilio B

I've had similar issues. Same pattern -- trying to access User object through the Owner relationship of a custom object.

 

I looked at the Enterprise WSDL closely and realized the issue.

"OwnerId" is the foreign key field. The name of the relationship is "Owner",

Owner is a relationship to either User **OR** to a Group object. This presents a problem for Force.com, since it never really knows which object the Id is pointing to. Is it a User record or a Group record?

 

 

To solve this, Force.com just points Owner to the generic "SObject" object rather than the specific User object.

As such, it is impossible to say MyCustomObject__c.Owner.SmallPhotoUrl, because Owner is a generic SObject.

 

So you will need to follow the advice given earlier.  Build your own inner query which does NOT use the "Owner" relationship, but rather does a SELECT statement on the User object explicitly WHERE User.Id = YourCustomObject__c.OwnerId  (notice I use "OwnerId" and not "Owner")

 

Emilio