Wednesday 18 July 2012

PopUp Open & close Window

There are i Have created two pages two Solve PopUp Open & close Window


VFP Page 1 (Main Page)



    
    
        
    



VFP Page 2 (TEZ_VFP_OpenPopupPage )



    
    
        
    



Wednesday 11 July 2012

TESTING ApexPages.Message IN CONTROLLER

Class

public class SomeController { 
  public SomeController (ApexPages.StandardController controller) { 
    if (System.currentPageReference().getParameters(). 
        get(’someParam’)!= null { 
      ApexPages.addMessage(new ApexPages.Message 
          (ApexPages.Severity.CONFIRM, ‘Parameter Exists’)); 
    } else if (System.currentPageReference(). 
          getParameters().get(’update’)!= null) { 
      ApexPages.addMessage(new ApexPages.Message 
          (ApexPages.Severity.ERROR, 
         ’Parameter Does Not Exist’)); 
    } 
  } 
}


Test Class

@isTest
public class TestClass {
 static testMethod void testConstructorParameters_noParams() { 
    PageReference ref = 
        new PageReference(’/apex/yourVisualforcePage’); 
    Test.setCurrentPage(ref); 
    
    SomeController controller = new SomeController (null); 
        
    System.assert 
      (ApexPages.getMessages().size() == 1); 
    System.assert 
      (ApexPages.getMessages().get(0).getDetail() 
        == ‘Parameter Does Not Exist’); 
    System.assert 
      (ApexPages.getMessages().get(0).getSeverity() 
        == ApexPages.Severity.ERROR);    
  } 
  
  static testMethod void testConstructorParameters_paramExists() { 
    PageReference ref = 
        new PageReference(’/apex/yourVisualforcePage?someParam=xyz’);
    Test.setCurrentPage(ref); 
    
    SomeController controller = new SomeController (null); 
      
    System.assert 
      (ApexPages.getMessages().size() == 1); 
    System.assert 
      (ApexPages.getMessages().get(0).getDetail() 
        == ‘Parameter Exists’); 
    System.assert 
      (ApexPages.getMessages().get(0).getSeverity() 
        == ApexPages.Severity.CONFIRM);  
  }
}

Monday 9 July 2012

JavaScript Remoting Example

JavaScript remoting in Visualforce provides support for methods in Apex controllers to be called via JavaScript. This allows you to create pages with complex, dynamic behavior that isn’t possible with the standard Visualforce AJAX components. There are three aspects to JavaScript remoting:

1. The remote method invocation you add to the Visualforce page, written in JavaScript.

2. The remote method definition in your Apex controller class, written in Apex, but there are few differences from normal action methods.

3. The response handler callback function you add to or include in your Visualforce page, written in JavaScript.

VFP Page


    

    
    
    
    

Class


global class TEZ_AC_RemoteActionExample {
    //Variables
    public String accountName { get; set; }
    public static Account account { get; set; }
    
    // constructor
    public TEZ_AC_RemoteActionExample() { }  
    
    //Remote Action
    @RemoteAction
    global static Account getAccount(String accountName) {
        account = [SELECT Id, Name, Phone, Type, NumberOfEmployees FROM Account WHERE Name = :accountName];
        return account;
    }
}



Set remove(null) method throws an error

"System.NullPointerException: Argument 1 cannot be null" will be received :-- You can also Test by below example

Set <Integer> testSet = new Set <Integer>(); 
testSet.add(1); 
testSet.add(2);
testSet.add(null);  
testSet.add(3); 

testSet.remove(3);
testSet.remove(null);



Error is: "System.NullPointerException: Argument 1 cannot be null It is thrown by the line: testSet.remove(null)"