Wednesday 3 December 2014

REST WEB SERVICES

                  REST WEB SERVICES



REST:
            Stands for: Representational state  transfer
Rest is :
Ø Stateless
Ø Client – server based
Ø HTTP Based
Ø It is not a protocol
Ø Support Both JSON and XML

@RestResource:
In Rest web services we need to implement @Rest Resource annotation .
We need to map endpoint URL  here   .
Syntax: @RestResource(urlMapping =’/endpoint url/*’..
Then we need to implement class with following Http methods
@Httppost  = create
@Httpget = read
@Httpput = update
@Httpatch = update
@Httpdelete = delete

Then we need implement following
Restcontext : it is a container class it holds  twoobjects
Restrequest:  params,requestbody,requestpath
Restresponse: return messages etc

@RestResource(urlMapping = '/v29/account/*')
    global class restwebservices{
   
    @Httpget
    global static account getdetails(){
        Restrequest req = restcontext.request;
        Restresponse res = restcontext.response;
        string name = req.requestURI.substring(req.requestURI.lastindexof('/')+1);
        account a = [select id,name,phone,type,website,rating from account where name =: name];
        return a;
   
    }
    @Httppost
    global static id createaccont(string name,string phone,string website){
        Restrequest req = restcontext.request;
        Restresponse res = restcontext.response;
        account a = new account();
        a.name = name;
        a.phone = phone;
        a.website = website;
        insert a;
        return a.id;
        }
  }
    


                                                                                 




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.....

Thursday 30 October 2014

User Licenses in Salesforce

User Licenses:

A user license determines the baseline of features that the user can access. Every user must have exactly one user license. You assign user permissions for data access through a profile and optionally one or more permission sets.

Salesforce has many license types which can get confusing.  To keep things straight, we’ll start with a brief summary of license types and then give more detail below.

Salesforce’s different user licenses give users different access to your data.  (The license type determines which profiles and permission sets are available to the user.)
To view a list of the active user licenses in your Salesforce org,  click Your Name | Setup | Company Profile |Company Information
Here’s the summary of Salesforce user license types:
Salesforce
Full access to standard CRM, custom apps, and AppExchange apps.
Salesforce Platform
Custom apps & core objects (Accounts, Contacts, etc) only; no CRM (no Opportunities or Forecasts).
Force.com – One App
One custom app & read-only for accounts and Contacts; no CRM.
Knowledge Only User
Salesforce Knowledge app only.
Chatter Free
Access to Chatter for people in your company without a Salesforce license.  No additional cost.
Chatter External
Allows your customers to use Chatter groups.  No additional cost.

Chatter Only (aka Chatter Plus).



Standard Profiles In Salesforce

There are six (6) Salesforce standard user profiles. 
     Additional standard profiles will appear when certain conditions are met within an organization, such as enabling Chatter, Partner Portal, Customer Portal, or Sites



Standard Profiles which mostly used are:

       ·         System Administrator
·         Standard User
·         Read Only
·         Solution Manager
·         Marketing User
·         Contract Manager



Tuesday 28 October 2014

Restricting Users through Validation rules

Restricting Users through Validation rules:

 Using Profiles and Userids We will restrict users in Salesforce.



IF( ISPICKVAL(<FIELD_NAME>, "<FIELD _VALUE>") && $User.Id = "<USERID_NUMBER>", TRUE, FALSE)


For example, this is the formula I used:

1.IF( ISPICKVAL(Type, "prospect") && $User.Id="005900000034iOC",TRUE,FALSE)

 2.IF(OR( ISPICKVAL(Type, "prospect"),ISPICKVAL(Type,"other")) && $User.Id="005900000034iOC",TRUE,FALSE)



3.AND(  OR (ISNEW(), ISCHANGED (Type)),  OR (ISPICKVAL(PRIORVALUE(Type), "Customer"), ISPICKVAL(Type,"Customer")),  OR ($User.Username <> "xxxx@nnnnn.com"),  OR ($User.Username <> "xxxx@nnnnn.com"))




Sunday 26 October 2014

Tracking Field History in Salesforce through SOQL and UI

Tracking Field History


You can select certain fields to track, and display the field history in the History related list of an object. You can track the field history of custom objects, as well as the history of the following standard objects:

§  Accounts
§  Cases
§  Contacts
§  Entitlements
§  Service contracts
§  Contract line items
§  Contracts
§  Leads
§  Opportunities
§  Articles
§  Solutions


To track field history for custom objects and standard objects.

1.      From Setup, click Create | Objects.
2.      Click Edit next to the name of the custom object.
3.      Select the Track Field History checkbox

  When you enable tracking for an object, be sure to customize your page layouts to include the object’s history related list.

4.      Click Save.
5.      Click Set History Tracking in the Custom Fields & Relationships section.
This section allows you to set a custom object’s history for both standard and custom fields.
6.      Choose the fields you want tracked.
You can select up to 20 standard and custom fields per object. You can’t track:
§  Formula, roll-up summary, or auto-number fields
§  Created By and Last Modified By
7.      Click Save.
Salesforce tracks history from this date and time forward. Changes made prior to this date and time are not included.



 SOQL to Track History.


Select Amount, leadsource, (Select OldValue, NewValue From histories) From Opportunity


SELECT name,CreatedDate,Fees__c,languages__c,(select field,oldvalue,newvalue from histories) FROM student__c

Custom Object:





Standard Object:



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!...