Hi,
I am trying to create a DB record where a dependency record may not yet
exist and I'm getting a "No rows for ..." error. I don't understand how
I should create the child record that will be used for the parent object
so it can be referenced by the parent object without getting an error.
The idea is to dynamically create a child record as needed.
Thanks,
Andrew
Example code:
ObjectContext oc = ClientBaseAdmin.getObjectContext();
CommunicationLog cl = oc.newObject(CommunicationLog.class);
cl.setCommunicationDT(LocalDateTime.now());
cl.setCommunicationType(CommunicationType.find("Email"));
oc.commitChanges();
and in CommunicationType I have
public static CommunicationType find(String value) {
CommunicationType result = null;
result = ObjectSelect.query(CommunicationType.class)
.where(CommunicationType.DESCRIPTION.eq(value))
.selectFirst(ClientBaseAdmin.getObjectContext());
if (result == null) {
CommunicationType ct =
ClientBaseAdmin.getObjectContext().newObject(CommunicationType.class);
ct.setDescription(value);
ClientBaseAdmin.getObjectContext().commitChanges();
result = ct;
}
return result;
}