I need help to make a soql to get the images from ContentVersion based on caseId
We have 3 objects:
ContentDocument
ContentVersion
ContentDocumentlink
ContentDocument is parent of ContentVersion and ContentDocumentLink
ContentVersion has versiondata(that is binary data)
ContentDocumentLink having case id(Fieldname is LinkedEntityId)
I need to create a SOQL that provides version data of ContentVersion based on linkedentityID ( case- ID) when I use this query
select versiondata from contentversion where contentdocumentid in(select contentdocumentid from contentdocumentlink where linkedentityid in(select id from case))
Than it is giving the error like
Entity 'contentdocumentlink' is not supported for semi join inner selects
It is giving error like semi join is not supported.
This works with any id (any object that you marked as allow attachments)
SELECT ContentDocument.LatestPublishedVersion.VersionData
FROM ContentDocumentLink
WHERE LinkedEntityId = '...'
Or top-down (useful if you need multiple records and their files)
SELECT Id, CaseNumber, Subject,
(SELECT ContentDocument.LatestPublishedVersion.VersionData FROM ContentDocumentLinks)
FROM Case
WHERE Id = '...'
Related
I need a query between Opportunity and OpportunityLineItem.
OpportunityLineItem has a lookup for Opportunity. Child relationship name is OpportunityLineItems. Opportunity Lookup field is called OpportunityId.
I'm trying the below query but it doesn't work.
select Id,Name,OpportunityId__r.Description from OpportunityLineItem
Also tried:
select Id,Name,OpportunityLineItems__r.Description from OpportunityLineItem
Top-down
SELECT Id, Name, Description,
(SELECT Id, Name FROM OpportunityLineItems)
FROM Opportunity
Bottom-up
SELECT Id, Name, Opportunity.Name, Opportunity.Description
FROM OpportunityLineItem
Check out the links in https://stackoverflow.com/a/73913839/313628 and https://stackoverflow.com/a/73877986/313628 too
I am trying to do a simple join between the user object and profile object. They are connected by ID
User = profileID
Profile = ID
This would be a simple query in SQL:
select u.name, u.profileID, p.name, p.ID
from Users
Join Profile
ON u.profileID = p.ID
I've tried the following and all I get are errors:
Select User.name, (SELECT profile.name, profileID from Profile) from User
select name, profileID, userRoleId from User WHERE ProfileId IN (select name from Profile)
SELECT User.name, user.profileId (SELECT profile.name FROM Profile)
FROM User
Where User.ProfileId IN ( Select Profile.ID from Profile)
for following FK relationships, you use the compound name as the field to query, e.g.
select name, profile.name from user
See the SOQL relationships docs for more details.
I have written a very simple SOQL query in Salesforce but it doesn't work.
SELECT Id, UserId, TerritoryId, IsActive
FROM UserTerritory
WHERE UserId NOT IN (SELECT UserId
FROM UserTerritory
GROUP BY UserId
HAVING COUNT(UserId) > 1)
The query above is throwing the following exception:
In Developer Console, it shows "Unknown error parsing query"
In Workbench, it shows:
MALFORMED_QUERY: (SELECT UserId FROM UserTerritory GROUP BY
UserId HAVING count(UserId) ^ ERROR at Row:1:Column:114 expecting a
right parentheses, found 'GROUP'
Such query doesn't make sense anyway.
Let's say that you have simplified the original SOQL as follows:
SELECT Id, UserId, TerritoryId, IsActive
FROM UserTerritory
WHERE UserId NOT IN (SELECT UserId FROM UserTerritory)
Salesforce won't let you do so and the exception will be thrown:
The inner and outer selects should not be on the same object type
If more thorough analysis is expected, additional details on the topic are needed (ideally, data examples).
trying to join lead table with opportunity table in force.com explorer. New to soql. Here is what I have tried with error messages as results... can anyone help please?
SELECT CreatedDate, LeadSource, RecordTypeId, Name__c, StageName, HubSpot_Original_Source_Data_1__c, Name, HubSpot_Original_Source_Data_2__c, HubSpot_Original_Source_Type__c, (SELECT Company, IsConverted, CreatedDate, HubSpot_Inc__HubSpot_Intelligence__c, HubSpot_Original_Source_Data_1__c, HubSpot_Original_Source_Data_2__c, HubSpot_Original_Source_Type__c, LeadSource, RecordTypeId FROM Lead) FROM Opportunity where Name in (select Company from Lead)
Where clause of your query will not work. You can use another query in where clause only for checking matching Id.
SELECT CreatedDate, LeadSource, RecordTypeId, Name__c, StageName, HubSpot_Original_Source_Data_1__c, Name, HubSpot_Original_Source_Data_2__c, HubSpot_Original_Source_Type__c, (SELECT Company, IsConverted, CreatedDate, HubSpot_Inc__HubSpot_Intelligence__c, HubSpot_Original_Source_Data_1__c, HubSpot_Original_Source_Data_2__c, HubSpot_Original_Source_Type__c, LeadSource, RecordTypeId FROM Lead) FROM Opportunity where name = 'test'
I'm trying to write a SOQL query to retrieve some Salesforce Content records and am having a bit of difficulty figuring out my next step. I want to exclude all versions of a document if a custom field of any version of that document has a value (is not null). Here's slimmed down version of what I am trying to do:
Select Id, Title
From ContentVersion
Where ContentDocumentId Not In
(
Select ContentDocumentId,
From ContentVersion
Where Custom_Field__c != null
)
So I know that you can't write a subquery that targets the same object as its outer query, so obviously what I've specified above won't work. Any suggestions on what will work?
Thank you.
Can You try something like this:
Select C.Id from ContentDocument C where
ID not in ( Select ContentDocumentId
From ContentVersion
where Custom_Field__c != null)