Friday, 22 April 2016

Service cloud Phone Systems









Allows for telephony to be integrated with the support/call center application.
•PBX – Private Branch Exchange system is the initial starting point for all calls into the support center. Allows organizations to receive multiple phone calls at one time
 
 
•ACD – Automatic Call Distributor uses intelligent routing to direct calls to the appropriate agent.
 
      The Automatic Call Distributor (ACD), also referred to as the phone switch, provides the ability to route calls to the most appropriate customer service representative by matching specific types of calls to available representatives who have certain designated customer servicing skills.  ACD software can be used to generate standard and customized reports for evaluating real-time and historical call statistics.

 
•IVR – An Interactive Voice Response system will prompt customer/caller for reason for calling.
 
      Interactive Voice Response (IVR), is used to provide call prompting and self-service functions to customers using the phone channel.  Call prompting can be used to identify the caller and type of request prior to call routing for more effective service.  Self-service options allow the customer to perform relatively simple servicing tasks without speaking to a customer service representative.
 
 
 

Wednesday, 13 April 2016

Rest API in Salesforce | Execute Rest API on workbench | Test class for Rest API


Now learning in salesforce to much easy as compare to our time. The Salesforce Trailhead now offers a fun way to learn everything related to Salesforce Integration
1) https://developer.salesforce.com/trailhead/module/apex_integration_services?utm_campaign=trailhead&utm_source=sfdc&utm_medium=chatter-success

Pleae check above Trailhead module for detail knowledge of web service.

REST API

The Force.com REST API lets you integrate with Force.com applications using simple HTTP methods, in either XML or JSON formats, making this an ideal API for developing mobile applications or external clients. Force.com also supports Apex REST, which lets you create Web services on Force.com using Apex





Create REST Apex class


@RestResource(urlMapping='/api/Account/*')
global with sharing class MyFirstRestAPIClass
{
@HttpGet
global static Account doGet()
{
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String AccNumber = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE AccountNumber = :AccNumber ];
return result;
}

@HttpDelete
global static void doDelete()
{
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String AccNumber = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE AccountNumber = :AccNumber ];
delete result;
}

@HttpPost
global static String doPost(String name,String phone,String AccountNumber )
{
Account acc = new Account();
acc.name= name;
acc.phone=phone;
acc.AccountNumber =AccountNumber ;
insert acc;

return acc.id;
}

}


As you can see, the class is annotated with @RestResource(urlMapping='/api/Account/*).
The base endpoint for Apex REST is
https://instance.salesforce.com/services/apexrest/.

The URL mapping is appended to the base endpoint to form the endpoint for your REST service.
For example, in the class example, the REST endpoint is
https://instance.salesforce.com/services/apexrest/api/Account/.


Test Class for REST API

@IsTest
private class MyFirstRestAPIClassTest
{
    static testMethod void testGetMethod()
    {
        Account acc = new Account();
        acc.Name='Test';
        acc.AccountNumber ='12345';
        insert acc;
        
        RestRequest request = new RestRequest();
        request.requestUri ='/services/apexrest/api/Account/12345';
        request.httpMethod = 'GET';
        RestContext.request = request;
        Account acct = MyFirstRestAPIClass.doGet();
        System.assert(acct != null);
        System.assertEquals('Test', acct.Name);
        
    }

    static testMethod void testPostMethod()
    {
        RestRequest request = new RestRequest();
        request.requestUri ='/services/apexrest/api/Account/12345';
        request.httpMethod = 'POST';
        RestContext.request = request;
        String strId = MyFirstRestAPIClass.doPost('Amit','2345678','12345');
        System.assert(strId !=null );
    }

    static testMethod void testDeleteMethod()
    {
        Account acc = new Account();
        acc.Name='Test';
        acc.AccountNumber ='12345';
        insert acc;
        
        RestRequest request = new RestRequest();
        request.requestUri ='/services/apexrest/api/Account/12345';
        request.httpMethod = 'DELETE';
        RestContext.request = request;
        MyFirstRestAPIClass.doDelete();
        
        List<Account> ListAcct = [SELECT Id FROM Account WHERE Id=:acc.id];
        System.assert(ListAcct.size() ==0 );
    }

}


Execute your Apex REST class in workbench

Step 1:- Open https://workbench.developerforce.com/
Step 2:- Select Environment as Production and select the checkbox to agree the terms and condition then select Login with Salesforce.


NOTE:- If you are already login then only above step will work other wise you need to enter user name and password.

Step 3:- In the Workbench tool select Utilities > REST Explorer



Step 4:- In the REST Explorer window paste the following url in the box

Create Account Call
Method :- Post
URL :- /services/apexrest/api/Account
Body:-
{
  "name" : "Test Rest",
  "phone" : "123456789",
  "AccountNumber" : "12345"

}



Get Account Call

Method :- Get
URL :- /services/apexrest/api/Account/12345
Body:- NA




Please check below post for more information
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_methods.htm
2) https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_REST_API





<<PREVIOUS       NEXT>>







Tuesday, 5 April 2016

Mass Delete | Delete from List View


Step 1:-  Create a Mass Delete button on account object 

Setup->Accounts->Buttons, Links, and Actions


Then Click on New Button or Link Button.


Then add below code in your button
{!REQUIRESCRIPT("/soap/ajax/9.0/connection.js")}

var records = {!GETRECORDIDS( $ObjectType.Account )};

if (records[0] == null) {
alert("Please select at least one record.")
}
else
{
var errors = [];
var result = sforce.connection.deleteIds(records);
if (result && result.length)
{
var numFailed = 0;
var numSucceeded = 0;
for (var i = 0; i < result.length; i++)
{
var res = result[i];
if (res && res.success == 'true')
{
numSucceeded++;
}
else
{
var es = res.getArray("errors");
if (es.length > 0)
{
errors.push(es[0].message);
}
numFailed++;
}
}
if (numFailed > 0)
{
alert("Failed: " + numFailed + "\nSucceeded: " + numSucceeded + " \n Due to: " + errors.join("\n"));
}
else
{
alert("Number of records deleted: " + numSucceeded);
}
}
window.location.reload();
}

Step 2:- Add button on List view

Setup -> Accounts->Account Search Layouts


Then add button in Account List view

Step 3:- Finally ready to use :-



Reference document which i followed :-
1) https://help.salesforce.com/HTViewHelpDoc?id=links_useful_custom_buttons_mass_delete.htm

You can install custom buttons from the Mass Delete app at http://sites.force.com/appexchange.
Thanks
Amit Chaudhary

Wednesday, 30 March 2016

Wrapper Class in Salesforce | Select All Java Script | Add to Grid

Problem :- 
How can I display a table of records with a check box and then process only the records that are selected?

Solution:- 
Wrapper class.

A wrapper or container class is a class, data structure, or an abstract data type whose instances are a collections of other objects.It is a custom object defined by Salesforce developer where he defines the properties of the wrapper class. Within Apex & Visualforce this can be extremely helpful to achieve many business scenarios within the Salesforce CRM software.

Using Wrapper classes we can have the ability to check few records from the displayed list and process them for some action




public with sharing class WrapperDemoController {
   
    public List<AccountWrapper> listAccountWrapper {get; set;}
    public List<Account> selectedAccounts{get;set;}

    public WrapperDemoController ()
    {
            listAccountWrapper = new List<AccountWrapper>();
            searchRecord();
    }
   
    public void searchRecord()
    {
        listAccountWrapper.clear();
            for(Account a: [select Id, Name,BillingState, Website, Phone ,Active__c from Account limit 10])
            {
                listAccountWrapper.add(new AccountWrapper(a));
            }
    }

    public void processSelected()
    {
        selectedAccounts = new List<Account>();
        selectedAccounts.clear();
        for(AccountWrapper wrapAccountObj : listAccountWrapper)
        {
            if(wrapAccountObj.selected == true)
            {
                selectedAccounts.add(wrapAccountObj.acc);
            }
        }
    }

    public void ActivateData()
    {
        for(Account acc : selectedAccounts )
        {
            acc.Active__c ='Yes';
        }
        update selectedAccounts ;
        searchRecord();
    }

    public void DeActivateData()
    {
        for(Account acc : selectedAccounts )
        {
            acc.Active__c ='No';
        }
        update selectedAccounts ;
        searchRecord();
    }
   


    // This is our wrapper/container class.
    public class AccountWrapper
    {
        public Account acc {get; set;}
        public Boolean selected {get; set;}
        public AccountWrapper(Account a)
        {
            acc = a;
            selected = false;
        }
    }

}
Page

<apex:page controller="WrapperDemoController">
    <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
    <apex:form >
        <apex:pageBlock id="PB1">
            <apex:pageBlockButtons >
                <apex:commandButton value="Add to Grid" action="{!processSelected}" rerender="table2,PB2"/>
            </apex:pageBlockButtons>

            <apex:pageblockSection title="All Accounts" collapsible="false" columns="1">
                <apex:pageBlockTable value="{!listAccountWrapper}" var="accWrap" id="table" title="All Accounts">
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                        <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                    </apex:column>
                    <apex:column value="{!accWrap.acc.Name}" />
                    <apex:column value="{!accWrap.acc.BillingState}" />
                    <apex:column value="{!accWrap.acc.Phone}" />
                    <apex:column value="{!accWrap.acc.Active__c}" />
                </apex:pageBlockTable>


            </apex:pageblockSection>
        </apex:pageBlock>
       
        <apex:pageBlock id="PB2" >
            <apex:pageBlockButtons >
                <apex:commandButton value="Activate" action="{!ActivateData}" rerender="PB1,PB2"/>
                <apex:commandButton value="DeActivate" action="{!DeActivateData}" rerender="PB1,PB2"/>
            </apex:pageBlockButtons>

                <apex:pageBlockTable value="{!selectedAccounts}" var="c" id="table2" title="Selected Accounts">
                    <apex:column value="{!c.Name}" headerValue="Account Name"/>
                    <apex:column value="{!c.BillingState}" headerValue="Billing State"/>
                    <apex:column value="{!c.Phone}" headerValue="Phone"/>
                    <apex:column value="{!c.Active__c}" headerValue="Active"/>
                </apex:pageBlockTable>
        </apex:pageBlock>

       
    </apex:form>
</apex:page>


Some Other useful like :-
1) https://developer.salesforce.com/page/Wrapper_Class

Thanks
Amit Chaudhary

 

Saturday, 12 March 2016

Dynamic Query | Select All Field in SOQL | Select * Form Account


Dynamic Select * Form Account Query in salesforce


public Void GetAllField()
{
String query ='';
String SobjectApiName = 'Account';
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();

String strFields = '';

for(String fieldName : fieldMap.keyset() )
{
if(strFields == null || strFields == '')
{
strFields = fieldName;
}else{
strFields = strFields + ' , ' + fieldName;
}
}

query = 'select ' +
strFields + ' from ' + SobjectApiName + ' Limit 10 ';

List <Account> accList = Database.query(query);

}


Thanks ,
Amit Chaudhary