Today, when I was doing unit testing, I discovered a weird behavior in P8. I just discovered that the fetchInstance method of the Factory.Document, this one:
public static Document fetchInstance(ObjectStore os, String path, PropertyFilter filter)
can also take the Id as a string and not only a path. I wasn’t as nice as P8 in my unit test since I was expecting an ID type when mocking the static method, and of course my test failed :). I still think this isn’t a good practice so I changed my code to convert the String to an Id, but I thought it was worth noticing so here is a post about it. The best way in my opinion is to write
Factory.Document.fetchInstance(os, new Id(id), pf);
Factory.Document.fetchInstance(os, id, pf);
which actually works. I had to debug to convince myself because I found really strange that it worked :).
That’s it folks. Another good to know, but not good to do!