I have requirement to fetch comment likes. I'm not able to figure out on how to retrieve commentlikes.
FeedLike object represents likes. You can't query FeedLike records directly. They can only be queried via the parent NewsFeed, UserProfileFeed, or entity feed, such as AccountFeed.
So to query FeedPost likes, use following:
SELECT Id, (SELECT Id, CreatedById, CreatedDate, FeedItemId, FeedEntityId FROM FeedLikes) FROM UserFeed
to query group post likes, use following:
SELECT Id, (SELECT Id, CreatedById, CreatedDate, FeedItemId, FeedEntityId FROM FeedLikes) FROM CollaborationGroupFeed
How to retrieve comment likes?
They are available through the Chatter REST API: http://wiki.developerforce.com/page/Chatter_API
I think you want to ChatterActivity SObject
Select c.ParentId, c.LikeReceivedCount, c.Id, c.CommentReceivedCount From ChatterActivity c
This should get what you are looking for.
EDIT:
Strange, I don't seem to be able to find anything on doing this in apex, you can do it through the api by calling
/chatter/comments/commentId/likes
So it should be possible somewhere along the line.This could work as a workaround though.
Related
I'm trying to create a SOQL query that pulls records from an Object based on if there are any results from another linked object. Here is sort of what I am trying to do.
SELECT id, casenumber FROM case WHERE count(SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = case.id) > 0
This returns the error,
MALFORMED_QUERY:
casenumber FROM case WHERE count(SELECT ContentDocumentId FROM ContentDocumentLink
^
ERROR at Row:1:Column:44
unexpected token: 'SELECT'
After a few attempts at trying to make this work I am not sure what else try. I know SOQL has some limitations but I am unsure if this is one of them. Anyone have insight? Thanks.
It's "down, then up", via many to many relationship. 1 document could be linked to many Cases but wasting storage space just once.
Normally you'd try something like this
SELECT Id, CaseNumber, Subject
FROM Case
WHERE Id IN (SELECT LinkedEntityId FROM ContentDocumentLink)
But it won't compile, there are some limitations. Experiment, worst case query all cases and use apex to inspect the related list?
SELECT Id, CaseNumber, Subject, (SELECT ContentDocumentId FROM ContentDocumentLinks LIMIT 1)
FROM Case
Case is funny. Attachments linked to emails (if you have Email-to-Case) will show on related list of Files but they won't be physically there. The full link will be Content Document -> ContentDocumentLink -> EmailMessage -> Case. Argh. CombinedAttachment is supposed to help with it, special readonly related list / view / whatever.
One more idea using polymorphic soql, bit bass-ackwards but give it a go:
SELECT ContentDocumentId, TYPEOF LinkedEntity WHEN Case THEN Id, Subject, CaseNumber END
FROM ContentDocumentLink
WHERE LinkedEntityId IN (SELECT Id FROM Case)
Using OrientDB 2.* with OrientSQL.
I have a simple graph with Class Users that has a number of properties (username, country, pets, etc). Each user also has outgoing friends edge. I want to select only the username and country from all users who are friends with a specific user.
My query so far:
SELECT EXPAND( BOTH('friends') ) FROM users WHERE #rid = #12:0
returns the full user objects for those who are friends of #12:0
I want only to return the username and country of those friends.
Am I missing something simple? Much appreciated!
You can:
select expand(both('friends').include('username', 'country'))
from #12:0
Note that you should:
select from #12:0
instead of:
select from Users where #rid = #12:0
A sub-query would work. I don't think there is any other way to do this.
Try this :
select
username, country
from (select
expand( both('friends') )
from
#12:0)
I am dealing with an SOQL query in Salesforce like
SELECT Id, Subject, Who.Name FROM Task
I need to know the Who.Account.Name in the same Query
How should I do that?
It was easy
SELECT Id, Task.Account.Name, Subject, Who.Name FROM Task
edit: SELECT Contact.Account.Name FROM Contact
general info:
http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_relationships.htm
I am trying to select all comments ,feeds and feedcomments for an individual case.
The hierarchy is like
Case
|
CaseComment
|
FeedComments(commnets or feeds under a CaseComment)
I could not find any relation between CaseComments and FeedComments nor CaseComments and CaseFeeds.
How can I select all together in a soql or individual soqls which relates Case, CaseComment,CaseFeed,FeedComment?
EDIT
The query you've included in the comment looks good. I'd write it as something like that:
SELECT Id, Body, ParentId, Parent.CaseNumber, CreatedDate,
(SELECT Id, CommentBody, CommentType FROM FeedComments)
FROM CaseFeed
ORDER BY Parent.CaseNumber, CreatedDate
(this is sample output rendered in Real Force Explorer, a pretty neat tool)
If I'll click into the "2 records" bit I can drill down to the fields selected from FeedComment for "this" CaseFeed:
If your query renders differently for you (some stuff is blank) - maybe try this different editor or even go to https://workbench.developerforce.com
If only some comments contain text - they might be uploaded images for example - filter them by CommentType = 'TextComment'?
ORIGINAL
FeedComments(commnets or feeds under a CaseComment)
No, not really. FeedComment is a Chatter table that can link to many objects but CaseComment is not one of them.
Maybe study the Chatter Entity Relationship Diagram?
Anyway - relationship to feed* objects doesn't have a nice name exposed so we can't query it all in one go:
I think you'll need something like this:
SELECT Id, CaseNumber,
(SELECT Id, CommentBody FROM CaseComments),
(SELECT Id, Body FROM Feeds)
FROM Case
SELECT Id, FeedItemId, ParentId, CommentBody
FROM FeedComment
WHERE ParentId = :caseIdHere
I want to get the field userhomepage from the custom table WebsiteUser via a SOQL query on the Account table. I tried about 10 different queries but i'm not getting it working...
fe. I've tried SELECT field1, (SELECT userhomepage FROM User) FROM Account with all the __c and __r combinations.
I've got the following structure:
<complexType name="Account">
<complexContent>
<extension base="ens:sObject">
<sequence>
...
<element name="WebsiteUser__c" nillable="true" minOccurs="0" type="tns:ID"/>
<element name="WebsiteUser__r" nillable="true" minOccurs="0" type="ens:WebsiteUser"/>
And the WebsiteUser table has a string field called userhomepage.
How do I put that in a query? i'm completely stuck, thnx in advance!
Maybe a child-to-parent style query will work.
Try this?
SELECT Account__r.field1, userhomepage FROM WebsiteUser__c
Relevant-looking documentation:
http://www.salesforce.com/us/developer/docs/api/index_Left.htm#StartTopic=Content/sforce_api_calls_soql.htm
I'm assuming that WebsiteUser__c has a lookup to Account which is what I believe the snippet you've posted is showing, however that doesn't look like the standard object XML so I'm not 100% on where it's coming from.
A lookup from WebsiteUser__c to account creates a Many Website User to One Account relationship. If you were selecting from the Website User table you'd do something like:
select Id, UserHomePage__c, Account__r.Name
from WebsiteUser__c where some conditional
Querying the other way around requires a subquery:
select Id, Name, (select Id, UserHomePage__c from WebsiteUser__r)
from Account
This will return an Account with a list of all WebsiteUser__c records which are associated with it, you could run through the results like so:
for(Account sAcct : select Id, Name,
(select Id, UserHomePage__c from WebsiteUser__r)
from Account limit 200)
{
for(WebsiteUser__c sUser : sAcct.WebsiteUser__r)
{
System.Debug(sUser.UserHomePage__c);
// etc.
Some things to watch out for are that WebsiteUser__r might be a plural, i.e. WebsiteUsers__r, and if you've tried all combinations and it's not working, check that you didn't put in __c or __r yourself into the API object name, the system does this automatically so you'd end up with fields ending in __c__c or __r__r.
If you say what information you have to base the query on I might be able to make this answer a little bit more specific for you!
SELECT id, (SELECT UserHomePage__c FROM WebsiteUser__r) FROM ACCOUNT
if websiteUser__r is the child relation
SELECT id, WebsiteUser__r.UserHomePage__c FROM ACCOUNT
if websiteUser__r is the parent relation
it seems like a parent relationship to me so I think the later query would work...
Hope that helps