Thursday, 17 May 2018

Create Super Clone Button To clone 3 level of Hierarchy


Create Super Clone Button To clone 3 level of Hierarchy :

Object Schema 


Create JavaScript Button on Account Detail page :


{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}

try{
alert("Entered try");
var accId='{!Account.Id}';
alert('____1___'+accId);
sforce.apex.execute("superClone","createClone",{accId:accId});
alert('____2___'+accId);
txt="Clones Create";
alert(txt);
}
catch(err) {
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.description + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
}

Apex class Code :Class Name superClone 


global class superClone {
    
    static Map<Id,Id> newoldcon=new Map<Id,Id>();
    webservice static void createClone(String accId)
    {
        system.debug(accId);
        Account acc= [SELECT ID, Name FROM Account WHERE Id = :accId];
        system.debug(acc);        
        Account acccopy=acc.clone(false,true);
        acccopy.Name=acc.Name+'Clonedcopy';
        insert acccopy;  // Grand Parent
        
        List<Contact> con = [SELECT Id, LastName, AccountId FROM Contact WHERE AccountId = : acc.Id];
        List<Contact> consdup= new List<Contact>(); 
        List<Id> cid = new List<Id>();
        if(con!=null)
        {
            for(Contact c:con)
            {
                cid.add(c.Id);
                Contact concopy=c.clone(false,true);
                concopy.AccountId=acccopy.Id;
                concopy.LastName =c.LastName + 'clonecopy';
                consdup.add(concopy);
            }
        }
        Database.insert(consdup);  // Parent
      
        if(consdup!=null && cid!=null)
        {
             for(ID i:cid)
            {
            for(Contact c1:consdup)
            {
                newoldcon.put(i,c1.id);
                
            }
            //createDivCon(i);
       
            } 
        }
        System.debug('newoldcon++++++ old id '+newoldcon.keySet());     
        List<Divsional_Contact__c> divlist=[SELECT Id,Name,Contact_Parent__c FROM Divsional_Contact__c WHERE Contact_Parent__c=:newoldcon.keySet()];
       System.debug('divisional list-------------******'+divlist);
        List<Divsional_Contact__c> divlist1=new List<Divsional_Contact__c>();
        if(divlist!=null)
        {
            for(Divsional_Contact__c d: divlist)
        {
             Divsional_Contact__c divcopy=d.clone(false,true);
            divcopy.Contact_Parent__c=newoldcon.get(d.Contact_Parent__c);
            divcopy.Name=d.Name+'Cloned Copy';
            divlist1.add(divcopy);
        }
        }  System.debug('--------------- ++++++divlist1 list'+divlist1);
           Database.insert(divlist1); 
       
        
    }



}

Credits goes to @Preeti

Monday, 16 April 2018

Salesforce Service Cloud Certification Topics


  • Industry Knowledge: 66%
  • Implementation Strategies: 54%
  • Service Cloud Solution Design: 33%
  • Knowledge Management: 50%
  • Interaction Channels: 20%
  • Case Management: 42%
  • Contact Center Analytics: 0%
  • Integration and Data Management: 100% 
  • --------------------------
  • omni channel salesforce
  • Quick Text
  • Macros
  • Publisher action
  • Live Agents
  • Chatter questions
  • Entitlement implement
  • Enable Salesforce social profile on contacts
  • SOS Video Chat
  • Developer k pro sandbox
  • Set up milestones
  • Enable HISTORY component within the Salesforce console for service
  • An Enterprise resource planning system
  • Milestones
  • Add the question action to chatter in the community publisher
  • Live agent user profile
  • Field Service Lightning
  • On demand email to Case

Friday, 28 July 2017

Salesforce Jenkins Ant deployment Steps

/**********************************************************************

**********************************************************************/


PREREQUSITES
*************************************************
1. JDK
2. JRE
3. Force.com Migration tool
4. Apache Ant

*************************************************

A. Install ANT
*************************************************
Step 1: Download JRE 6 : Verify the correct installation by executing the following command: java -version
Step 2: Download Ant(version 1.6 or higher) zip file from http://ant.apache.org/bindownload.cgi
Step 3: Download Force.com Migration Tool zip folder from Salesforce Org for which the path is as follows: Develop->Tools->Force.com Migration Tools
Step 4: Copy the "ant-salesforce.jar" file from the above extracted folder and paste it in the lib directory of the installed Ant folder.
Step 5: Set the environment Variables as follows:
        ->System Variables->new>  Variable Name: ANT_HOME
                         Variable Value: C:\Program Files\apache-ant-x.xx.x
->System Variables->new>  Variable Name: JAVA_HOME
                         Variable Value: C:\Program Files\Java\jdk_x.xx.x

        ->System Variables->edit->PATH ->
                                  In PATH, add %JAVA_HOME%\bin and %ANT_HOME%\bin
..... %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;....;%JAVA_HOME%\bin;%ANT_HOME%\bin; .....

Step 6: Verify if 'C:\Program Files\Java\jdk_x.xx.x\lib' contains 'Tools.jar' file.
Step 7: Run the following command in cmd to verify the correct installation of ANT : ant -version

OPTIONAL:
Step 8: have build.xml and build.properties at the src level of moving source file.(ANT checks package.xml of the project src file to know what all things have to migrate).


*************************************************

B. Install Jenkins (on Windows)
*************************************************
If you're running on Windows you might want to run Jenkins as a service so it starts up automatically without requiring a user to log in. Install jenkins using windows package (http://jenkins-ci.org/) or using java web archive (.war) file.
You need to start jenkins engine if you've installed using the .war file. To do this, open command prompt and navigate to the folder where 'jenkins.war' file is located. run the following command:

C:/...>java -jar jenkins.war

If you've installed using windows installer, there's no need to start jenkins engine.
To run Jenkins, open your browser and connect to 'localhost:8080'



*************************************************

C. Configure Jenkins
*************************************************
Once your jenkins is up, goto jenkins > manage jenkins > configure system
Update the JDK and ANT sections with their respective version and path.



*************************************************

D. Configure Jobs
*************************************************
1. Click on 'New Item' and enter item name. Select 'free-style software project'. click 'OK'
2. Goto 'Build' section in the configuration page. Select Ant version.
3. In the Targets field, enter the library and property file path.
Eg:
-lib
D:\...\apache-ant-1.9.2\lib/ant-salesforce.jar
-propertyfile
D:\...../build.properties

4. Click on advanced button. In the 'Build File' field, enter the the path Ant's for build.xml
D:\.....\build.xml

5. In the 'Proprties' field, enter the salesforce parameters used by Ant in build.xml

sf.username = user@xyz.com
sf.password = PasswordSecurityToken
sf.serverurl = login.salesforce.com
sf.checkOnly = false
sf.runAllTests = false
sf.logLevel = None

6. Click Save. Your deployment job is ready to go! Click 'Build Now' to run the deployment job.
*************************************************

Wednesday, 31 August 2016

system.debug statements not appearing in the debug log

system.debug statements not appearing in the debug log


System.debug(LoggingLevel.Info, '___My Variable__'+Variable);













Tuesday, 16 August 2016

Salesforce Helping Hands: Pagination with maintaing the state of selected re...

Salesforce Helping Hands: Pagination with maintaing the state of selected re...: Hi All, I have seen many people implemented pagination using salesforce, but recently I have come across a situation where I have to sele...







First Class Code:
global class CustomIterable implements Iterator<list<AccountInner>>{ 

   List<Account> accs {get; set;} 
   list<AccountInner> accInnerList {get; set;} 
   list<AccountInner> accInnerListRequested {get; set;} 
   AccountInner accInnerObj;
   Integer i {get; set;} 
   public Integer setPageSize {get; set;} 

   public CustomIterable(string sQuery){ 
       //accs = [SELECT Id, Name, NumberOfEmployees FROM Account Limit 36]; 
       accs = Database.Query(sQuery);
       accInnerList = new list<AccountInner>(); 
       accInnerListRequested = new list<AccountInner>();     
       for(Account a : accs) {
            accInnerObj = new AccountInner(false, a);
            accInnerList.add(accInnerObj);
       } 
       setPageSize = 10;
       i = 0; 
   }   

   global boolean hasNext(){ 
       if(i >= accInnerList.size()) {
           return false; 
       } else {
           return true; 
       }
   } 
   
   global boolean hasPrevious(){ 
       system.debug('I am in hasPrevious' + i);
       if(i <= setPageSize) {
           return false; 
       } else {
           return true; 
       }
   }   

   global list<AccountInner> next(){       
       system.debug('i value is ' + i);
       accInnerListRequested = new list<AccountInner>(); 
       integer startNumber;
       integer size = accInnerList.size();
       if(hasNext())
       {  
           if(size <= (i + setPageSize))
           {
               startNumber = i;
               i = size;
           }
           else
           {
               i = (i + setPageSize);
               startNumber = (i - setPageSize);
           }
           
           system.debug('i value is =====' + i);
           system.debug('i value is 2==== ' + (i - setPageSize));
           
           for(integer start = startNumber; start < i; start++)
           {
               accInnerListRequested.add(accInnerList[start]);
           }
       } 
       return accInnerListRequested;
   } 
   
   global list<AccountInner> previous(){      
       accInnerListRequested = new list<AccountInner>(); 
       system.debug('i value is previous before =====' + i);
       integer size = accInnerList.size(); 
       if(i == size)
       {
           if(math.mod(size, setPageSize) > 0)
           {    
               i = size - math.mod(size, setPageSize);
           }
           else
           {
               i = (size - setPageSize);
           } 
       }
       else
       {
           i = (i - setPageSize);
       }
       
       system.debug('i value is previous =====' + i);
       system.debug('i value is 2previous ==== ' + (i - setPageSize));
       
       for(integer start = (i - setPageSize); start < i; ++start)
       {
           accInnerListRequested.add(accInnerList[start]);
       } 
       return accInnerListRequested;
   }   
}

Second Class:
global Class AccountInner
{
    public boolean isSelected {get;set;}
    public Account acc {get;set;}
    
    public AccountInner(boolean isSelected, Account acc)
    {
        this.isSelected = isSelected;
        this.acc = acc;
    }
}

Visual force page :
<apex:page controller="Example1">
  <apex:form >
      <apex:sectionHeader title="Pagination" subtitle="Hi"/>
      <apex:pageBlock >
          <apex:pageBlockSection >
              <apex:pageBlockTable value="{!accInnerObj}" var="inner">
                  <apex:column >
                      <apex:inputCheckbox value="{!inner.isSelected}"/>
                  </apex:column> 
                  <apex:column headerValue="Account"> 
                      <apex:outputText value="{!inner.acc.Name}" />
                  </apex:column>    
              </apex:pageBlockTable>
          </apex:pageBlockSection>
      </apex:pageBlock>
      
      <br/>
      <apex:commandButton value="<<Previous" action="{!previous}" rendered="{!hasPrevious}"/>
      <apex:commandButton value="Next >>" action="{!next}" rendered="{!hasNext}"/>
      
  </apex:form>
</apex:page> 

Corresponding Controller:
public class Example1 {
    
    CustomIterable obj;
    public list<AccountInner> accInnerObj {get;set;}
    
    public Example1 () {       
        string sQuery = 'SELECT Id, Name, NumberOfEmployees FROM Account Limit 36';
        obj = new CustomIterable(sQuery); 
        obj.setPageSize = 10;
        next();
    }
    
    public Boolean hasNext {
        get {
            return obj.hasNext();
        }
        set;
    }
    
    public Boolean hasPrevious {
        get {
            return obj.hasPrevious();
        }
        set;
    }
    
    public void next() {
        accInnerObj = obj.next();
    }
    
    public void previous() {
        accInnerObj = obj.previous();
    }
}  

Wednesday, 22 July 2015

Test class Factory design pattern

Test class Factory design pattern

public class UtileTesClass {



    /*-----setup data for user----*/
    public Static User setupUser()
    {
        Profile prof = [select id from profile where name = 'System Administrator'];
        User user = new User(alias = 'standt', email = 'my123_123@gmail.com', emailencodingkey = 'UTF-8',
                         lastname = 'Test', languagelocalekey = 'en_US', localesidkey = 'en_US',
                         profileid = prof.Id, timezonesidkey = 'America/Los_Angeles',
                         username = 'testuser_123@gmail.com');
        insert user;
        return user;
    }

   
    /*----------------Setup data for Account----*/
    public static Account setupAccount(user MyMnger)
    {      
        Account  acc= new Account();  
        acc.Name='Test Account';
        acc.ShippingStreet ='Royal Street';
        acc.ShippingCity='London';
        acc.ShippingState='UK';
        acc.ShippingPostalCode ='123456';
        acc.ShippingCountry='UK';
        return acc;
    }

     
    /*----------------Setup data for Case ----*/
    public static case setupCase(Account acc)
    {      
        Case cs = new Case();
        cs.status='Open';
        cs.Subject='Demo Case';
        cs.Origin='Email';
        cs.AccountId = acc.id;
        cs.Reason = 'Defects';  
        return cs;
    }
   
       
}

------------------------------------------------- Test class --------------------------------------

@isTest(SeeAllData=false)

public class TestclassFactory{

    static testmethod void testCCREscalations (){
    User CCRUser =  UtileTesClass.setupUser();

    Test.startTest();

        system.runAs(CCRUser) {
        List<user> selectedusers = new List<User>();
        String CommonError ='';
        Integer ErrorFlag = 0;

         

            // setup Account
            Account account = UtileTesClass.setupAccount(CCRUser);
            insert account;
           
            List<account> listAccount = [select id,name from Account];
            System.assertEquals(1, listAccount.size());

            Case cas = UtileTesClass.setupCase(account);
            insert cas;          

        }
    Test.stopTest();
    }                

 
    }

Wednesday, 3 June 2015

Salesforce Developer Stuff: Understanding Trigger Context Variable

Salesforce Developer Stuff: Understanding Trigger Context Variable:                                       

https://www.forcewizard.com/blog/understanding-trigger-context-variable


    When I started my carrier as Salesforce developer.when I wrote my first trigger code, I always use to hear


trigger TriggerContextVarDemo on Book__c (before insert, after insert, before update, after update)
{
      /*This if block will run only before insert.It means mean time of
        the records going to save into salesforce database*/
       
      if(Trigger.isInsert && Trigger.isBefore){
            System.debug('****Insert before Trigger.new******'+Trigger.new);
            /*Trigger.New-new versions of the sObject records.
              e.g. It will work both insert and update for insert every record will be new.
              creating 1st record on book it will return 1st record value,creating 2nd will return second
              record value like that it will go.
            */
           
            System.debug('****Insert before Trigger.old******'+Trigger.old);
            /*Trigger.Old-old versions of the sObject records.
              this will not work both before and after insert.Then always the value will be null.
               because there will be no old version(old value) of the record, all are new record.
               old vesion in the sence while updating any record you may change some field value to new value .
               that old value with record will be in trigger.old.
            */
           
            System.debug('****Insert before Trigger new map******'+Trigger.newMap);
            /*Trigger.newMap-map of IDs to the new versions of the sObject records.
              It will work only on after insert because new map must store the Id and record.
              In the before insert how the id will be generated.
              so always it will return null.
            */
              System.debug('****Insert before Trigger old map******'+Trigger.oldMap);
              /*It will not return any value always its null*/
    }
 
    /*This if block will only run after succesful insert of records into salesforce database*/
       
    if(Trigger.isInsert && Trigger.isAfter){
            System.debug('****Insert after Trigger.new******'+Trigger.new);
            /*It will return same value as explained before insert of Trigger.new*/
           
            System.debug('****Insert after Trigger.old******'+Trigger.old);
            /* this will not work both before and after insert.Then always the value will be null.
               because the will be no old version(old value) of the record all are new record
               old vesion in the sence while updating any record you may change some field value to new value .
               that old value will be in trigger.old
            */
            System.debug('****Insert after Trigger new map******'+Trigger.newMap);
           /*It will return new map value as explained before insert of Trigger.newMap
             because id is generated for new record that is saved.
           */
           System.debug('****Insert after Trigger old map******'+Trigger.oldMap);
            /*It will not return any value always its null */
    }
   
      /*This if block will run only before update.It means mean time of
        the records going to update into salesforce database*/
       
    if(Trigger.isupdate && Trigger.isBefore){
            System.debug('****update before Trigger.new******'+Trigger.new);
            /*As I explained previously Trigger.new is the new version of sobject record
              create first book record with price 200 then edit and change price 600 and click save
              now this Trigger.new will contain the new value of record that means price  value with 600 record
           */
            System.debug('****update before Trigger.old******'+Trigger.old);
             /*As I explained previously Trigger.new is the new version of sobject record
              Edit the created book record and change price from 200 to 600 and click save
              now this Trigger.old will contain the old value of record that means price value with 200 record
           */
            System.debug('****update before Trigger new map******'+Trigger.newMap);
            /*As I explained previously Trigger.new is the new version of sobject record
              create first book record with price 200 then edit and change price 600 and click save
              now this Trigger.newMap will contain the newmap value of record that means price  value with 600 record
           */
            System.debug('****update before Trigger old map******'+Trigger.oldMap);
             /*As I explained previously Trigger.new is the new version of sobject record
              Edit the created book record and change price from 200 to 600 and click save
              now this Trigger.oldMap will contain the oldMap value of record that means price value with 200 record
           */
   }
   
    /*This if block will only run after succesful update of records into salesforce database*/
    //This block will return same value as returned in is before update
     if(Trigger.isupdate && Trigger.isAfter){
            System.debug('****update after Trigger.new******'+Trigger.new);
            System.debug('****update after Trigger.old******'+Trigger.old);
            System.debug('****update after Trigger new map******'+Trigger.newMap);
            System.debug('****update after  Trigger old map******'+Trigger.oldMap);

    }

}

Thursday, 15 January 2015

Bob Buzzard Blog: Managing a list of New Records in Visualforce

Bob Buzzard Blog: Managing a list of New Records in Visualforce: This week's post concerns bulk creation of an unknown number of sobject records - Accounts, for example. In this situation I want to dis......

Wednesday, 14 January 2015

Test class for visualforce (VF) page with URL parameters

//Test class for visualforce (VF) page with URL parameters
/*
Here i am creating test class for standard controller as well when we want to pass parameters in URL 
*/
@isTest
public class VFTestClass
{

Monday, 12 January 2015

visualforce with radio button

/*
Here i want to demonstrate vf page with radio button on standard object USER and selected value will be save in custom object (TestUser__c )
*/

Monday, 27 October 2014

SOQL query of Knowledge Articles

SOQL query of Knowledge Articles


SELECT ArticleNumber,ArticleType,CreatedById,UrlName,VersionNumber FROM Offer__kav where PublishStatus = 'Online' AND Language ='en_US'


Output:- 


ArticleNumberArticleTypeCreatedByIdUrlNameVersionNumber
1000001008Offer__kav00590000001DZcHAAWMy-first-Article1
2000001004Offer__kav00590000001DZcHAAWHow-can-I-cancel-my-flight1
3000001006Offer__kav00590000001DZcHAAWIs-my-passport-valid1
4000001000Offer__kav00590000001DZcHAAWfirst-offer11
5000001001Offer__kav00590000001DZcHAAWsecond-offer21





SOQL query of Knowledge Articles

Monday, 11 August 2014

Generate report for all test classes In salesforce (SFDC)

 Generate report for all test classes in salesforce (SFDC)

/*
    to meet this requirement i created a scheduler class (TestResultScheduler ), a main class (TestResultGenerator ) , and one future method class (testLog) to retrieve all test class status and email the result.

*/