Get the last instance of aggregate

I have the below aggregate to initialize a user. The user has a code. The code is predefined for the first user created DCAA" + cmd.getAcronym() + "001. Now, for the other users, I always need to retrieve the last created code to construct a new one.

So, my question is: how can I get the userCode of the last created user in the CommandHandler?

@Getter
@Setter
@NoArgsConstructor
public class User {

    @AggregateIdentifier
    private String userId;
	
    private String userCode;

    @CommandHandler
    @CreationPolicy(AggregateCreationPolicy.CREATE_IF_MISSING)
    private void handle(InitializeUser cmd) {
       final String code = "DCAA"+ cmd.getAcronym() +"001";

        final UserInitialized event = UserInitialized.builder()
                .userId(cmd.getUserId())
                .userCode(code)
                .build();

        AggregateLifecycle.apply(event);
    }

    @EventSourcingHandler
    private void on(UserInitialized evt) {
        this.userId = evt.getUserId();
        this.userCode = getUserCode();
    }
	
}

I don’t understand the question. If you would add a command handler annotated method to this class, it can directly access the user code. And likely it will apply an event to change the user code.

When the aggregate is loaded, it will get all the events for the aggregate, and rebuild the aggregate state (save for exceptions when either a cache or snapshots are used). But does that answer the question?

If I understand well, it needs the last one, not of the aggregate, but of all. This could be solved by using one specific aggregate just for that. But this might have a bad influence on performance, as this aggregate is needed for all code changes, and might be locked because of other updates. It might also quickly become big.