Association Labels based on First & Most Recent

Hi,
I’m trying to create a company based workflow which applies and updates “Most Recent” or “First” association labels to associated records.

The associated records live within a custom object, and they’re already associated through a indentifer key - but they’re misssing labels.
We have a bunch of historical records, so it’s not enough to set labels for whenever something new comes it. We have to set labels on the old ones as well.

There’s a date property on each associated record which we can use to “calculate” the order. I’m unable to write code myself so I’ve tried prompting chatgpt in various ways including this property, but I haven’t managed to solve it.
As an example, this is the output I’d like to achieve:

Associated Record ID Date Association Label
1 2025-01-01 First
2 2025-02-01 -
3 2025-03-01 -
4 2025-04-01 Most Recent

If new associated record comes in:

Associated Record ID Date Association Label
1 2025-01-01 First
2 2025-02-01 -
3 2025-03-01 -
4 2025-04-01 -
5 2025-05-01 Most Recent

Would love some guidence or suggestions on any way to achieve this.
Thanks in advance!

Hi @Andreas11 ,

Thank you for reaching out to the Community!

I’d like to invite some community members who are subject matter experts to join this conversation.

@DavidVoigt @karstenkoehler @Jonas_De_Mets - Would you be able to share any insights on this? Your expertise would be greatly appreciated.

Best regards,

Hi there,

if it’s a company based workflow, then enrollment could be based on each time the number of associated custom objects change.
If an object assiociation has been removed, you may need to relabel the remaining ones.
If one has been added, same. Because you’ll never know, what if the first associated object has been deleted - then the next best one would take its place.
Then, I would probably remove both association labels,
and re-label the associated objects.
So, for the workflow code:
1. get all the associated objects with id and their sort date property into a dictionary
2. clear their association labels to the company object
3. return the ids of the one with the oldest and newes date property
4 apply the new labels.
Btw what do you want to happen if there’s only one associated object? Because that would be the first and the most recent at the same time. Do you want to apply both labels?
For better advice, could you maybe disclose what’s the business problem this labelling is going to solve?