You need to sign in to do that
Don't have an account?
prady
SOQL Help
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.
Thanks
Try This
SELECT Id, scantime__c, name, asset__c, status from trans__c
WHERE status = ‘pending’ ORDER BY scantime ASC LIMIT 1;
Limit 1 will only show one record.. What i wanted was
to get records of all assets, but if there are assets which are repeating then i only want the latest record of the repeating asset.
Thanks
try
Set<External ID type> setOfIDs = New Set<External ID Type>();
trans__c[] tcList = New trans__c[]{};
for (trans__c t : [SELECT Id, scantime__c, name, asset__c, status from trans__c
WHERE status = ‘pending’ ORDER BY scantime__c DESC]){
if(!setOFIDs.contains(assett__c)){
setOfIDs.add(t.assett__c);
tcList.add(t);
}
}
You should end up with a list (tcList) of unique assest with any duplicated asset only showing the latest scantime.
if you go with desc in the query then u will access the latest in all those...
[select id from objectname order by field name desc]
See my post above.
If you do not filter the query furthur you do not meet the use case of not returning any duplicate asset__c records. While sorting DESC will return the correct order, you still have the issue of multiple records for the same assett__c