Thursday, 26 August 2021

Salesforce MAP with Dynamic Values

Salesforce MAP with  Dynamic Values  

Considerations: 

e.g. Account trigger is passing old and new maps.

Create a custom metadata: ObjectNames_Setting__mdt ,DeveloperName must have object Name



public void dynamicmethod(Map<Id,sobject> newAccountMap, Map<Id,sobject> oldAccountMap) {

       

        Set<Id> resultIds = new Set<Id>();

              

        system.debug('----------'+newAccountMap+'-----'+oldAccountMap+'----------'+newAccountMap.size()+'-----'+oldAccountMap.size());

        try{

            Set<Id> ids = newAccountMap.keySet();

            Id firstId =  new List<id> ( ids )[0];

            String sObjName = firstId.getSObjectType().getDescribe().getName(); //

            system.debug('---DynamicsObjName---'+sObjName); //

            

            List<ObjectNames_Setting__mdt> MOSobj = [SELECT id,Label,Update_Fields_Name__c, FROM ObjectNames_Setting__mdt where DeveloperName =: sObjName   LIMIT 1];

            System.debug('+++'+MOSobj[0].Update_Fields_Name__c);            

            List<String> objectFields = MOSobj[0].Update_Fields_Name__c.split(',');            

            for (sObject l : newAccountMap.values()) {

                //system.debug('=====sObject===='+ l);

                for(String fieldVar : objectFields){

                    if (l.get(fieldVar) != oldAccountMap.get(l.Id).get(fieldVar)) {

                        resultIds.add(l.Id);                    

                        break;

                    } 

                }

  }

}  

 catch(exception e)

        {

            System.debug('--------Exception ---'+e);

}

}

            

Wednesday, 5 September 2018

platform developer 2 topics


  • ·         Apex Design pattern
  • ·         Visualforce Developer Guide
  • ·         Lightning Design System Basics.
  • ·         Asynchronous Apex
  • ·         Apex Triggers and Order of Execution
  • ·         When and how to use @future (callout=true)
  • ·         Tools for using metadata in salesforce (Whisper word: Workbench)
  • ·         Best practices in Unit testing (about getURLU especially)
  • ·         Displaying Error messages in Vf pages and in lightning pages
  • ·         Sharing model in Salesforce
  • ·         Apex code Debugging from the sample code (some examples around: Database.rollback )
  • ·         Best practices for Apex CPU time limits
  • ·         Have Apex Governor limits on your fingertips
  • ·         Custom and Standard controllers
  • ·         Using multiple custom controllers and order of execution in the same
  • ·         Ways to view state issues
  • ·         Debugging triggers
  • ·         Exception handling
  • ·         Debugging in Developer Console and its components (refer Salesforce Help Doc here)
  • ·         SOQL and its best practices (especially preventing SQL injection)
  • ·         Types of fields in objects.
  • ·         Unique and External ID fields.
  • ·         Using SOAP/REST web services and its best practices.
  • ·         SOAP API parameters
  • ·         REST annotations
  • ·         Types of APIs in Salesforce and its basics
  • ·         VF pages with Javascript remote actions
  • ·         Dynamic SOQL and its limitations
  • ·         Visualforce tags (Tip: Not the basic tags)
  • ·         List, Set and Map collections in apex
  • ·         Workflows and Process builders (Tip: If process builder is an option in Ans, Think twice. Mostly that would be the ans. Don’t blame me if you get it wrong. )
  • ·         Debugging run time errors from sample code. (Tip: there could be multiple bugs in the code. Look for the line which will cause failure at first in the order of execution)
  • ·         Know about Debug logs and how to debug via debug logs, and setting the parameters for debug logs.
  • ·         Chatter and how apex can access chatter programmatically
  • ·         Pagination in Vf pages and best practices
  • ·         https://developer.salesforce.com/page/Apex_Design_Patterns
  • ·         https://www.youtube.com/watch?v=tsa8Z2S1Agc
  • ·         https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_intro.htm
  • ·         https://trailhead.salesforce.com/modules/lex_dev_lc_basics


Salesforce Sales Cloud Certification Topics and references

Visit to this link





It will redirect you on below link , Use that below link
opt topics from Sales Cloud Basics     and read one by one. It will cover almost all topics

More topics: -


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();
    }
}