How to get Account.Name when Selecting Tasks in Salesforce SOQL - salesforce

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

Related

Select certain properties (fields) when using BOTH in Orient SQL

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)

Relating Solutions to Accounts in Salesforce

Hi I am new to Salesforce SOQL. I am trying to relate a solution to the accounts but can't get it working. I have created a query but calling from API and executing following query returns me a 'Case' object
SELECT case.account.name
FROM case
WHERE id IN (
SELECT CaseId
FROM CaseSolution
WHERE SolutionId ='XXXXXXX'
)
What about querying the CaseSolution object and then Account Name details from the Case:
SELECT Case.Account.Name FROM CaseSolution WHERE SolutionId = 'XXXXXX' GROUP BY Case.Account.Name

Salesforce SOQL Filter by child relationship

I have the following simple query which shows I can access the field I want to filter by:
SELECT Id, Name, (SELECT HC4__IsSearchableExternally__c FROM Contacts)
FROM Account
However, what I really want to do is return only the Id and Name properties for Accounts that have at least one Contact where HC4__IsSearchableExternally__c is true. Is this possible to do with a Salesforce query?
Basically, I want to do something like the following (nonfunctional query):
SELECT Id, Name
FROM Account
WHERE (SELECT COUNT(Id) FROM Contacts WHERE HC4__IsSearchableExternally__c = true) > 0
Thanks for any help you can provide!
You can do this with a semi-join, e.g:
select id, name from account
where id in (select accountId from contact where HC4__IsSearchableExternally__c = true)

soql select individual CaseComment with all its FeedComments

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

Chatter : SOQL for fetching CommentLikes

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.

Resources