How to get Notes & Attachments Record using SOQL - salesforce

I am not found Notes & Attachments Record in Custom Object
select Id, Name,(SELECT Id, Name FROM Attachments),(SELECT Id, Title FROM Notes) from Student__c

Related

How to retrieve 2 object fields from Salesforce using SOQL

I'm trying to retrieve 2 object fields using Salesforce queries SOQL
Product
Product2
PricebookEntry
Both these objects have product Code = "CUCR05RC002"
I want to combine these 2 queries
Product2
SELECT id
FROM product2
WHERE productcode = "CUCR05RC002"
PricebookEntry
SELECT id
FROM pricebookentry
WHERE productcode = "CUCR05RC002"
Here is Product Page inside of it we have Price Book
This is Price Book page have same Product Code as Product
Thanks
"bottom up" (from pricebook entry up to product)
select Id, Product2Id, Product2.Id, Product2.Name
FROM PricebookEntry
WHERE productcode='CUCR05RC002'
"top down" (from product go down to related list of pricebook entries")
select Id, Name,
(select id from PricebookEntries)
FROM Product2
WHERE productcode='CUCR05RC002'
You use one or another depending on what you need. Multiple products? All entries from 1 pricebook?

Salesforce: Is there a way I can query my custom Commission table to return all the commissions under all contacts under a specific Account

I have a custom Commission table which has a master detail relationship with contact. I have a List of AccountIds being passed into the function and then into the query. I'm getting the error: " Didn't understand relationship 'Contacts' in FROM part of query call" Any help would be great.
List<Commission__c> comList2 = [SELECT commission_amount__c, date_given__c,
(SELECT Id FROM Contacts WHERE AccountId in : accountIds)
FROM Commission__c];
SELECT commission_amount__c, date_given__c, Contact__r.Name, Contact__r.Email
FROM Commission__c
WHERE Contact__r.AccountId IN :accountIds
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_understanding.htm

Salesforce Cross Object SOQL Query

I have a custom object called 'Billings'. On that object there is a custom lookup field to the Opportunity. I'm trying to query all the 'Billings' records associated with a particular Opportunity. I get "Unknown error parsing query".
SELECT Id, StageName,
( SELECT Name, Email FROM Billings__C )
FROM Opportunity WHERE Opportunity ID = '0011000002mfTil'
For Nested Queries in SOQL, you need to use the '__r' suffix on the Child Relationship Name for the field that provides the look-up from the Child Record to the Parent.
In your case, this is most likely 'Billings__r'. However, to confirm, go to the Billings object and click on the custom field that provides the lookup to the Opportunity object. In the "Lookup Options" section on the Custom Field details screen you will see the official Child Relationship Name without the '__r' suffix. This is the correct name for this relationship for a Nested Query.
The other error in your query is that you have "WHERE Opportunity Id =". It should just be "WHERE Id ="
Based on the information you provided, your query should be:
SELECT Id, StageName, ( SELECT Name, Email FROM Billings__r ) FROM Opportunity WHERE ID = '0011000002mfTil'

Attachments in Apex SOQL Subquery

I have custom objects Team member and Employment, and there's a lookup relationship from employment(many) to team member(one), plus another lookup record on team member called current employment.
The employment record may have attachments.
I want a SOQL query, to run in an APEX class, which will return attachments information for specific team members.
So far I have this:
SObject[] results = [select id,(select id,name from Attachments) from Employment__c where id in (select Current_Employment__c from Team_Member__c where id=:id)];
Wnen I run the query in the schema browser, it works OK and I'm able to drill-down to the attachments, but when I run it in Apex (Anonymous), the result set does not contain the attachments:
for (SObject result : results) {
System.debug(result);
}
I can only see the Employment id in the results.
How can I get attachments in APEX?
You do following to get list of attachment related to that object.
Employment__c[] results = [select id,(select id,name from Attachments) from Employment__c where id in (select Current_Employment__c from Team_Member__c where id=:id)];
for (Employment__c result : results) {
if(result.Attachments!=null){
List<Attachment> AttachmentList=result.Attachments;
}
}

SOQL Salesforce Join and Filter for 3 Different Objects

I would appreciate if someone can help me with the following requirement for building a SOQL.
Object1: Event :
Fields to get: Id, Subject, OwnerId
Object2: EventAttendee :
Fields to get: EventId, AttendeeId
Object3: User :
Fields to get: Id, Email
Note:
Id of Event = EventId of EventAttendee &
AttendeeId of EventAttendee = Id of user
So the requirement is to lookup Id from Event into EventId of EventAttendee and get the respective AttendeeID, then for the same AttendeeId lookup into user to get the Email address.
Thanks for your help.
One way would be to start from Event, go down to Attendees, then up to Users. The table that holds attendees is actually called EventRelation. Something like that should get you started:
SELECT Id, Subject, OwnerId,
(SELECT EventId, RelationId, Relation.Email FROM EventRelations)
FROM Event

Resources