Skip to main content

Posts

Showing posts with the label apex code

Cache me if you can: What you should know before daring to set URL parameter on visualforce

Photo by John- Mark Kuznietsov http://stocksnap.io  If someone gave me a pence for every time there was an SOQL query in an APEX Class without using Limit or a condition during a code review, I could afford a Lamborgini this month. Sigh. If only. We make it a habit of going digging for data, at the very moment we need it. The crux of this problem happens when you have chain classes which are independent of each other. Each class needs the reference from a single record and we have to query for that record every single time. While we don't see it, every SOQL query has a cost to it, and it does not go in my Lamborghini fund, however, it should. In a recent project, we had to construct an Account 360 page that could fetch information from different integration points. The page was also called using a live telephony integration, which could pass the phone number for the account. This required an ability to keep in context the Account that was on call. Platform Cac...

Improving the user experience using visualforce

One of the biggest question customers have when implementing a CRM solution is how much can we automate the process? Considering that the representative will be spending 8-9 hours on the computer operating on CRM, the biggest question they ask is, 'Are you making my life easier or harder?' During a recent conversation on twitter this question popped up again. Is it possible to auto-populate the values on a visualforce page on choosing a lookup? Lets say you are designing a custom contact manager page. The page contains 4 fields from Account on the page including a lookup. When the user chooses a account value from lookup he would like to see the other 3 fields automatically populated, Sample visualforce code <apex:page standardController="Contact" extensions="AutopopulateController"> <apex:form> <apex:pagemessages id="msgs"/> <apex:pageblock title="Contact Create/Edit"> <apex:pageblocksec...

Five things to do while writing an apex code to prevent pulling your hair out later.

A new intern joined the team excited to learn about Salesforce. She had a little Java background and thought that Salesforce was very easy compared to Java. In her eagerness, she wrote a 20 lines of code to prove her skills and grasp on Salesforce. The problem was, the code could be written in just 3 lines. When you are coding on Salesforce, you have to keep in mind the following things: i) If you can save some lines of code, save it, you can use those lines later.  If you can write a code in 5 lines, don't waste a 6th one. That one line you saved could be the difference between spending a weekend in office optimizing the code or going to a party at the weekend. ii) Write like the code will run forever. Yes, your Sales team has taken in writing that there will only be three records in the system. Yes, you have written a good code for that. But when you are dealing with Salesforce, remember that data is going to increase over a period of time. Today you may be processing ...