Skip to main content

Posts

Common Mistake We Do While Developing.

HI All,  I am going to address common mistake we do while doing customization in client sandbox. M istake-1 We  created one visualforce page(name-testpage) and controller(name-testpageController) for some functionality. To call that page we created one button whose content source is link. We have to provide the link.  let say link is  https://c.ap1.visual.force.com/apex/testpage From link  " https://c.ap1.visual.force.com " this part is known as instance name which differs from org. to org. However this button will work fine in the sandbox but It wont work if we move changes to production because production must be having different instance name. If we click on button in the production it will show error page does not exists .  Remedy for this problem is we will provide link as below. /apex/testpage   (Don't append instance ). Mistake-2   Suppose we created a hyperlink formula field to navigate some visualforce page as belo...

Check Package Installation based on Name Space Prefix..

How can you ensure particular package is installed or not in your org.  Here is some code snippet which will help you on the same.  let say the package prefix is invoiceit_crmx. String sExtensionNameSpace = 'invoiceit_crmx';     Boolean isInstalled;     try{     if( Userinfo.isCurrentUserLicensed(sExtensionNameSpace )){     isInstalled = true;     }     else{     isInstalled = false;     }     }catch(Exception ex){     isInstalled  = false;         ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Please  install CRM extension package to access these records');     ApexPages.addMessage(myMsg);              } If package is not installed then It will through Type exception. You can handle that exception and show...

Retrieving Value From SelctionOption List

Hi Guys  I am going to share about one issue which I have come across.  I was just  comparing some value of selectOption list by iterating that list. Here is the code:- list<SelectOption> listOfOptions; listOfOptions = new list<SelectOption>(); listOfOptions.add(new SelectOption('a','a') ); listOfOptions.add(new SelectOption('1','1') ); listOfOptions.add(new SelectOption('A','A') ); listOfOptions.add(new SelectOption('@','@') ); for(SelectOption option:listOfOptions){    if(option== 'A'){         System.debug('hi');    } } COMPILE ERROR: Comparison arguments must be compatible types: System.SelectOption, String To avoid this error we need to use getValue() met hod. list<SelectOption> listOfOptions; listOfOptions = new list<SelectOption>(); listOfOptions.add(new SelectOption('a','a') ); listOfOptions.add(new SelectOption('1','1') ...

Restricting User to Double Click on Button

Hey Guys !!! This post is regarding to avoid one small issue I have come across it. Let say there is a visual force page where input fields and one button is present. When that button is clicked records are inserted in to the object. If button is clicked twice in same time(double click) then records(duplicate records ) are being created twice.  How will we avoid that? How will restrict user to do double click on button? Here I am sharing some snippet of code.Hope It will help you. V isualforce Page <apex:page standardController="Account">     <apex:form >         <apex:pageMessages id="messages"></apex:pageMessages>         <apex:pageBlock title="Avoid Doublle Click" >             <apex:pageBlockButtons location="both">                                  <apex:act...

Preventing Copy,Paste and Right Click In Your Page

Hi Guys Everybody must have visited bank site there we can not do right click or copy Account number and paste in another field Retype Account Number. That means we should not give any chance to anybody to see page source. We do this for more security purpose.  That made me to think and try to design same in visual-force page. Here I have  only  used JavaScript  for this functionality.  There are some snippet of code.Hopefully It will help you.  Functionality  Preventing to see the Page Source. Preventing paste Email field value in Re Email field. Here is the page:- <apex:page StandardController="Contact">   <script>       function DisableRightClick(event){             if (event.button==2)         {             alert("Right Click is not Allowed");                ...

Test Class in Salesforce

Hi Guys  This post is only for somebody (who are new to test class in salesforce) who asked me to write a test class for one of my Post   .  Unit tests are class methods that verify whether a particular piece of code is working properly. Unit test methods take no arguments, commit no data to the database, send no emails, and are flagged with the testMethod keyword or the isTest annotation in the method definition. Also, test methods must be defined in test classes, that is, classes annotated with isTest. Here I am sharing some links regarding test class basic functionality. Please go through this. http://salesforceworld.blogspot.in/2012/03/unit-testing-in-salesforce.html http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm. Roopal Chouhan  ,Here is the example of test class which you had asked me to write for this  Controller Here is the test class.  /**  * Testing and Code Coverage.  */ @isTest private c...

A Visualforce Page Excatly Same as Contact Edit Page

Hi  This is a very simple post. I had seen that question  developerforce.com . That's why I thought I will share in my blog. The question was there will be a link called "Copy Mailing Address to Other Address" when clicked that link all Mailing address will be copied to other address same as standard edit page of contact. This can be done two ways.  By using java script By using Controller extension In the command link we have to call java script method there we will get all the field value of mailing addresss using documnet.getElementByid() method in javascript and will assign to the other address field.  Second approach is we will call extension method where will assign all the mailing address field to other address field and will reRender (refresh) the block. It will behave exactly like as standard edit page layout of Contact functionality. Now the challenge is how will we display that command link inside that pagablock section header. ...