I have two Objects: Opportunity and Bid(custom Object). A bid is having a lookup field to opportunity i.e. an opp. can have multiple bids.

I need to update the comment field of Bid records, but the condition is I need to update only the latest created bid record of an open Opportunity. For example, if an open opp. is having 4 bid records and 4th bid is the latest created bid then I need to update only 4th bid record.

I need to achieve this scenario for multiple open opp. using data loader. I am not sure how to write SOQL for this and is this scenario possible to achieve using data.

1 Answer 1



In that case, you could use a nested query ordering the child records by CreatedDate, descending. Something like:

      (SELECT Id, Comment__c 
         FROM Your_Child_Record_Relationship__r 
         ORDER BY CreatedDate DESC 
         LIMIT 1) 
FROM Opportunity 
WHERE (your Opportunity filters here)

You can find the name of your Child Relationship Name on the Opportunity field of your custom object (Bid).

By exporting the child records, you will probably be able to use a data loader to update the comments.

  • Thanks for the solution. I am still struggling with this. Is this possible to convert this query to Bid object instead of Opportunity? Jun 22, 2022 at 9:27
  • @NikhilSinghal not in a single query due to the data configuration (Opportunity is the "parent" object, Bid is the child). You could grab a list of the OpportunityIds first and then use this list to filter down your Bid records query, using Apex or exporting the data in different steps to something like a spreadsheet. Jun 22, 2022 at 22:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .