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
DPFrazierDPFrazier 

Apex Code - Can't save unless it compiles correctly?

I've tried to create a relatively simple function in both the Eclipse environment and in Setup->Build->Code, and unless/until the code compiles correctly, all edits since the last successful compile will be wiped out.

I'm a newbie to Java, so I don't know if this is normal.  But I don't always finish debugging a code block before I want to (or have to) move onto something else, and I don't want to lose the work I've done when I do so.

Perhaps have both "in development" and "deployed" modes for Apex code packages?

As an aside, it's interesting that I can be editing the same code in both places at the same time.  There should probably be an interlock for this.
adamgadamg
I assume you mean that if within Eclipse you can't "save" a non-compiled package / trigger? (If a compile fails, it doesn't remove your changes, but if you close the file in Eclipse, I believe it will.)  If so, that could be an interesting feature to add..
DPFrazierDPFrazier
Here's the sequence I just went through...

  • In Eclipse, I entered about 20 lines code in a package, and clicked "Save".
  • There were a few undeclared variables, so I declared them, and again clicked "Save".
  • There was an UNKNOWN_EXCEPTION error.
  • So I exited Eclipse, and was asked if I wanted to save changes in the Apex package. I selected "Yes".
  • When I went back into Eclipse, all my code changes were gone.
  • I still wanted to save the code in the Apex package, without encountering the exception error.
  • So I re-entered the code and left one undeclared variable.
  • I again exited Eclipse, and again selected "Yes" to the prompt about saving changes to the package.
  • Once again, when I went back into Eclipse, all my code changes were gone.

So I can't save this code in Eclipse no matter what I do!

I went through a similar sequence with Setup->Build->Code, but still can't save the code in either the "correct" form (since there's the exception error) or the "buggy" form (since apparently you can't save Apex code that has a syntax error).

So now I'm capturing my code in a Word file before I exit Eclipse...