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
Related
I'm trying to figure out how to query a custom object that is related to opportunities.
The object name is McaApp__Offer__c
The lookup field for that object is McaApp__Opportunity__c (master-detail)
This is what I have, but I'mk missing something as this object is not related to accounts, what do I need to change?
SELECT id, Name,
(
Select Id, Name From Opportunities ORDER BY Id DESC LIMIT 1
),
(
SELECT McaApp__Funder__c, McaApp__Status__c FROM McaApp__Offers__r WHERE McaApp__Opportunity__c = 'oppidxxx'
)
FROM Account
WHERE id = 'acctidxxx'
You can't query McaApp__Offer__c from within Account as there is no direct relationship. Account < Opportunity < McaApp__Offer__c this is how it realted.
SOQL statements cannot query aggregate relationships more than 1 level
away from the root entity object.
You can do like this.
SELECT Id, Name, AccountId,
(SELECT McaApp__Funder__c, McaApp__Status__c
FROM McaApp__Offers__r)
FROM Opportunity
WHERE AccountId = 'acctidxxx'
LIMIT 1
I already have contact by using Accountid, so before creating the new contact I want to verify the existing contact with email and id, can you please help me with this salesforce query to check if the Contact already exist with Contact Email and AccountId?
I already tried using the below query but it was throwing exceptions:
SELECT Id, Name , email
FROM Contact
WHERE email='XXX#Email.com'
AND Id IN (SELECT ContactId
FROM AccountContactRelation
WHERE AccountId = 'XXXX')
Got the below error:
INVALID_TYPE: and Id IN (SELECT ContactId FROM AccountContactRelation
WHERE AccountId
^
ERROR at Row:1:Column:121 sObject type 'AccountContactRelation' is not
supported. If you are attempting to use a custom object, be sure to
append the '__c' after the entity name. Please reference your WSDL or
the describe call for the appropriate names.
Can you please share the correct Salesforce Query ?
The below Query worked like charm :)
SELECT Id, Name , email
FROM Contact
WHERE email='XXXXXXXXX#XXX.com'
AND AccountId='YYYYY#yyy.com'
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 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)
Hey Salesforce experts,
I have a question on query account information efficiently. I would like to query accounts based on the updates in an activityHistory object. The problem I'm getting is that all the accounts are being retrieved no matter if there's "complete" activeHistory or not. So, Is there a way I can write this query to retrieve only accounts with activeHistory that has status="complete" and Type_for_reporting='QRC'?
List<Account> AccountsWithActivityHistories = [
SELECT
Id
,Name
,( SELECT
ActivityDate
,ActivityType
,Type_for_Reporting__c
,Description
,CreatedBy.Name
,Status
,WhatId
FROM ActivityHistories
WHERE Status ='complete' and Type_for_Reporting__c = 'QRC'
)
FROM Account
];
You have a WHERE clause on the histories but you still miss one on the Account level.
For example this would return only Accounts that have Contacts:
SELECT Id, Name
FROM Account
WHERE Id IN (SELECT AccountId FROM Contact) // try with NOT IN too
With Activities it's trickier because they don't like to be used in WHERE in that way.
http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql_select.htm
The following objects are not currently supported in subqueries:
ActivityHistory
Attachments
Event
EventAttendee
Note
OpenActivity
Tags (AccountTag, ContactTag, and all other tag objects)
Task
Additionally the fine print at the bottom of ActivityHistory definition is also a bit discouraging.
The following restrictions on users who don’t have “View All Data” permission help prevent performance issues:
In the main clause of the relationship query, you can reference only
one record. For example, you can’t filter on all records where the
account name starts with ‘A’; instead, you must reference a single
account record.
You can’t use WHERE clauses.
You must specify a limit of 499 or fewer on the number of rows returned in the list.
You must sort on ActivityDate in ascending order and LastModifiedDate in descending order; you can display nulls last. For
example: ORDER BY ActivityDate ASC NULLS LAST, LastModifiedDate DESC.
Looks like you will need multiple queries. Go for Task (or Event, depending for which the custom field is visible), compose a set of AccountIds and then query the Accounts?
Or you can manually filter through list from your original query, copying accounts to helper list:
List<Account> finalResults = new List<Account>();
for(Account a : [SELECT...]){
if(!a.ActivityHistories.isEmpty()){
finalResults.add(a);
}
}