For the sake of completeness, and because I’ve received a large number of hits from the googled phrase ‘pass apex to javascript’, I thought it would be appropriate for me to write an article detailing the converse of an operation explain in a previous post.
Wes
Passing Javascript values to Apex code.
It’s been a while crocodile. Truth be told I was working furiously on my Site’s Developer Challenge entry, and then I was just too pooped to post. I’m sure you were all waiting with bated breath for my next post.. nooooot.
Anyway, let’s get down to brass tacks. Quite often I’ve needed to manipulate variable values in-page(Visualforce) with JS, and then pass these modified values to Apex or a Standard Controller. Just as often I’ve simply dismissed the possibility and worked-around the issue. Recently I was speaking to a fellow who proposed the beginnings of a terribly smashing idea and thought I’d try my hand at a simple implementation.
Lists of SObjects and Classes – By value or reference?
I found a quirky bug in my code some time back, and realised that the cause of the bug was quite a useful Apex feature viz. SObjects and Apex classes are passed by reference and not value.
What does this mean you say? Let’s start by defining what passing by value means.
In a nutshell, if you pass a variable to a method and it’s a Force.com primitive type(Integer, String etc.) it will be passed by value meaning that the value of the variable and not the variable itself is passed to the method
Formatting Salesforce OutputText
Quite recently I came across an interesting forum post by XactiumBen that mentioned some awesomesauce abilities of params in outputTexts. I’ve written an article detailing the basics of this functionality before, and thought I’d document these advanced capabilities too. For anyone interested you can read Part 1 here.
Now I’m sure some of you thought that simply being able to use dynamic custom labels was pretty smashing in it’s own right, but you ain’t seen nothing yet. Imagine a world where you could not only use dynamic custom labels, but were also able to use decision structures in those labels. That’s the world we live in buddy!
Meaningful Error Messages #24
Having just managed to discover the cause of a particular error message, I thought I’d share the solution with the community.
Once in while you come across error messages that point you in absolutely no direction at all. Most recently I’ve been receiving ‘Failed validation: ApexPage‘. Thinking that I might get something more meaningful from the in-browser IDE I dumped my code there and got this little gem
Error: common.request.servlet.PageDispatcher$Hack404 | ||
Error: null |
the sharing model cannot be updated through the api
Now I’m sure there’s a reason for this but it makes me sad a bit. Especially when working with a team of developers. Recently I found myself in the following situation,
My team and I had been building a Force.com application and were interested in implementing an UAC model. We had setup the UAC model on one of the Orgs using profiles, roles and sharing rules(we had some issues here too) and then attempted to commit these changes into our SVN repository. Happy that things were going so well, each developer checked out the code and BHAM! we were no longer able to deploy object definitions. [Slow pan to me on my knees screaming to the heavens. A thunderbolt, then a thunderclap overhead]
Handling System.QueryException
When attempting to fetch a single record from the database it is easy to run into the above exception. I’ve seen two schools of thought in dealing with this issue – mostly in the forums – and have been hoping to find a more official standpoint.
Unit Test Data Consistency
I’m sure every Apex developer has had their Developer Org data interfere with their unit testing. Or perhaps you have coded unit tests that function perfectly within your Developer Org but when deployed to another Org fail because of a different, partial or empty database.
Of course as a developer this type on inconsistency within your work environment is extremely counter-productive. Initially I developed a methodology that did the job but wasn’t nearly as concise as I would have liked. More recently however I’ve developed a technical solution that is universal as well as quick to implement.
How to avoid Governor Limits [Part 1 of N]
This topic is waaaay too big to cover in one post, so for now I’m going to concentrate on avoiding this particular exception: ‘Too many SOQL queries’. I will also touch on the ‘Too many DML rows’ exception, and expand on it’s solutions in another post. Bulkifying your triggers is another topic I will cover at some later date, but the methodologies mentioned here should go some way towards helping you avoid some of the Governor Limits there too.