Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6963489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:47:55+00:00 2026-05-27T15:47:55+00:00

I need to query an object called trans__c which has the following fields id,

  • 0

I need to query an object called trans__c which has the following fields

 id,
 scantime__c // datetime
 name
 asset__c // external id
 status

I need to get only data which has status as pending and if there are any repeating asset then I need to get only record with scantime as the latest.

For e.g.

If there are 3 records

   asset         name      scantime              Status

    1            Rec 1      17-dec-2011 13:10     Pending
    1            Rec2       17-dec-2011 13:50     Pending
    2            Rec3       17-dec-2011 13:10     Pending

The output of the query should be

    1            Rec2       17-dec-2011 13:50     Pending
    2            Rec3       17-dec-2011 13:10     Pending
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:47:56+00:00Added an answer on May 27, 2026 at 3:47 pm

    Group By is only really for use with aggregate queries, which is a bit of a pain when it comes to the other fields that you don’t want to aggregate.

    This may not be the correct approach, but I’d grab all of the ‘Pending’ records then do the logic in code (assuming you’re not masses of results):

    map<integer, Trans__c> mapAssetToRecord = new map<integer, Trans__c>();
    
    for(Trans__c [] sTransArr : [select Id, Name, Asset__c, Scan_Time__c, Status__c
                                   from Trans__c
                                  where Status__c = 'Pending'])
    {
        for(Trans__c sTrains : sTransArr)
        {
            if(mapAssetToRecord.get(sTrans.Asset__c) == null)
            {
                mapAssetToRecord.put(sTrans.Asset__c, sTrans);
            }
            else if(sTrans.Scan_Time__c > mapAssetToRecord.get(sTrans.Asset__c).Scan_Time__c)
            {
                mapAssetToRecord.put(sTrans.Asset__c, sTrans);
            }
        }
    }
    
    // now mapAssetToRecord includes all of the records you want
    

    There may be a more elegant solution involving some clever SOQL, but it escapes me right now (after all, it is Sunday morning and I’ve only just had breakfast!).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database called People which contains the following schema <id,name,foodchoice1,foodchoice2> .
I have a JPA object called Customer.java: @NamedQueries({@NamedQuery(name=getAccountWithCheckRangeByService, query=SELECT c FROM Customer}) public Long
I need to implement a Query Object Pattern in Java for my customizable search
I need to write a query that returns all object less that or equal
How can I construct an object using a query if I also need to
I need to query a database which is designed so what a NVARCHAR column
I have a model( Delivery ) with 2 fields called name and to_date .
We have a custom object in Salesforce called domain which reflects each website we
I need to write some sql that will allow me to query all objects
Need to query my SQL server from Access using an ADO connection (for example),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.