function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kkaalkkaal 

Update works, but not insert

I have a custom object which is edited in a edit form.

 

if((editTrait.Id == null) || (editTrait.Id == '')){ insert editTrait; } else { update editTrait; } editTrait = new Trait__c();

 

My question:

 

The update works, but not the insert.  I made sure that the must fields are filled. Is my if statement wrong?

 

 

bob_buzzardbob_buzzard
When you say it doesn't work, are you getting an error?  In which case can you post it.
kkaalkkaal
No error whatsoever, not on the form nor in the logs. It just doesn't insert.
bob_buzzardbob_buzzard

I would try a couple of things:

 

First, add some debug after the insert to  ensure it has completed successfully - dump out the editTrait object

 

Second, if the above doesn't shed any light, change the insert to a Database.insert and inspect the result to see if there were any errors.

kkaalkkaal

Sorry for my stupid question:

 

Over the WE I treied to make the debugging work. I get the logs, mut my statements System.debug(LoggingLevel.Info,...

does not show any entry in the logs. 

 

What would be the right debug statement. Maybe there is a good docu on that?? The standard docu, just tells me how I can switch on the logging, but not enough to about how to write the right statements in the code.

 

Thanks

bob_buzzardbob_buzzard

It depends on the filter settings as to what will appear in the logs.

 

If you are struggling with that, another way is to add a pagemessages tag to the page and add some messages at the INFO level. 

NaishadhNaishadh
try upsert