If Visualforce Blows, This Sucks
I recently saw a tweet that included nothing but a link and a lot of salesforce.com related tags.
Visual Force Blows (link was shortened in original tweet so I couldn’t see title)
What could this be I pondered? A new product announcement? A glowing review of the force.com platform? Upon clicking the link I entered the “I hate Apex and Visualforce Zone” (Dun Dun Dunnnnnnnnnnn). Some dude on a blog (man, everyone has a blog now days) is trying to build a dynamic link menu with data pulled from salesforce objects and using visualforce to display. This seems pretty normal right? Let us check out some excerpts first:
On Apex and Visualforce:
Sounds great in theory, however in reality it makes you want to stab yourself. A lot.
I on the other hand would bathe in it if I could. Oh ya….Visualforce and Apex, sooo bubbly clean. Ya, that was weird. Let’s move on.
Problem is, it uses what is called MVC (Model View Controller, or some shit like that) which divides your logic code, from your design code (oh my god, they invented the idea of functions that can be called, how fucking astounding). Seems like a solid plan, cause your design team and your programming team get to work separately and not step all over each others code. Problem is, I am the design team, and the coding team. That means I get to deal with the whole project from the ground up and deal with all the over engineered bs.
Whoa whoa whoa! The harshness, it hurts, but wait a second, isn’t the MVC concept pretty common. Isn’t this what all of those crazy iPhone apps use? And about a gazillion other languages.
Separating the design team and programming team is not really the purpose of this as both must work together to build awesome apps (even if it is the same person). The real advantage is that the styling/layout and logic are separate. This makes it much easier to code, debug, troubleshoot, and rework in the future. Anyone who has used the old s-controls can atest to this fact. Let us continue.
So what is the developer trying to do. He (she?) wants to simply create a navigation menu with links that have sub links. With his (we will assume it’s a he, sorry ladies) approach is that it stores all of the link relationships in one object. At first this may seem like a more simple and streamlined approach but this will soon spin out of controll as seen by the post in question.
In cold fusion he said he could do this in 6 lines but it doesn’t look like the example includes the sub links. So how about a Visualforce solution that includes sublinks in 10 lines of Apex and 11 lines of Visualforce (including class name, Visualforce page, and componenet tags)? Oh ya! It also only took me about 30 minutes to build. Double oh ya!
The first thing I would do differently is break this up into two objects. Link and Sub Link. Why more objects? We can then use the out of the box relationships to query all sub links when we query the links. This will actually significantly reduce the amount of required code. Each object has two text fields, URL and Label. The Sub Link object also has a lookup to the Link object. This approach also makes it much easier to maintain from a admin/user perspective. You can see all sub links for a link on one page.
Before we jump in to the code you can check out the snazzy demo here:
http://tehnrddemos-developer-edition.na7.force.com/linkmenu
First let’s look at the controller for the custom component we will be using. What we do is query the link object and all sub links related to the “parent” link at the same time. Technically I could make this class have even less lines but this example follows best practices so I won’t.
public class linkMenu{ List links; public List getLinks(){ if(links == null){ links = [select Label__c, URL__c, (select Label__c, URL__c from Sub_Links__r) from Link__c]; } return links; } }
Next up is the component. This loops through all of the parent links and outputs a hyperlink. For each parent it will then loop through the sub links and create a link that is indented slightly for each.
{!l.Label__c}
{!sl.Label__c}And finally the page. This is were it gets sort of complicated. Sorry about that.
So what have we learned today? I think if the other post is accurate in its statement that Visualforce blows than I am going to assume that this post really really sucks.
Oh, and don’t worry Apex and Visualforce creators, PMs, and team. I will protect you.
Apex and Visual Force (they are the bane of my existence on this planet and I would die a happy man if their creator(s) where beaten with reeds to within an inch of their life).
But seriously, what is up with this guy? I’ll admit some rants are funny but this is going over the top and you should try to keep it a little professional. Bridge burned. This is that last time I will provide any type of assistance to this guy.
EDIT: Oh darn! Just realized I named this post “If Visualforce Sucks, This Blows”. That was backwards. It is fixed now.

thanks for this rebuttal, that original post was ridiculous…much like the title of his blog “I Write Crappy Code”
As usual, not just a great (and much needed) response, but a great post, Jason!
Agree with Joe – the original post sucked!
Hey, this is Kenji, the guy who wrote that original post you are writting about. I certainly appreciate your rebuttal, and you are correct I may have been over the top. If you want to know “what is up” with me, it’s probably the fact that I simply do not understand how this language works and it frustrates me to know end that no matter how much I try to grasp it, I simply cannot understand why it works the way it does. That post was more me venting about my own lack of understanding than any real hate directed at the language. In my about section on that blog I do say that I don’t really know what I am doing in most things, and I fumble along, but I cannot seem to do that in apex. I am a big enough man to know that apex and visual force are probably good languages, and it’s me who is failing, but it doesn’t make it any easier. I will amend my post to try and have a bit more of disclaimer. Thank you for you’re informed rebuttal, I have learned a few things.
@Joe Ferraro
You are right. That’s why my blog is named that. I don’t know what I’m doing. Get it? It’s not a coincidence.
Also, please excuse the various spelling and grammar errors in the post above. I was fairly upset when I first read your post and replied.
I do feel foolish now, you have all made your point. To be honest I never thought anyone would even read my blog, it was just personal venting. Sigh, continue hating on me now. I guess I deserve it.
Don’t worry, I am a horrible speller myself. The reason your post go so much exposure was from the tweet and then this post.
The salesforce.com developer community is still pretty small. Dave, the guy who helped you on your blog is actually a technical evangelist for salesforce.com. It’s pretty cool that someone so close to the source is so deeply involved in the community that he was able to find and assist on your blog. If you are stuck there are a ton of resources at developer.force.com, including some great forums.
I can only offer this little advice. I understand the heavy use of satire but when it comes to the harshness, I would definitely tone it down. This is coming from someone who has walked that road before straight into a dead end and thankfully there were no negative repercussions but because this community is still on the smaller side the negative implications have the potential to be much greater for you.
Thank you for your feedback and advice. I have always been told I need to watch what I post alas, I am still kinda young and hot headed, and need to learn to keep that in check.
I agree the forums are great (when you actually get a response). Generally the people are friendly and professional, and yeah, it’s all good.
For the record, I really do like Salesforce, and the whole platform. Been working with it for about 2 years now (mostly just setting up objects, workflow rules, validation rules, etc), and really I do find most things to be very intuitive and easy to use and as a web developer myself am constantly amazed by the improvements they make with each release.
The issue is, probably due to lack of any proper training in this, or any similar language it (apex) ends up being a constant source of frustration, and yeah I lost it a little bit in that post after I had been grinding away for 2 days. I am really not a great programmer and I hate the constant failure I feel with Apex. I don’t understand the language constructs, I don’t get why things have to be bound to one controller, I don’t know why pages can’t invoke any component I want them to, I don’t get why there isn’t any flow control or logical statements available in VF (that I can find). In general I just feel very “boxed” into their design pattern which just doesn’t mesh well with the way I tend to write code, for better or worse.
The hardest part is realizing that it’s not the language that is failing, it’s me.
@Jason
Also, I have no idea why my post tweeted. I don’t use twitter, and I don’t recall setting it up to do so. I never meant for it to get that kind of exposure.
Yes your right, everyone has a blog these days, so you just answered my internal question. I am not creating a blog
The good news is this guy hates Visualforce. You might ask, “but mikef, why do you think it’s good that this person hates VF…”, because if you have a product; you want people to love it or hate it. Cause no one loves or hates products that are useless,
http://4.bp.blogspot.com/_mmBw3uzPnJI/Sy_PTWahxmI/AAAAAAAA7v0/aZxDr-IksmQ/s1600-h/useless_product_01.jpg
Thanks for posting the solution and maybe this guy/girl will learn something and make some money off this on-demand computing thing and be happy.
Or he/she just might start an open source project to bring back all teh coolness of cold fusion. I do recall a sfdc cold fusion tool kit, I am sure someone still has it.
Yes, in fact I do use the coldfusion SFDC toolkit and even made some improvements (supports infinite rows in a return query, and mass update/create of objects instead of one at a time). I love working with the Salesforce API, that is something I can really get behind and use. Pretty much every tool in our company, and our public facing website makes heavy use of Salesforce/Coldfusion integration.
I did learn something, and I will be implementing the suggested solution shortly, once I am able to finish swallowing my pride.
Win.
This could actually be accomplished without a controller entirely if not done in a component and done in a page.
One problem with your post, This guy is correct visualforce and apex does BLOW.
* The sales force pages look like they where created 20 years ago
* Visual force/Apex cannot even support JSON
* There are no Namespaces. Seriously? come on how can you be considered to be a decent language without name spaces, not to mention folders
* ALL the toolsets BLOW, the Eclipse plug-in is as slow as hell goes to crap everytime you hit save, Trying to delete a file or static resource is a nightmare as force.com thinks the file is references else where even when it is not
* Visual force fills your pages with Junk HTML, the HTML it outputs is ugly and generate huge page sizes
* The default behaviour of redirecting users after each form post, pfft how about a real solution instead of forcing users to make two round trips to the server.
* This list goes on and on
* Apex the API is so limited its unbelievable, no two way encryption, 100Kb limits on SOAP request, its a disaster to program against.
Additionally
The Date and DateTime Formatting support is abismal
Their wyiwyg editor blows
You cannot generate any type of java/apex doc
I want to output the current year as2010 salesforce auto format it for me to 2,010
No Select Distinct, Luckily Aggregate functions just made into the new version only had to wait until 2010 to so a Sum and Max SOQL command
I would applaud the author of the iwritecrappycode article, however – everything he states, is in fact pretty obvious.
I would then like to continue by giving out a darwin award, to everyone who mocks him.
Never before have I seen a more simple, restricted, limiting, and lets not forget: UGLY language. If you wish to create a simple web application that stores a single item in a single page, and that’s all – GREAT! It allows retarded monkeys with down syndrome to create this in a matter of 5 minutes – of course the interface looks like diarrhea, and the backend looks something like vomit.
Have you tried to do something complicated? Say a form, that has several linked objects, that does some processing. ITS A JOKE!
The built in functions are less than half the size that of java despite the language being a derivative of java, missing even the most basic of functions.
As for editing, all three options are retarded. The api takes forever to save, the X page editor chews memory like a motherf@#$er and so you find your self in this web embedded text editor – except that it lacks everything a text editor has like CTRL+Save, and the occasional backspace=browse.backwards and you loose your code.
And what kind of platform has limits on SQL queries per object?! WTF?!
And another thing, wtf is up with shared IDs. Have you tried to export from one sandbox to the other? ITS A NIGHMARE!
And logins, BLOODY LOGINS! So login names will be globally unique, but not globally recognised?! WHAT NOO!!!!! WERE YOU SALESFORCE GUYS DROPPED ON YOUR HEAD AS BABIES OR SOMETHING??
In all honesty, I would not allow the author or iwritecrappycode to beat the creators with a piece of reid… no no BECAUSE I WOULD BEAT HIM TO IT!!!
In case anyone is wondering, Tim and Dave, is the same person…….or are two people posting from the same IP address. Maybe two very disgruntled people at the same location, but I’m guessing the same guy
.
Though it is unfortunate, I am somewhat relieved to know I am not the only person struggling. Best of luck with your projects Tim/Dave, hopefully you’ll end up faring better than myself.
Jason: Because its impossible that two people from the same company would use the same technology, and share resources and articles related to said technology.
You obviously are a SalesForce supporter, not sure which gave it away first – you’ve defensive stance to Myself and Dave or your general stupidity.
Kenji776: oh no, we have a team of developers here who share your thoughts
Although, heavens forbid that they all make a post on here – Jason might get all skittish and schizophrenic and start making stupid remarks like “omg these ten people are all the same IP so they must be the same single person!”. Wheres that piece of reid when you need it.
Wow, I think it’s pretty obvious I am a salesforce supporter. No surprises here. Let’s not forget that if salesforce.com sucks so much there are plenty of other technologies out there that can be used instead.
Finally fixed the markup in Richards comment above. Thanks for showing that. No code = cool.
Well I am back, after more failure. I really tried to get it to work, but alas no success. Problem is I don’t need just links output, I need them in divs (to apply some styles and positioning via CSS). So I added some fields (to hold the desired CSS class, and required element ID) and attempted to include them in my controller. I ended up with this
Page
Component
Class
Produced Output
Desired Output
If anyone can tell me why, I would be very grateful. I’ll be posting on the Salesforce boards soon as well. Sorry to spam your blog.
Uhh, not sure what happened but my code above got totally manged. Most of it is missing. There was a fair amount of HTML thrown in there, so that’s probably what did it. Sorry bout that, I tried to use the code formatting tags.
@Kenji776
Hey Kenji, paste the code to http://www.cl1p.net/kenji776_sfdc then anyone on this board can take a look at it and modify it. If you do post back here and I’ll try to take a look at it today sometime.
Done. Thanks for the assist.
Kenji776′s code above has been fixed. WordPress is being dumb and is stripping out the code. I’ll need to do some testing.
If you post this on the dev boards, post the link here as well.
@Kenji776
Okay, so one problem you’re having is something I hate about VisualForce. Repeat components create a span tag, which breaks certain things it falls inside of. I have run into this countless time with tables and lists, and such. Are you bound to using unordered lists? You could attach styleClass to the repeat component and build something similar using span tags. As for the missing Id tags and missing class tags that is strange behavior. Perhaps someone else has some insight on why those aren’t coming across. Possible try throwing a debug statement to see if those fields are actually populated in the controller.
I don’t think the extra span is hurting me, as the css style is applied at the ID level (bad I know, but I didn’t design this css, some outside vendor built this style I’m just trying to move it all into SF).
I will do some extra digging to try and make sure those values are there, maybe I thought I put them in and I didn’t. It seems like it’s not able to get everything, cause its not pulling my link items either, only the containers.
Thanks for the help.
I got so fed up with the way visual force pages and how they RUIN how my XHTML and CSS work we decided to ditch visual force pages all together, Instead now we use the provided JavaScript classes
and call our custom apex web services to return data, then use PURE html and javascript to display the page. This works well for us, its:
1) much faster doing ajax request
2) faster as the page size is alot smaller not unwanted span tags and view state
3) gives us pixel perfect CSS and HTML layouts
From the same Dave as above
Those classes were ment to read:
/soap/ajax/17.0/connection.js and
/soap/ajax/17.0/apex.js
That’s actually a pretty good to handle it. I am about to go for that approach. I mean literally I’ve been hacking at this on and off for around a month now and still nothing to show. Perhaps it’s time for a new approach.
Just wondering (I’m sure its in the docs, but ill ask anyway), how do the objects get returned in JS? Just an array of structures or what? I’m pretty handy with JS (not amazing, but good enough to build a browser RPG out of it), so this is sounding pretty tempting. Can you get full DOM manipulation and such of VF pages? I would imagine so.
Yes the objects that come back at full structures with Array of Objects.
So you can do things like User.Accounts[1].name
I have updated the page here http://cl1p.net/kenji776_sfdc/ with some sample code. (NOT TESTED just written of the top of my head)
I find I still use the apex:repeater control a bit, and the {!bind} command but that’s about it.
I am also investigating http://jtemplates.tpython.com/ for generating HTML from JavaScript object
Also to answer your question “Can you get full DOM manipulation and such of VF pages”
yes you can do it (I use jQuery) but as VF generates ugly DOM IDs and classnames with : in them it makes it painful. Probably easier just to write your own HTML and not use VF at all.
I’m fine with that really. We just wanted to use VF and Salesforce sites for it’s hosting platform anyway, really don’t need any of the visual force capabilities (for now). I am so happy to find there is an alternative that can help me at least get this project complete before I invariable have to learn some more of it.
Dave, trying your code, for some reason the class is causing an error. It’s claiming a variable is undefined in line 6
links = [select Label__c, CSS_Class__c, HTML_ID__c, URL__c, (select Label__c, Link_Category__r.CSS_Class__c, Link_Category__r.HTML_ID__c, URL__c from Link_Items__r) from Link_Category__c];
I think it thinks links is undefined, but it is declared farther up. I wish the interface gave some more details as to whats wrong.
Thanks a ton for the sample code, gets me on the right track i think.
Sorry Blog owner for taking over your comments section and not using the force.com forums.
Yes sorry that’s because its static and we do not need a links variable.
Just return the select statement see updated source code. The method should just say
return [your soql];
WebService static List getLinks()
{
return [select Label__c, CSS_Class__c, HTML_ID__c, URL__c, (select Label__c, Link_Category__r.CSS_Class__c, Link_Category__r.HTML_ID__c, URL__c from Link_Items__r) from Link_Category__c];
}
Ah, okay cool. That did save. Loading the page now it does display your script and all that inside the div, but prodocudes no visible output. Javascript error console is reporting
Error: uncaught exception: {faultcode:’sf:INSUFFICIENT_ACCESS’, faultstring:’linkMenu: no access allowed to this class.’, }
Seems like perhaps I need to do something to mark the class as publicly available? It is declared as web service I thought. Not sure what else might need doing.
Kenji,
I think you’re class has to be global. Is it defined as global?
Ah, had to adjust security on that. Now im getting $ is not defined. That’s related to jquery right?
Yea… what browser are you using? In Chrome you can see all the loaded resources and see if it loaded jQuery. One thing to watch out for is that Vforce uses prototype, but from what I can tell it is only included when you use an AJAX method in Vforce. So check to see if prototype was loaded, if so remove any vforce ajax methods like “action”, “commandbutton”,”commandLink”, etc…
If you are getting an interference with jQuery and prototype you can use jQuery noconflict mode to get around it.
http://docs.jquery.com/Using_jQuery_with_Other_Libraries
Okay, this is so random, it seems to be bounding back and forth between the INSUFFICIENT_ACCESS message, and the $ is not defined message. I changed my component to use the no conflict
jQuery.noConflict();
jQuery(document).ready(function()
{
sforce.connection.sessionId = ‘{!$Api.Session_ID}’;
var results = sforce.apex.execute(‘linkMenu’ , ‘getLinks’, {menuName: ‘blah’ });
html = ”;
jQuery.each(results,function(intIndex, LinkItem){html += “” + LinkItem.Label__c + “”;});
var item = jQuery(html);
// Insert the generated HTML – is slower to do one at a time but doing this way allows us to set Data
jQuery(“body”).append(item);
})
but still am back to getting the insufficient access message. Yes it is global, and I am using firefox. Thanks for the help, this is weird.
First just try doing a Hello World Web Service Call. and alert it to the screen. No List or JQuery required. once you have that working move on.. Its all about BABY STEPS
Kenji,
Can you post the entire class again? I think I see the issue but need to see the whole class to confirm.
global class linkMenu
{ WebService static List getLinks(string menuName)
{
return [select Label__c, CSS_Class__c, HTML_ID__c, URL__c, (select Label__c, Link_Category__r.CSS_Class__c, Link_Category__r.HTML_ID__c, URL__c from Link_Items__r) from Link_Category__c];
}
}
I tested with this class and it seemed to work fine using the same syntax with changed class name, method name and variable name.. Try declaring the list as a List and see if that helps.. it seems like it shouldn’t matter, but I don’t see anything else wrong there.
global class testWS {
webservice static List caseList(String email) {
return [select Id, Subject, CaseNumber, Status from Case where Account.personEmail = :email];
}
}
That looks okay to me. In Firebug console window can you see the HTTP post to the service being made and returned ok?
Try this:
Class:
WebService static string hello(string name)
{
return ‘hello ‘+ name;
}
Page:
sforce.connection.sessionId = ‘{!$Api.Session_ID}’;
var x = sforce.apex.execute(‘linkMenu’ , ‘hello’, {name: ‘blah’ }) ;
alert(x);
arghh it cut the list type I was mentioning… Maybe even your code defines that… tehnrd’s blog likes to cut out code… gotta love wordpress.
yea mine wasn’t posting into the body with that jquery code, I even tried changing from body to #caseContainer (a div I created). try after the sforce.apex.execute command to do this: alert(results);
then we’ll know if the problem is elsewhere.
Dave, I managed to get this code working on my end. Thanks for showing me a new technique to get around the strange limitations of vforce.