The following sample creates a history record.
Date date = new Date();
protected HistoryRepository historyRepository;
String uniqueKey = historyRepository.insertHistory(history);
private void createHistory() {
HistoryCreate history = new HistoryCreate();
//archivedOn is a required field
history.setArchivedOn(date);
//shortDescription is a required field
history.setShortDescription("Subject - Update contact phone number");
//text is an additional field that stores more information than the
shortDescription; text allows up to 20000 characters
history.setText("Additional information about the contact record update");
Category cat = new Category();
//the next two lines identify a category and then add the category to the history record
cat.setUniqueKey("HIST_STAT");
history.getCategories().add(cat);
//use the parentObject property to associate the history with an existing record by unique key, for example, to describe a contact record that you have recently modified
history.setParentObject("CONT_1234");
return history;
}