Sunday 23 November 2014

How to convert integer to string in apex

Example of conversion of integer to string

      integer i=123;

      string s1=string.valueof(i);



Example of conversion of string to integer

    string s='123';

    integer i=integer.valueof(s);

capitalize()
Returns the current String with the first letter changed to title case.

String s = 'varaprasad';
String s2 = s.capitalize();
System.debug('convert first letter to capitalize' +s2);

center(Integer)
Returns a version of the current String of the specified size padded with spaces on the left and right, so that it appears in the center. If the specified size is smaller than the current String size, the entire String is returned without added spaces.

String s1 = 'hello';
String s3 = s1.center(9);
System.debug('.put center..' +s3);




Visualforce Actionsupport examples



<apex:page controller="actionSupport6">
  <apex:form >
      <apex:outputPanel id="test">
          <apex:pageBlock >
              Enter Text1:<apex:inputText value="{!text1}"/>
                            <br/><br/><br/><br/>
            
              Enter Text2:<apex:inputText value="{!text2}">
                                <apex:actionSupport event="onmouseover" action="{!CallMethod}" reRender="test"/>
                          </apex:inputText>
          </apex:pageBlock>
      </apex:outputPanel>
  </apex:form>
</apex:page>


public class actionSupport6
{

    public String text1{get;set;}
    public String text2{get;set;}
    
    public void CallMethod()
    {
       
        text2 = text1;
    } 
}


===============================================================





<apex:page standardController="Contact" extensions="ActionSupport">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection id="appraiserInfo">
                <apex:inputField value="{!Contact.firstname}"/>

               </apex:pageBlockSection>
                 <apex:inputField label="Company" value="{!contact.AccountId}">
                      <apex:actionSupport action="{!UpdateContactDetails}"  event="onchange" rerender="appraiserInfo" />
                  </apex:inputField>
        </apex:pageBlock>
    </apex:form>
 
</apex:page>

===========================================================

public class ActionSupport {

    public contact conObj;
    public ActionSupport(ApexPages.StandardController controller)
    {
        conObj=(Contact)controller.getRecord();
    }
    public void UpdateContactDetails()
    {
        system.debug('Method is Calling with id===>'+conObj.Accountid);
       
        Account Varacc=[select id,name from Account where id=:conObj.Accountid];
        conObj.firstname=Varacc.name;
    }

}


Wednesday 12 November 2014

Difference between “apex:dataTable” and “apex:pageBlockTable”


Both component is used to render data in tabular format. dataTable will render records in simple HTML table format whereas the “pageBlockTable” possess default look and feel of salesforce standard CSS and must be written inside “apex:pageBlock” componet.
You can read more here.

PageBlockTable:
PageBlockTable should be defined inside pageblock or pageblocksection.
PageBlockTable uses standard styles sheets to design a visualpage.
It has the  required attribute "value".
Column headers  will be displayed automatically.

DataTable:
No need to write inside pageblock or pageblocksection.
There is no required value.
The  data can be displayed using  custom style sheets.
 we need to specify column headers explicitly.




Tuesday 11 November 2014

Standard controller with Extension

Like other Apex classes, controller extensions run in system mode. Consequently, the current user's credentials are not used to execute controller logic, and the user's permissions and field-level security do not apply. However, if a controller extension extends a standard controller, the logic from the standard controller does not execute in system mode. Instead, it executes in user mode, in which the permissions, field-level security, and sharing rules of the current user apply.

You can choose whether a controller extension respects a user's organization-wide defaults, role hierarchy, and sharing rules by using the with sharing keywords in the class definition.

controller extension is any Apex class containing a constructor that takes a single argument of type ApexPages.StandardController or CustomControllerName, where CustomControllerName is the name of a custom controller you want to extend.



            The value of the <apex:outputText> component renders as varam. Overrides are defined by whichever methods are defined in the “leftmost” extension, or, the extension that is first in the comma-separated list. Thus, the Prasad  method of ExtOne is overriding the method of ExtTwo..

<apex:page standardController="Account" extensions="exte1,exte2"  sidebar="false">
    <apex:form >
    <apex:outputText value="{!prasad}"></apex:outputText>
    </apex:form>
</apex:page>

public class exte1 {

    public exte1(ApexPages.StandardController controller) {

    }
    public string getprasad(){
    return 'varam';
    }

}

public class exte2 {

    public exte1(ApexPages.StandardController controller) {

    }
    public string getprasad(){
    return 'varam1';
    }

}


Monday 10 November 2014

Difference b/w External ID & Unique ID

External ID
This is a field that usually references an ID from another (external) system. For instance, if the customer has an Oracle Financials system that they will be linking with salesforce.com, it may be easier for them to be able to refer to the Oracle ID of account records from within salesforce. So they would create an external ID in salesforce.com and they would load the Oracle ID into that field for each account. They can then refer to that ID field, rather than the salesforce.com id.

Additionally, if you have an external ID field, the field becomes searchable in the sidebar search. You also can use the upsert API call with the extenal ID to refer to records.

You can have multiple records with the same external ID (though it is not reccomended, as it will defeat the purpose of the external id) 

Unique ID field

This is a setting for the field that will prevent you from using the same value in multiple records for the unique field. So if I create a 5 character text field and make it unique, and I create a record with the value "12345" I will not be able to create another record with that same value in the unique field. If I try to do so, I will get an error saying that the value is already in use.

Often, External Ids are set with the unique property so that the IDs will be unique to each record.

Choosing Workflow or Trigger for Field Updates

Keep in mind that you should always use a workflow when possible!  Only use triggers when you cannot accomplish something using a workflow.

See below for which to use and why:

----Master-detail Relationship----

1) Updating parent picklist value based on child picklist values (Workflow or Trigger)
>> Workflow, because with master-detail relationship a child object can update the parent

2) Updating child picklist value based on parent picklist values (Workflow or Trigger)
>> Trigger, because you cannot update all children records from a workflow rule, no mater what the relationship is

----Lookup Relationship----
 
3) Updating parent picklist value based on child picklist values (Workflow or Trigger)
>> Trigger, because you can only update the parent record in a workflow if it is a master-detail relationship

4) Updating child picklist value based on parent picklist values (Workflow or Trigger)
>> Trigger, because you cannot update all children records from a workflow rule, no mater what the relationship is

----No Relationship Between Objects----

5) Updating parent picklist value based on child picklist values (Workflow or Trigger)
>> Trigger, because without a relationship the workflow will not know which record to change

6) Updating child picklist value based on parent picklist values (Workflow or Trigger)
>> Trigger, because without a relationship the workflow will not know which record to change


Enjoy with Salesforce.....

Complete Salesforce CPQ training Free videos

Salesforcestart:: We are excited to announce that our YouTube channel, Salesforcestart, is your one-stop-shop for all things Salesforce CPQ!...