i have three custom objects.          Bank_Account__c(Parent) ---&gt;Bank_transaction__c(child)  Bank_Account__c(Parent) ---&gt;Bank_statement__c(child)  Bank_transaction__c fields are date__c, credit__c, debit__c  Bank_statement__c fields are  start_date__c, end_date__c  I just want to write a single query to get the records of Bank_transaction__c which date__c is in between start_date__c and end_date__c of bank_statement__c object. How can i achieve this
121084
I want to write a soql query , My scenario is as follows. I have three objects objectA,objectB,objectC. objectA is the parent object for both objectB,objectC.   objectA - objectB  (Master-detail relationship) objectA - objectC  (Master-detail relationship)`   ObjectB has two fields:   Start_date__c End_date__c   ObjectC has a field:    Date__c   Now i want to retrieve records with date__c in objectC those were in between start_date__c and end_date__c of objectB. how can i achieve such functionality .
93357
My Trigger will send an email anytime one account has 7 cases created within 8 days. Towards the bottom in my Else block, I am trying to access fields in my first SOQL statement. I have tried many ways and read many help pages. Help with the syntax for the line: message.PlainTextBody = 'Account name: ' + cl.get('name') + ' has ' + (Integer)cl.get('co') + ' cases opened in the last 8 days.';`  is greatly appreciated.  List&lt;AggregateResult&gt; AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co                                          FROM Case                                          WHERE CreatedDate = LAST_N_DAYS:8                                          GROUP BY AccountId, Account.Name                                          HAVING COUNT(Id)  &gt;= 7];                           Set&lt;Id&gt; AcctIds = new Set&lt;Id&gt;();                 for(AggregateResult aggr: AggregateResultList){                      Id accId = (Id)aggr.get('AccountId');                         AcctIds.add(accId);                 }                  List&lt;Case&gt; caseList = [SELECT Id, AccountId, Account.Name,Parent_Project_if_applicable__r.Implementation_status__c,                                                 Parent_Project_if_applicable__r.PM_Implementation_Status__c,                                                  Parent_Project_if_applicable__r.RCM_Implementation_Status__c                                            FROM Case                                        WHERE AccountId IN :AcctIds];             Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();             for(Case cl:caseList){                   if(cl.Parent_Project_if_applicable__r.Implementation_status__c == 'Live - Closed Project'){                             //Private method *** getAddresses() *** retrieves email address from Customer_Success_Managers Public Group                              message.toAddresses  = getAddresses();                            }                         else{                                message.toAddresses = new String[] { Parent_Project_if_applicable__r.Client_Advisor_Email__c  };                          }                     message.Subject = 'Subject Test Message';                     message.PlainTextBody = 'Account name: ' + cl.get('name') + ' has ' + (Integer)cl.get('co') + ' cases opened in the last 8 days.';                     Messaging.SingleEmailMessage[] messages =   new List&lt;Messaging.SingleEmailMessage&gt; {message};                     Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);             } private List&lt;String&gt; getAddresses(){ List&lt;User&gt; UserList =         [SELECT id, name, email         FROM User          WHERE id          IN (SELECT userorgroupid              FROM groupmember             WHERE group.name = 'Customer Success Managers')];  List&lt;String&gt; emailString = new List&lt;String&gt;();  for(User u: UserList){     emailstring.add(u.email); }    return (emailString); }
33173
I would like to query an object that would return the "Created by" date from all custom apps in my org. Is there a way to do this through SOQL?
115603
How to find Accounts with no child Accounts? I tried Aggregate Query but its not returning proper result and inner query isn't supported for Self-Relation. Thoughts?
65366
I have a table of events with a recorded start and end time as a MySQL DATETIME object (in the format YYYY-MM-DD HH:MM:SS. I want to find all events that occur in a specific date range. However, events can span multiple days (and go outside of my date range, but I want to return them if they even overlap by 1 second or more with my date range).  Suggestions?
38431
I have More amount of Records in salesforce, i have created field as not Unique.So for account Records is created with duplicate Records also,I want to check how many Records contain dulplicate Records  for that I have wrote Query : I have lot of account records, i don't want to use limit for filtering the records when querying, i want to query all the records in salesforce.  But when i use:  SELECT JDE_ship_to_account_no__c, count(Id) records FROM account GROUP BY JDE_ship_to_account_no__c HAVING count(Id) &gt; 1   for that they suggested answer for this question:    How to write a batch apex code for above scenario, account records contain duplicates or Not?  I want to check all the records whether the record contain duplicates or Not
42901
I'd like to run a query using the EntityFieldQuery object. I need value from both the node and node_access table therefore I'd need to use INNER JOIN. From the d.o documentation I can't figure out how this is possible.  Here's what I have --  $query = new EntityFieldQuery(); $result = $query-&gt;entityCondition('entity_type', 'node') -&gt;entityCondition('bundle', 'node_access') -&gt;propertyCondition('type', 'external_link') -&gt;propertyCondition('status', 1) -&gt;fieldCondition('gid', '3', '=') -&gt;fieldCondition('realm', 'domain_id', '=') -&gt;fieldCondition('grant_view', '1', '&gt;=') -&gt;range(0,1) -&gt;execute();
67038
I'm trying to retrieve a list of Account objects from Salesforce using SOQL. Originally my query was this:  var result = service.query("SELECT Id, Name, RecordTypeId FROM Account"); return result.records.Select(record =&gt; record as Account).ToList();   However this only returns a maximum of 2,000 records and I have over that which I need to be returned by this query. After some digging around I found an example in Java which loops over the SOQL query which will allow a maximum of 10,000 records to be returned. I tried to replicate this in C# but it differs slightly, here is what I have now:  var accounts = new List&lt;Account&gt;(); foreach (Account account in service.query("SELECT Id, Name, Composer_ID__c, RecordTypeId FROM Account").records)     accounts.Add(account);  return accounts;   However this still only returns a maximum of 2,000 records. How can I return more than 2,000 records by querying Account?
82389
I have a contact in a generic sObject in apex and while I'm able to easily get detail field values using   sObject.get('MyContactField__c')  I'm not able to get fields off the related parent object, and I'm sure the related field is in memory, based on the debug logs. This returns a runtime error:  sObject.get('Account.MyAccountField__c')  with the error     Invalid field Account.MyAccountField__c' for Contact   How do I get a field value off of a parent on a generic sObject?
123689
I have a hierarchical query in Oracle 11gR2 that returns something like this:   Parent (Level 1)  Child (Level 2)  Grandchild (Level 3)  Child (Level 2)  Grandchild (Level 3) Grandchild (Level 3)  Child (Level 2)    The query I would like to write should get all the rows matching some predicate, for the minimum level; i.e. nearest the parent. For example, if one of the child rows matches the predicate, it should return just that row, irrespective of whether any grandchild rows match. If multiple child rows match, it should return all of them, again irrespective of grandchild rows. If no child rows match, it should return any grandchild rows that match, etc. (In the real system I have a lot more than three levels, and lots more rows per level.)  I assume this is possible with analytic functions, but I'm not sure which one to use, or how to integrate it into my query. I've seen similar problems solved using min (level) keep (dense_rank last order by level), but that doesn't seem to do quite what I want.
51081
I need to get a set of total transactions over time on a weekly interval. Essentially I need a total-transactions-to-date column. When I group by WEEK(Date) I get the amount of transactions for that week, but need to also get the transactions from any time before that week as well.  So let's say I have a table like this:  TransactionID  | Date ---------------|-----------              1 | 8-04-2014              2 | 8-05-2014              3 | 8-18-2014              4 | 8-18-2014              5 | 8-20-2014   I want to have a select statement that would provide me with something like  TotalTransactionsToDate | Week | Year ------------------------|------|------                       2 |    1 | 2014                       5 |    3 | 2014   I am using MySql 5.5.38
86549
I have created two custom objects (A and B)and a junction object(AB). i.e. Both A and B have Many to Many relationship. Now I need to insert 5000 records. How can I automatically populate the relation in Junction object. DO I have to write any trigger or Do I have to do Manually mapping the records?
55797
I am new to Apex trying to do some practice assignments and have gotten stuck on this junction object query.  Task: Edit the current getUser() method to do the following:  Return a custom object (that you define in the class) with the current getUser method's query data, and the list of teams the person belongs to (by querying the team assignments).   Parent Object 1: User (Standard Object) Parent Object 2: Team (Custom Object) Junction Object: Team Assignments (Custom Object)    **Original Class &amp; getUser Method** global class CTI {     global class CTIException extends Exception {}      global static User getUser() {          return [SELECT Id, Name, ProfileId, Profile.Name, UserRoleId, UserRole.Name, Username                  FROM User WHERE Id = :UserInfo.getUserId() ];     } }
99826
Why my soql query is returning 'RecordTypeId' instead of the fields mentioned in the query?  Here's my query:  SELECT Id, Name, ABC, (SELECT Id, XYZ FROM InnerObject) FROM OuterObj   Note: My query contains a subquery.
104137
H|~^20200425|~^abcd|~^sum R|~^abc|~^2019-03-06T12:33:52.27|~^1000123.34567|~^2018-04-12T12:33:52.27| R|~^abc|~^2019-03-05T12:33:52.27|~^111930.02876|~^2018-10-23T12:33:52.27| R|~^abc|~^2019-03-05T12:33:52.27|~^2112320.028|~^2018-10-24T12:33:52.27| R|~^abc|~^2019-03-06T12:33:52.27|~^12230.0809|~^2018-09-11T12:33:52.27| R|~^abc|~^2019-03-05T12:33:52.27|~^3076543789.00878|~^2018-08-05T12:33:52.27| R|~^abc|~^2019-03-06T12:33:52.27|~^156655.0389|~^2018-10-23T12:33:52.27| R|~^abc|~^2019-03-06T12:33:52.27|~^10453.0489|~^2018-04-08T12:33:52.27| R|~^abc|~^2019-03-05T12:33:52.27|~^20654.0907|~^2018-07-23T12:33:52.27|   I need to get the sum of the total amounts in the 4th field for the record starts from 'R'. I wanted sum of amounts of all the rows to be stored in a variable. how to achieve it
62227
I need to get all the dates present in the date range using SQL Server 2005
80455
Let's say  this is the sample date coming from a join of 2 tables. Database is Postgres 9.6  id  product_id  invoice_id  amount       date 1    PROD1       INV01       2          01-01-2018 2    PROD2       INV02       3          01-01-2018 3    PROD1       INV01       2          05-01-2018 4    PROD1       INV03       1          05-01-2018 5    PROD2       INV02       3          08-01-2018 6    PROD2       INV04       4          08-01-2018   I want to know if it's possible in a optimized way to:   Get all the PRODx with their respective INVx which have the latest date, but per product_id. Please note that records unused from a day may be reported to a new one. This means:    id  product_id  invoice_id  amount       date 3    PROD1       INV01       2          05-01-2018 4    PROD1       INV03       1          05-01-2018 5    PROD2       INV02       3          08-01-2018 6    PROD2       INV04       4          08-01-2018     Get daily summed amounts for each PRODx but fill the gaps with the previous ones if day does not exist.   This means:   product_id    amount       date    PROD1         2          01-01-2018    PROD2         3          01-01-2018    PROD1         2          02-01-2018    PROD2         3          02-01-2018    PROD1         2          03-01-2018    PROD2         3          03-01-2018    PROD1         2          04-01-2018    PROD2         3          04-01-2018    PROD1         3          05-01-2018    PROD2         3          05-01-2018    PROD1         3          06-01-2018    PROD2         3          06-01-2018    PROD1         3          07-01-2018    PROD2         3          07-01-2018    PROD1         3          08-01-2018    PROD2         7          08-01-2018   A few thoughts:   For first question I could obtain the max(date) for each PRODx and the pick for each PRODx the rows that have the date=with max(date) but I was wondering if there's faster way to obtain this given a large number of recors in the database For the second question, I could generate a series of dates for the interval needed and then use WITH rows As and do the query grouping by product_id and sum by amount and then select for each date the previous values from rows with a limit 1 but that does not sound that optimized either.   Looking forward for any input. Thank you.  Later edit: Trying to give DISTINCT ON () a try.   If I have distinct on(product_id, invoice_id) then I don't get only the most recent ones for the most recent date. If there were invoice_ids in the the past, beside the latest date, then they will be returned If I have distinct on (product_id) then it returns from the most recent date, but as normal, only the last rows even if in the last day I have two positions for PROD1.    Basically I need something like 'I need for the most recent date, all the product_ids and their invoice_ids while keeping in mind that a product_id can have multiple invoice_ids'  Later edit 2:  Running a query like for first question seems to be reasonably fast:  select product_id, invoice_id, amount from mytable inner join myOtherTable on...              inner join (select max(date) as last_date, product_id                           from mytable                           group by product_id) sub on mytable.date =                           sub.last_date