Maintain identity histories option in refresh identity task update identity history by creating the identity snapshot. This may cause performance issue, however there are couple of cases like we need to create identity snapshot based on the life cycle events like in case of termination or transfer. Here is sample code which can be used to create identity snapshot programmatically.
String identityName = "<name of the identity in IdentityIQ>";
Identity identity = context.getObjectByName(Identity.class, identityName);
IdentityArchiver identityArchiver = new IdentityArchiver(context);
IdentitySnapshot identitySnapshot = identityArchiver.createSnapshot(identity);
context.saveObject(identitySnapshot);
context.commitTransaction();