Ajax (1) Apex Class (12) Apex Trigger (2) Community (2) Home Page (1) HTML (4) Integration (3) JS (7) KB (1) Label (1) Licenses (1) Listing (1) Log (1) OOPs (5) Sharing (1) Static Resource (1) Test Class (3) URI (1) Visualforce (10)

Thursday 29 January 2015

Simple/Regular Vs Abstract Vs Virtual )

Salesforce : APEX : Class ( Simple/Regular Vs Abstract Vs Virtual )

APEX : Class ( Simple/Regular Vs Abstract Vs Virtual )
Note : simple/regular means, class without abstract and virtual keyword

Before going into differences between these, understand regular, abstract, virtual methods :
Regular Method  : Has code body or code implementation  and cannot be overridden

Virtual Method    : Has code body or code implementation and can be overridden by extending class method using override keyword

Abstract Method : Doesn't have body or code implementation and can be overridden by extending class method using override keyword



Regular Class:
a) Can be constructed ( can create object ).
b) Can not be extended
c) Can have regular methods
d) Can have virtual methods
e) Can not have abstract methods

Virtual Class:
a) Can be constructed ( can create object ).
b) Can be extended
c) Can have regular methods
d) Can have virtual methods
e) Can not have abstract methods

Abstract Class:
a) Can not be constructed ( can not create object ).
b) Can be extended
c) Can have regular methods
d) Can have virtual methods
e) Can have abstract methods

Note:
i) Extending class can not reduce visibility of super method by overriding it.
ii)Extending class can not change return type of super method by overriding it.
iii)Extending can do method over loading e.g.

Super class has 
public void getName(){
return 'My Name'; 
}

and Extending class can have
public getName(String str){
return str; 
}

iv) class can't extend two classes but can extend one class (virtual/abstract) and implements multiple interfaces. 

Using the super Keyword

Open topic with navigation

Using the super Keyword

The super keyword can be used by classes that are extended from virtual or abstract classes. By using super, you can override constructors and methods from the parent class.

For example, if you have the following virtual class:
public virtual class SuperClass {      public String mySalutation;      public String myFirstName;      public String myLastName;        public SuperClass() {            mySalutation = 'Mr.';          myFirstName = 'Carl';          myLastName = 'Vonderburg';      }        public SuperClass(String salutation, String firstName, String lastName) {            mySalutation = salutation;          myFirstName = firstName;          myLastName = lastName;      }        public virtual void printName() {            System.debug('My name is ' + mySalutation + myLastName);      }       public virtual String getFirstName() {         return myFirstName;     }  }
You can create the following class that extends Superclass and overrides its printName method:
public class Subclass extends Superclass {    public override void printName() {          super.printName();          System.debug('But you can call me ' + super.getFirstName());      }  }

The expected output when calling Subclass.printName is My name is Mr. Vonderburg. But you can call me Carl.

You can also use super to call constructors. Add the following constructor to SubClass:
public Subclass() {      super('Madam', 'Brenda', 'Clapentrap');  }

Now, the expected output of Subclass.printName is My name is Madam Clapentrap. But you can call me Brenda.

Best Practices for Using the super Keyword

  • Only classes that are extending from virtual or abstract classes can use super.
  • You can only use super in methods that are designated with the override keyword.
© Copyright 2000–2015 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.

 

Extended Class Example

Open topic with navigation

Extended Class Example

The following is an extended example of a class, showing all the features of Apex classes. The keywords and concepts introduced in the example are explained in more detail throughout this chapter.

// Top-level (outer) class must be public or global (usually public unless they contain                      
// a Web Service, then they must be global)
public class OuterClass { // Static final variable (constant) – outer class level only
  private static final Integer MY_INT; // Non-final static variable - use this to communicate state across triggers
  // within a single request)
  public static String sharedState; // Static method - outer class level only
  public static Integer getInt() { return MY_INT; } // Static initialization (can be included where the variable is defined)
  static { MY_INT = 2; } // Member variable for outer class
  private final String m; // Instance initialization block - can be done where the variable is declared,
  // or in a constructor { m = 'a'; } // Because no constructor is explicitly defined in this outer class, an implicit,
  // no-argument, public constructor exists

  // Inner interface
  public virtual interface MyInterface { // No access modifier is necessary for interface methods - these are always
    // public or global depending on the interface visibility
    void myMethod(); } // Interface extension
  interface MySecondInterface extends MyInterface { Integer method2(Integer i); } // Inner class - because it is virtual it can be extended.
  // This class implements an interface that, in turn, extends another interface.
  // Consequently the class must implement all methods.
  public virtual class InnerClass implements MySecondInterface { // Inner member variables
    private final String s; private final String s2; // Inner instance initialization block (this code could be located above) { this.s = 'x'; } // Inline initialization (happens after the block above executes)
    private final Integer i = s.length(); // Explicit no argument constructor InnerClass() { // This invokes another constructor that is defined later
       this('none'); } // Constructor that assigns a final variable value
    public InnerClass(String s2) { this.s2 = s2; } // Instance method that implements a method from MyInterface.
    // Because it is declared virtual it can be overridden by a subclass.
    public virtual void myMethod() { /* does nothing */ } // Implementation of the second interface method above.
    // This method references member variables (with and without the "this" prefix)
    public Integer method2(Integer i) { return this.i + s.length(); } } // Abstract class (that subclasses the class above). No constructor is needed since
  // parent class has a no-argument constructor
  public abstract class AbstractChildClass extends InnerClass { // Override the parent class method with this signature.
    // Must use the override keyword
    public override void myMethod() { /* do something else */ } // Same name as parent class method, but different signature.
    // This is a different method (displaying polymorphism) so it does not need
    // to use the override keyword
    protected void method2() {} // Abstract method - subclasses of this class must implement this method
    abstract Integer abstractMethod(); } // Complete the abstract class by implementing its abstract method
  public class ConcreteChildClass extends AbstractChildClass { // Here we expand the visibility of the parent method - note that visibility
    // cannot be restricted by a sub-class
    public override Integer abstractMethod() { return 5; } } // A second sub-class of the original InnerClass
  public class AnotherChildClass extends InnerClass { AnotherChildClass(String s) { // Explicitly invoke a different super constructor than one with no arguments
      super(s); } } // Exception inner class
  public virtual class MyException extends Exception { // Exception class member variable
    public Double d; // Exception class constructor MyException(Double d) { this.d = d; } // Exception class method, marked as protected
    protected void doIt() {} } // Exception classes can be abstract and implement interfaces
  public abstract class MySecondException extends Exception implements MyInterface { } }
This code example illustrates:
  • A top-level class definition (also called an outer class)
  • Static variables and static methods in the top-level class, as well as static initialization code blocks
  • Member variables and methods for the top-level class
  • Classes with no user-defined constructor — these have an implicit, no-argument constructor
  • An interface definition in the top-level class
  • An interface that extends another interface
  • Inner class definitions (one level deep) within a top-level class
  • A class that implements an interface (and, therefore, its associated sub-interface) by implementing public versions of the method signatures
  • An inner class constructor definition and invocation
  • An inner class member variable and a reference to it using the this keyword (with no arguments)
  • An inner class constructor that uses the this keyword (with arguments) to invoke a different constructor
  • Initialization code outside of constructors — both where variables are defined, as well as with anonymous blocks in curly braces ({}). Note that these execute with every construction in the order they appear in the file, as with Java.
  • Class extension and an abstract class
  • Methods that override base class methods (which must be declared virtual)
  • The override keyword for methods that override subclass methods
  • Abstract methods and their implementation by concrete sub-classes
  • The protected access modifier
  • Exceptions as first class objects with members, methods, and constructors

This example shows how the class above can be called by other Apex code:

// Construct an instance of an inner concrete class, with a user-defined constructor  OuterClass.InnerClass ic = new OuterClass.InnerClass('x');    // Call user-defined methods in the class  System.assertEquals(2, ic.method2(1));    // Define a variable with an interface data type, and assign it a value that is of 
// a type that implements that interface OuterClass.MyInterface mi = ic; // Use instanceof and casting as usual OuterClass.InnerClass ic2 = mi instanceof OuterClass.InnerClass ? (OuterClass.InnerClass)mi : null; System.assert(ic2 != null); // Construct the outer type OuterClass o = new OuterClass(); System.assertEquals(2, OuterClass.getInt()); // Construct instances of abstract class children System.assertEquals(5, new OuterClass.ConcreteChildClass().abstractMethod()); // Illegal - cannot construct an abstract class
// new OuterClass.AbstractChildClass();

// Illegal – cannot access a static method through an instance
// o.getInt();

// Illegal - cannot call protected method externally
// new OuterClass.ConcreteChildClass().method2();
This code example illustrates:
  • Construction of the outer class
  • Construction of an inner class and the declaration of an inner interface type
  • A variable declared as an interface type can be assigned an instance of a class that implements that interface
  • Casting an interface variable to be a class type that implements that interface (after verifying this using the instanceof operator)
© Copyright 2000–2015 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.

 

Access Modifiers

Open topic with navigation

Access Modifiers

Apex allows you to use the private, protected, public, and global access modifiers when defining methods and variables.

While triggers and anonymous blocks can also use these access modifiers, they are not as useful in smaller portions of Apex. For example, declaring a method as global in an anonymous block does not enable you to call it from outside of that code.

For more information on class access modifiers, see Apex Class Definition.

Note
Interface methods have no access modifiers. They are always global. For more information, see Understanding Interfaces.

By default, a method or variable is visible only to the Apex code within the defining class. You must explicitly specify a method or variable as public in order for it to be available to other classes in the same application namespace (see Namespace Prefix). You can change the level of visibility by using the following access modifiers:

private
This is the default, and means that the method or variable is accessible only within the Apex class in which it is defined. If you do not specify an access modifier, the method or variable is private.
protected
This means that the method or variable is visible to any inner classes in the defining Apex class, and to the classes that extend the defining Apex class. You can only use this access modifier for instance methods and member variables. Note that it is strictly more permissive than the default (private) setting, just like Java.
public
This means the method or variable can be used by any Apex in this application or namespace.
Note
In Apex, the public access modifier is not the same as it is in Java. This was done to discourage joining applications, to keep the code for each application separate. In Apex, if you want to make something public like it is in Java, you need to use the global access modifier.
global
This means the method or variable can be used by any Apex code that has access to the class, not just the Apex code in the same application. This access modifier should be used for any method that needs to be referenced outside of the application, either in the SOAP API or by other Apex code. If you declare a method or variable as global, you must also declare the class that contains it as global.
Note
We recommend using the global access modifier rarely, if at all. Cross-application dependencies are difficult to maintain.

To use the private, protected, public, or global access modifiers, use the following syntax:

[(none)|private|protected|public|global] declaration

For example:

private string s1 = '1';    public string gets1() {      return this.s1;   }  
© Copyright 2000–2015 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.

 

Thursday 15 January 2015

JQuery Slider

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>

<div data-role="page">
  <div data-role="header">
    <h1>Slider Control</h1>
  </div>

  <div data-role="main" class="ui-content">
    <form method="post" action="demoform.asp">
      <label for="points">Points:</label>
      <input type="range" name="points" id="points" value="50" min="0" max="100">
      <input type="submit" data-inline="true" value="Submit">
    </form>
  </div>
</div>

</body>
</html>

Tuesday 13 January 2015

Understanding User Sharing

Open topic with navigation

Understanding User Sharing

Set organization-wide defaults for internal and external user records. Then, extend access using sharing rules based on membership to public groups, roles, or territories, or use manual sharing to share individual user records with other users or groups.
Available in: Professional, Enterprise, Performance, Unlimited, and Developer Editions

When you enable user sharing, users can see other users in search, list views, and so on only if they have Read access on those users.

Review these considerations before you implement user sharing.
“View All Users” permission
This permission can be assigned to users who need Read access to all users, regardless of the sharing settings. If you already have the “Manage Users” permission, you are automatically granted the “View All Users” permission.
Organization-wide defaults for user records
This setting defaults to Private for external users and Public Read Only for internal users. When the default access is set to Private, users can only read and edit their own user record. Users with subordinates in the role hierarchy maintain read access to the user records of those subordinates.
User sharing rules
General sharing rule considerations apply to user sharing rules. User sharing rules are based on membership to a public group, role, or territory. Each sharing rule shares members of a source group with those of the target group. You must create the appropriate public groups, roles, or territories before creating your sharing rules. Users inherit the same access as users below them in the role hierarchy.
Manual sharing for user records
Manual sharing can grant read or edit access on an individual user, but only if the access is greater than the default access for the target user. Users inherit the same access as users below them in the role hierarchy. Apex managed sharing is not supported.
User sharing for external users
Users with the “Manage External Users” permission have access to external user records for Partner Relationship Management, Customer Service, and Customer Self-Service portal users, regardless of sharing rules or organization-wide default settings for User records. The “Manage External Users” permission does not grant access to guest or Chatter External users.
User Sharing Compatibility
When the organization-wide default for the user object is set to Private, User Sharing does not fully support these features.
  • Chatter Messenger is not available for external users. It is available for internal users only when the organization-wide default for the user object is set to Public Read Only.
  • Customizable Forecasts—Users with the "View All Forecast" permission can see users to whom they don't have access.
  • Salesforce CRM Content—A user who can create libraries can see users they don't have access to when adding library members.
  • Standard Report Types—Some reports based on standard report types expose data of users to whom a user doesn’t have access. For more information, see Controlling Standard Report Visibility.
© Copyright 2000–2014 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.

 

with sharing and without sharing

Open topic with navigation

Using the with sharing or without sharing Keywords

Use the with sharing or without sharing keywords on a class to specify whether or not to enforce sharing rules.

The with sharing keyword allows you to specify that the sharing rules for the current user be taken into account for a class. You have to explicitly set this keyword for the class because Apex code runs in system context. In system context, Apexcode has access to all objects and fields— object permissions, field-level security, sharing rules aren’t applied for the current user. This is to ensure that code won’t fail to run because of hidden fields or objects for a user. The only exceptions to this rule are Apex code that is executed with the executeAnonymous call and Chatter in Apex. executeAnonymous always executes using the full permissions of the current user. For more information on executeAnonymous, seeAnonymous Blocks.

Use the with sharing keywords when declaring a class to enforce the sharing rules that apply to the current user. For example:

public with sharing class sharingClass {    // Code here    }

Use the without sharing keywords when declaring a class to ensure that the sharing rules for the current user are not enforced. For example:

public without sharing class noSharing {    // Code here    }
Some things to note about sharing keywords:
  • The sharing setting of the class where the method is defined is applied, not of the class where the method is called. For example, if a method is defined in a class declared with with sharing is called by a class declared with without sharing, the method will execute with sharing rules enforced.
  • If a class isn’t declared as either with or without sharing, the current sharing rules remain in effect. This means that if the class is called by a class that has sharing enforced, then sharing is enforced for the called class.
  • Both inner classes and outer classes can be declared as with sharing. The sharing setting applies to all code contained in the class, including initialization code, constructors, and methods.
  • Inner classes do not inherit the sharing setting from their container class.
  • Classes inherit this setting from a parent class when one class extends or implements another.
© Copyright 2000–2014 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.

 

Sunday 11 January 2015

How to Auto refresh a page one time.

<script type="text/javascript">  $(document).ready(function(){    //Check if the current URL contains '#'   if(document.URL.indexOf("#")==-1)  {  // Set the URL to whatever it was plus "#".  url = document.URL+"#";  location = "#";    //Reload the page  location.reload(true);    }  });  </script>