Monday, 29 December 2014

Some of Setup Objects in Salesforce.com

Hi,
The following are the Setup Objects in Salesforce.com.
I got this  from "http://www.salesforce.com/us/developer/docs/api_toolingpre/api_tooling.pdf".
You can get more information from the above link.

Object
Descripion
CompactLayout
Represents the values that define a compact page layout.
CustomField
Represents a custom field on a custom object that stores data unique to your
organization.
CustomObject
Represents a custom object that stores data unique to your organization. Includes access to the associated CustomObject object and related fields in Salesforce Metadata API.
EmailTemplate
Represents an email template
EntityDefinition
Provides row based access to metadata about standard and custom objects.
FieldDefinition
Provides row based access to metadata about standard and custom fields of
standard and coustom objects.
FlexiPage
Represents a Lightning Page. A Lightning Page is the home page for an app that appears as a menu item in the Salesforce1 navigation menu. Includes access to the associated FlexiPage object in the Salesforce Metadata API.
Layout
Represents a page layout. For more information, see “Managing Page Layouts” in the Salesforce online help.
MenuItem
Represents a menu item.
Profile
Represents a user profile. A profile defines a user's permission to perform different functions within Salesforce.
ProfileLayout
Represents a profile layout.
QuickActionDefinition
Represents the definition of a quick action.
QuickActionList
Represents a list of quick actions.
QuickActionListItem
Represents an item in a quick action list
RecordType
Represents a custom record type.
User
Represents a user.
ValidationRule
Represents a formula that is used for specifying when a criteria is met. This includes both validation rules and workflow rules. Includes access to the associated ValidationRule object in the Salesforce Metadata API.
WorkflowAlert
Represents a workflow alert. A workflow alert is an email generated by a workflow
rule or approval process and sent to designated recipients
WorkflowFieldUpdate
Represents a workflow field update
WorkflowOutboundMessage
Represents an outbound message. An outbound message is a workflow, approval, or milestone action that sends the information you specify to an endpoint you designate, such as an external service. Outbound messaging is configured in the
Salesforce setup menu. Then you must configure the external endpoint. You can
create a listener for the messages using the SOAP API.
WorkflowRule
Represents a workflow rule that is used to fire off a specific workflow action when
the specified criteria is met. Includes access to the associated WorkflowRule object in Salesforce Metadata API.
WorkflowTask
Represents a workflow task that is used to fire off a specific workflow action when
the specified criteria is met. Includes access to the associated WorkflowRule object
in Salesforce Metadata API.

Sunday, 14 December 2014

Generation of JSON String , Deserialize and Serialize

Hi,
We have a small example ,how to generate json .The below code is used for  generating json string.
To generate JSON string we have to use "JSONGenerator " and "createGenerator(true)" method.



JSONGenerator gen=JSON.createGenerator(true);
gen.writeStartArray();
gen.writeStartObject();
gen.writenumberField('StudentNumber',1);
gen.writeStringField('StudentName','Balaji');
gen.writeEndObject();
gen.writeStartObject();
gen.writenumberField('StudentNumber',2);
gen.writeStringField('StudentName','Shilpa');
gen.writeEndObject();
gen.writeEndArray();
String jsonString= gen.getAsString();
System.debug('jsonString:'+jsonString);

Output:
=====
jsonString:[ {
"StudentNumber" : 1,
"StudentName" : "Balaji"
 }, {
  "StudentNumber" : 2,
   "StudentName" : "Shilpa"
  } ]

To deserialize the above json string ,we have to prepare a class as shown below.
Class:
======
public class Studentscls{
    public Class StudentDetail{
        public integer StudentNumber{get;set;}
        public String StudentName{get;set;}  
    }
}

Execution:
------------
To deserialize JSON string we have "deserialize" method as shown below by using above class.

List<Studentscls.StudentDetail>  studentList = (List<Studentscls.StudentDetail>)JSON.deserialize(jsonString,List<Studentscls.StudentDetail>.class);
System.debug('Deserialized Result:'+studentList);

OuptPut:
======
Deserialized Result:(StudentDetail:[StudentName=Balaji, StudentNumber=1], StudentDetail:[StudentName=Shilpa, StudentNumber=2])

To serialize above list we have to user "serialize()" method as shown below.
--------------------------------------------------------------------------------------------

String studentJSONString=Json.serialize(studentList);
System.debug('Student JSONString:'+studentJSONString);

Output:
=====

Student JSONString:
[{"StudentNumber":1,"StudentName":"Balaji"},{"StudentNumber":2,"StudentName":"Shilpa"}]


Saturday, 6 December 2014

Wrapper List Sorting(Column Sorting) using Comparable Interface

Comparable Interface adds sorting support for Lists that contain non-primitive types, that is, Lists of user-defined types.

Whenever we want to achieve column sorting in wrapper list then we have to implement Comparable and we should define the "compareTo" method as shown below.

Here i am querying the account object records and passing them to wrapper list for giving example. Basically a wrapper class can contain combination of different types. For all such type of things also it will work.Comparable interface is very useful for sorting wrapper list.


Class:
======

public class AccountClass {

    public List<AccountWrappercls> wrapperList{get;set;}
    public string sortableField{get;set;}
    public string sortOrder{get;set;}
    public string previoussortfield{get;set;}
    public AccountClass(){
        wrapperList = new List<AccountWrappercls>();
        sortableField = 'name';
        sortOrder = 'asc';
        previoussortfield =sortableField;
        for(Account actobj:[select id,name,ActiveDate__c,ACnumber__c from Account where ActiveDate__c!=null and ACnumber__c!=null]){
                AccountWrappercls wrapObj = new AccountWrappercls(actobj.ActiveDate__c,actobj.Acnumber__c,actobj.name);
                wrapperList.add(wrapObj);
        }           
        wrapperList.sort();
    }
    public pagereference doSort(){      
        //sortorder='asc';      
        if(previoussortfield == sortableField){
            sortorder='desc';
            previoussortfield=null;
        }
        else{
            sortorder='asc';            
            previoussortfield=sortableField;
        }
        System.debug('sortableField:::'+sortableField);
        System.debug('sortOrder::'+sortOrder);
        AccountWrappercls.sortableField = sortableField;
        AccountWrappercls.sortorder = sortOrder;        
        wrapperList.sort();
        return null;
    }
}

Class Which Implements Comparable interface:
======================================
public  class AccountWrappercls implements comparable{
  public Date createdDate {get;set;}
  public decimal num1 {get;set;}
  public String  name {get;set;}
  public static String sortableField='name';
  public static String sortOrder='asc';  
  public AccountWrappercls(Date createdDate,decimal num1,String  name){
      this.createdDate = createdDate;
      this.num1 = num1;
      this.name =name;
      //this.sortableField = sortableField;
      //this.sortOrder = sortOrder;
  }
   public  Integer compareTo(Object compareTo) {
     AccountWrappercls compWrap = (AccountWrappercls)compareTo;
     if(sortOrder == 'asc'){
    if(sortableField == 'num1'){     
            if (num1 == compWrap.num1) return 0;
          if (num1 > compWrap.num1) return 1;
          return -1;        
    }
    if(sortableField == 'name'){     
            if (name == compWrap.name) return 0;
          if (name > compWrap.name) return 1;
          return -1;        
    }
    if(sortableField == 'createdDate'){     
            if (createdDate == compWrap.createdDate) return 0;
          if (createdDate > compWrap.createdDate) return 1;
          return -1;        
    }}else{
      if(sortableField == 'num1'){     
            if (num1 == compWrap.num1) return 0;
          if (num1 > compWrap.num1) return -1;
          return 1;        
    }
    if(sortableField == 'name'){     
            if (name == compWrap.name) return 0;
          if (name > compWrap.name) return -1;
          return 1;        
    }
    if(sortableField == 'createdDate'){     
            if (createdDate == compWrap.createdDate) return 0;
          if (createdDate > compWrap.createdDate) return -1;
          return 1;        
    }
    }
    
    return null;
    }    
    
}
Visualforce Page:
==============
<apex:page controller="AccountClass">
 <apex:form >
  <apex:pageBlock id="pb">
   <apex:pageBlocKTable value="{!wrapperList}" var="wrapObj">
    <apex:column >
     <apex:facet name="header">
      <apex:commandLink value="Name {!IF(sortableField=='name',IF(sortOrder='asc','▼','▲'),'')}" action="{!doSort}" rerender="pb">
       <apex:param name="name" value="name" assignTo="{!sortableField}"></apex:param>
      </apex:commandLink>
     </apex:facet>
     
      <apex:outputText value="{!wrapObj.name}"/>
     
    </apex:column>
    <apex:column >
     <apex:facet name="header">
      <apex:commandLink value="Ac Number {!IF(sortableField=='num1',IF(sortOrder='asc','▼','▲'),'')}" action="{!doSort}" rerender="pb">
        <apex:param name="num1" value="num1" assignTo="{!sortableField}"></apex:param>
      </apex:commandLink>
     </apex:facet>
     
      <apex:outputText value="{!wrapObj.num1}"/>
         
    </apex:column>
    <apex:column >
     <apex:facet name="header">
      <apex:commandLink value="Date {!IF(sortableField=='createdDate',IF(sortOrder='asc','▼','▲'),'')}" action="{!doSort}" rerender="pb">
       <apex:param name="createdDate" value="createdDate" assignTo="{!sortableField}"></apex:param>
      </apex:commandLink>
     </apex:facet>
     
      <apex:outputText value="{0, date, MM/d/yyyy}">
       <apex:param value="{!wrapObj.createdDate}"/>
      </apex:outputText>
        
    </apex:column>
   </apex:pageBlocKTable>
  </apex:pageBlock>
 </apex:form>
</apex:page>                                        


                                        
Output:
======