SFDC Data Loader on Account - Same Id, Different Field Values

159 Views Asked by At

This is a relitively simple question regarding data loader. I'm currently running a query into our app that is pulling the 'last login' by a user for each account. As our app is not integrated with our SFDC I have to query the data, then manually upload the CSV file using data loader.

This particular field, 'Last Login', is on the account page. Long story short, the output of my query has some rows that will have the same account ID, but with different dates - most recent, and less recent. E.g. Two rows with same account ID. One 'Last Login' date is 7/30/18, and the other row (same account id) has a 'Last Login' date of 7/17/18.

See 'blue' delineated area. I want 7/30 to populate the field instead of 7/17

Instead of manually deleting the row with the 'less recent' date, is there a way I can order the column in such a way (either descending or ascending) so that the field 'Last Login' field will populate with the 'most recent' date?

Essentially, if the record is the same, what is the order in which the org will ingest the data?

Thanks for your help!

-M

1

There are 1 best solutions below

2
On BEST ANSWER

Data is inserted/updated in the order in which it appears in source file.

If you have update file like that:

Id,Name
00170000015Uemk,Some Name
00170000015Uemk,Some Different Name

The last option will "win". Note that this is behavio(u)r of the API access. In Apex doing something like that will crash & burn:

update new List<Account>{
    new Account(Id = '00170000015Uemk', Name = '1'),
    new Account(Id = '00170000015Uemk', Name = '2')
};
// System.ListException: Duplicate id in list: 00170000015UemkAAC

If you want to do it quick & dirty see if SELECT ... FROM Account ORDER BY Id, LastLoginDate ASC helps. It should sort multiple rows for same account together, but then sort by date in ascending order so most recent should "win".

But this sounds like you have a business rule to never overwrite a newer date with older one. So a validation rule maybe to reject bad rows? Something like

!ISBLANK(Date__c) && PRIORVALUE(Date__c) > Date__c