Thursday 27 October 2016


Salesforce Developer -Summer 16 -Release Exam

1. Which two Objects are accessible via APEX?
Choose 2 answers
A. LinkedContactRelation
B. ApexTestRunResult
C. AccountContactRelation
D. DatedConversionRate
Answer: BC

2. What should be considered when using Custom DocTypes in Visualforce?
A. Custom DocTypes can be specified as an attribute on the tag.
B. Custom DocTypes can be specified using the tag.
C. Only the HTML and PDF DocTypes are supported in Visualforce.
D. Custom DocTypes are unsupported in Visualforce.
Answer: A

3. Which two are true when activating LockerService?
Choose 2 answers
A. LockerService affects both Lightning Components and Visualforce Pages that contain JavaScript
B. LockerService is enforced on Managed Packages when the Critical Update is not Activated
C. LockerService is not enforced on Managed Packages when the Critical Update is not Activated
D. When LockerService is enabled, the instance of operator is unreliable
Answer: AD

4. Which values can be entered that are enhancements to Lightning Components? 
A. Number values using k, m, b, or t
B. Boolean values as yes or no
C. Rich-text values into text fields
D. Date values using mm/dd/yyyy
Answer: A

5. Which field can be used to match with existing Accounts and Contacts when using the Data Import Wizard?
A. An External Key Field
B. Account Site
C. An External ID Field
D. A Unique Field
Answer: C

Sunday 18 September 2016

Update the parent object using trigger - relationship master detail

Trigger :


trigger LoanPaymentTransactionTrigger on loan__Loan_Payment_Transaction__c (after insert, after update, after delete) {
  if(Trigger.isAfter){
        if(Trigger.isInsert || Trigger.isUpdate){
            LoanPaymentTransaction_TriggerHandler.onAfterUpsertProcess(Trigger.new);
        }
        
        if(Trigger.isDelete){
            LoanPaymentTransaction_TriggerHandler.onAfterDeleteProcess(Trigger.old);
        }
    }
}


Trigger Handler:

public class LoanPaymentTransaction_TriggerHandler { public static void onAfterDeleteProcess(List<loan__Loan_Payment_Transaction__c> lstOldData){ Map<Id, Map<String, Integer>> mapCounts = new Map<Id, Map<String, Integer>>(); Map<String, Integer> mapRCount = new Map<String, Integer>(); Set<Id> setMasterIDs = new Set<Id>(); Map<Id, loan__Loan_Account__c> mapMasterRecords = new Map<Id, loan__Loan_Account__c>(); List<loan__Loan_Account__c> updateloanAcc = new List<loan__Loan_Account__c>(); for(loan__Loan_Payment_Transaction__c payT: lstOldData ){ if(payT.loan__Reversal_Reason__c != null){ setMasterIDs.add(payT.loan__Loan_Account__c); // Master Obj Ids } } if(setMasterIDs.size() > 0){ List<loan__Loan_Account__c> lstLoanAccounts = queryMasters(setMasterIDs); for(loan__Loan_Account__c lAcc: lstLoanAccounts){ mapMasterRecords.put(lAcc.Id, lAcc); } if(lstLoanAccounts.size() > 0){ for(loan__Loan_Account__c loanAcc: lstLoanAccounts){ for(loan__Loan_Payment_Transaction__c payT: loanAcc.loan__Loan_Payment_Transactions__r){ if(mapCounts.containsKey(loanAcc.Id)){ Map<String, Integer> innerMap = mapCounts.get(loanAcc.Id); if(innerMap.containsKey(payT.loan__Reversal_Reason__c)){ Integer existingCount = innerMap.get(payT.loan__Reversal_Reason__c); existingCount++; // Increasing current count innerMap.put(payT.loan__Reversal_Reason__c, existingCount); } else{ innerMap.put(payT.loan__Reversal_Reason__c, 1); // adding current count } mapCounts.put(loanAcc.Id, innerMap); } else{ Map<String, Integer> innerMp = new Map<String, Integer>(); innerMp.put(payT.loan__Reversal_Reason__c, 1); mapCounts.put(loanAcc.Id, innerMp); } /* if(mapRCount.containsKey(payT.loan__Reversal_Reason__c)){ Integer existingCount = mapRCount.get(payT.loan__Reversal_Reason__c); existingCount++; // Increasing current count mapRCount.put(payT.loan__Reversal_Reason__c, existingCount); } else{ mapRCount.put(payT.loan__Reversal_Reason__c, 1); // adding current count } */ } } // Update value to master for(Id masterId : mapCounts.keySet()){ Map<String, Integer> inncounts = mapCounts.get(masterId); loan__Loan_Account__c loanAccforUpdate = mapMasterRecords.get(masterId); system.debug('loanAccforUpdate ==>>>'+loanAccforUpdate); String formingDesc = ''; for(String cnt : inncounts.keySet()){ if(cnt != null) formingDesc += cnt + ' - ' + inncounts.get(cnt) + '; '; } system.debug(' formingDesc ===========>>'+formingDesc+' ==>'+loanAccforUpdate); loanAccforUpdate.Reason_Code_Snapshot__c = formingDesc; system.debug(' loanAccforUpdate.Reason_Code_Snapshot__c ===========>>'+loanAccforUpdate.Reason_Code_Snapshot__c); updateloanAcc.add(loanAccforUpdate); } update updateloanAcc; } } } public static void onAfterUpsertProcess(List<loan__Loan_Payment_Transaction__c> lstNewData){ Map<Id, Map<String, Integer>> mapCounts = new Map<Id, Map<String, Integer>>(); Map<String, Integer> mapRCount = new Map<String, Integer>(); Set<Id> setMasterIDs = new Set<Id>(); Map<Id, loan__Loan_Account__c> mapMasterRecords = new Map<Id, loan__Loan_Account__c>(); List<loan__Loan_Account__c> updateloanAcc = new List<loan__Loan_Account__c>(); system.debug('inside trigger'); for(loan__Loan_Payment_Transaction__c payT: lstNewData ){ // if(payT.loan__Reversal_Reason__c != null){ setMasterIDs.add(payT.loan__Loan_Account__c); // Master Obj Ids // } } if(setMasterIDs.size() > 0){ List<loan__Loan_Account__c> lstLoanAccounts = queryMasters(setMasterIDs); for(loan__Loan_Account__c lAcc: lstLoanAccounts){ mapMasterRecords.put(lAcc.Id, lAcc); } if(lstLoanAccounts.size() > 0){ for(loan__Loan_Account__c loanAcc: lstLoanAccounts){ for(loan__Loan_Payment_Transaction__c payT: loanAcc.loan__Loan_Payment_Transactions__r){ system.debug('inside lpt loop'); if(mapCounts.containsKey(loanAcc.Id)){ Map<String, Integer> innerMap = mapCounts.get(loanAcc.Id); if(innerMap.containsKey(payT.loan__Reversal_Reason__c)){ Integer existingCount = innerMap.get(payT.loan__Reversal_Reason__c); existingCount++; // Increasing current count innerMap.put(payT.loan__Reversal_Reason__c, existingCount); system.debug('blankreversalreasontest1'); } else{ //innerMap.put(payT.loan__Reversal_Reason__c, 1); // adding current count // commenting for test - Annand innerMap.put(payT.loan__Reversal_Reason__c, 1); system.debug('blankreversalreason'+innerMap); } mapCounts.put(loanAcc.Id, innerMap); } else{ Map<String, Integer> innerMp = new Map<String, Integer>(); innerMp.put(payT.loan__Reversal_Reason__c, 1); mapCounts.put(loanAcc.Id, innerMp); system.debug('blankreversalreasontest2'); } /* if(mapRCount.containsKey(payT.loan__Reversal_Reason__c)){ Integer existingCount = mapRCount.get(payT.loan__Reversal_Reason__c); existingCount++; // Increasing current count mapRCount.put(payT.loan__Reversal_Reason__c, existingCount); } else{ mapRCount.put(payT.loan__Reversal_Reason__c, 1); // adding current count } */ } } // Update value to master for(Id masterId : mapCounts.keySet()){ Map<String, Integer> inncounts = mapCounts.get(masterId); loan__Loan_Account__c loanAccforUpdate = mapMasterRecords.get(masterId); system.debug('loanAccforUpdate ==>>>'+loanAccforUpdate); String formingDesc = ''; for(String cnt : inncounts.keySet()){ if(cnt != null) formingDesc += cnt + ' - ' + inncounts.get(cnt) + '; '; } system.debug(' formingDesc ===========>>'+formingDesc+' ==>'+loanAccforUpdate); loanAccforUpdate.Reason_Code_Snapshot__c = formingDesc; system.debug(' loanAccforUpdate.Reason_Code_Snapshot__c ===========>>'+loanAccforUpdate.Reason_Code_Snapshot__c); updateloanAcc.add(loanAccforUpdate); } update updateloanAcc; } } } private static List<loan__Loan_Account__c> queryMasters(Set<Id> rIds){ List<loan__Loan_Account__c> lstloanAcc = [SELECT Reason_Code_Snapshot__c, Id, (SELECT loan__Reversal_Reason__c,loan__Loan_Account__c FROM loan__Loan_Payment_Transactions__r) FROM loan__Loan_Account__c WHERE Id IN : rIds]; return lstloanAcc; } }




Out Put:


Thursday 11 August 2016

Get Field Count using Aggregate Function:

List<AggregateResult> ui=[Select  count(loan__Rejection_Reason__c) cnt,count(loan__Reversal_Reason__c) cnt1,count(Failure_Reason__c) cnt2,loan__Loan_Account__c from loan__Loan_Payment_Transaction__c where loan__Rejection_Reason__c !=null group by  loan__Loan_Account__c];
for(AggregateResult ar: ui)
{
    //loan__Loan_Payment_Transaction__c lt = new loan__Loan_Payment_Transaction__c();
   
    String str = '' + ar.get('loan__Loan_Account__c') ;  //Get profileId
    String str1 = '' + ar.get('cnt') ; 
    String str2 = '' + ar.get('cnt1') ;
    String str3 = '' + ar.get('cnt2') ;//Get count of Id using the alias name
    System.debug('##########'+str);
    System.debug('$$$$$$$$$$$'+str1);
    System.debug('%%%%%%%%%%'+str2);
    System.debug('&&&&&&&&&&'+str3);
  }

Friday 29 July 2016

Moving dates "After" or "Before" 15 days or whatever days we need :

date d = system.today().addDays(-15);
Account [] acc=  [select id from account where createdDate = :d];
System.debug('Test'+acc);
System.debug('date'+d);

Sunday 24 July 2016

Deleting the records in "Salesforce using Batch Class":

global class DeleteLeadRecord implements Database.batchable<sobject>{

 global database.querylocator start(Database.BatchableContext BC){
  String query = 'Select id from Lead where leadsource=\'Purchased - Raw\' AND isconverted=false';
  return database.getqueryLocator(query);
 }

 global void execute(Database.BatchableContext BC, list<Lead> leadList){
   if(!leadlist.isEmpty()){
    delete leadList;
   }
 }
 global Void finish(Database.BatchableContext BC){
 }


}
Date Functions:

This table lists all the date functions supported by SOQL.
Date FunctionDescriptionExamples
CALENDAR_MONTH()Returns a number representing the calendar month of a date field.
  • 1 for January
  • 12 for December
CALENDAR_QUARTER()Returns a number representing the calendar quarter of a date field.
  • 1 for January 1 through March 31
  • 2 for April 1 through June 30
  • 3 for July 1 through September 30
  • 4 for October 1 through December 31
CALENDAR_YEAR()Returns a number representing the calendar year of a date field.2009
DAY_IN_MONTH()Returns a number representing the day in the month of a date field.20 for February 20
DAY_IN_WEEK()Returns a number representing the day of the week for a date field.
  • 1 for Sunday
  • 7 for Saturday
DAY_IN_YEAR()Returns a number representing the day in the year for a date field.32 for February 1
DAY_ONLY()Returns a date representing the day portion of a dateTime field.2009-09-22 for September 22, 2009
You can only useDAY_ONLY() with dateTime fields.
FISCAL_MONTH()Returns a number representing the fiscal month of a date field. This differs from CALENDAR_MONTH() if your organization uses a fiscal year that does not match the Gregorian calendar.
Note
This function is not supported if your organization has custom fiscal years enabled. See "Fiscal Years" in the Salesforce Help.
If your fiscal year starts in March:
  • 1 for March
  • 12 for February
See “Set the Fiscal Year” in the Salesforce online help.
FISCAL_QUARTER()Returns a number representing the fiscal quarter of a date field. This differs from CALENDAR_QUARTER() if your organization uses a fiscal year that does not match the Gregorian calendar.
Note
This function is not supported if your organization has custom fiscal years enabled. See "Fiscal Years" in the Salesforce Help.
If your fiscal year starts in July:
  • 1 for July 15
  • 4 for June 6
FISCAL_YEAR()Returns a number representing the fiscal year of a date field. This differs from CALENDAR_YEAR() if your organization uses a fiscal year that does not match the Gregorian calendar.
Note
This function is not supported if your organization has custom fiscal years enabled. See "Fiscal Years" in the Salesforce Help.
2009
HOUR_IN_DAY()Returns a number representing the hour in the day for a dateTime field.18 for a time of 18:23:10
You can only useHOUR_IN_DAY() with dateTime fields.
WEEK_IN_MONTH()Returns a number representing the week in the month for a date field.2 for April 10
The first week is from the first through the seventh day of the month.
WEEK_IN_YEAR()Returns a number representing the week in the year for a date field.1 for January 3
The first week is from January 1 through January 7.

Tuesday 19 July 2016

Pick List and the Text field validation:

            AND 
             ( 
                 ISPICKVAL( Type_of_Dispute__c , "Other"), 
                 ISBLANK( If_Other_selected_please_explain__c ) 
             )
Salesforce Custom Phone number validation:

Setup --> Contact --> Create New Custom Fields --> Phone ---> Save

NOT(REGEX( Phone__c , "\\D*?(\\d\\D*?){10}"))
Salesforce Custom State Field Validation:

OR( ISNUMBER( State__c ), OR(CONTAINS(State__c , "!"),CONTAINS(State__c , "@"),CONTAINS(State__c , "#"), CONTAINS(State__c , "$"),CONTAINS(State__c , "$"),CONTAINS(State__c , "%"),CONTAINS(State__c , "^"), CONTAINS(State__c , "&"),CONTAINS(State__c , "*"),CONTAINS(State__c , ","),CONTAINS(State__c , ":"),CONTAINS(State__c , ".") ,CONTAINS(State__c , "{"),CONTAINS(State__c , "}"),CONTAINS(State__c , "]"),CONTAINS(State__c , "["),CONTAINS(State__c , ";") ,CONTAINS(State__c , "="),CONTAINS(State__c , "+"),CONTAINS(State__c , "("),CONTAINS(State__c , ")"),CONTAINS(State__c , "_"),CONTAINS(State__c , "-"),CONTAINS(State__c , "|"),CONTAINS(State__c , "{"),CONTAINS(State__c , "}"),CONTAINS(State__c , "1"),CONTAINS(State__c , "2"),CONTAINS(State__c , "3"),CONTAINS(State__c , "4"),CONTAINS(State__c , "5"),CONTAINS(State__c , "6"),CONTAINS(State__c , "7"),CONTAINS(State__c , "8"),CONTAINS(State__c , "9"),CONTAINS(State__c , "0")))

Monday 18 July 2016

Update the Contact Email with developer Console:

list<Contact> conOldList = [select id, email from contact where email!=null and (not(email like '%preprod'))Limit 4000];
list<Contact> conList = new list <Contact>();

for(contact ct: conOldList){
  ct.email += '.preprod';
  conList.add(ct);
}
update conLi
st;

Wednesday 29 June 2016

Can you update lookups using workflows?


    This will have to be done with coding.  Workflow Rules can't process unrelated records.  And, Workflow Rule Field Updates can't dynamically set Lookup() field values.

Monday 27 June 2016

State Validation Rule

The US State contains 2 Letters. 

1. Create a Text field and the set values as "2"
2. To write a below validation rule  

OR( ISNUMBER( State__c ), OR(CONTAINS(State__c , "!"),CONTAINS(State__c , "@"),CONTAINS(State__c , "#"),CONTAINS(State__c , "$"),CONTAINS(State__c , "$"),CONTAINS(State__c , "%"),CONTAINS(State__c , "^"),CONTAINS(State__c , "&"),CONTAINS(State__c , "*")))

Tuesday 14 June 2016

Roll Up Summary using Trigger


trigger sumofLPT on loan__Loan_Payment_Transaction__c (after insert, after update, after delete) {
    List<loan__Loan_Account__c> llaList = new List<loan__Loan_Account__c>();
  
    Set<ID> setlpt =  new Set<ID>();
  
    for(loan__Loan_Payment_Transaction__c lpt: trigger.new)
    {
        setlpt.add(lpt.id);
    }
    Decimal sum1;
    Decimal sum2;
    Decimal sum3;
    Decimal sum4;
    for(loan__Loan_Account__c loan: [select name, (select name, loan__Cleared__c, loan__Rejected__c, loan__Rejection_Reason__c, loan__Reversed__c, loan__Reversal_Reason__c, loan__Transaction_Amount__c FROM loan__Loan_Payment_Transactions__r)
    FROM loan__Loan_Account__c ])
    {
      
        sum1 = 0;
        sum2 = 0;
        sum3 = 0;
        sum4 = 0;
        for(loan__Loan_Payment_Transaction__c lpt1:loan.loan__Loan_Payment_Transactions__r){
        if(lpt1.loan__Rejected__c == true){   
            sum1 += lpt1.loan__Transaction_Amount__c;
            loan.Rejected_Transaction_Amount__c = sum1;
            System.debug('!!!!!!!!!!!!!sum1'+sum1);
            System.debug('@@@@@@@@@@@@@loan.Rejected_Transaction_Amount__c'+loan.Rejected_Transaction_Amount__c);
          
           }
            /*else
            {
                for(loan__Loan_Payment_Transaction__c lpt2: Trigger.old){
                if((Trigger.isUpdate || Trigger.isDelete) && lpt1.loan__Rejected__c == true){
                loan__Loan_Payment_Transaction__c lpt1old = Trigger.oldMap.get(lpt1.Id);
                }
               }
            }*/
         if(lpt1.loan__Reversed__c == true){
            sum2 += lpt1.loan__Transaction_Amount__c;
            loan.Reversed_Transaction_Amount__c = sum2;
            System.debug('!!!!!!!!!!!!!sum2'+sum2);
            System.debug('@@@@@@@@@@@@@loan.Reversed_Transaction_Amount__c'+loan.Reversed_Transaction_Amount__c);
            }
         if(lpt1.loan__Cleared__c == true){
            sum3 += lpt1.loan__Transaction_Amount__c;
            loan.Cleared_Transaction_Amount__c = sum3;
            System.debug('!!!!!!!!!!!!!sum3'+sum3);
            System.debug('@@@@@@@@@@@@@loan.Cleared_Transaction_Amount__c'+loan.Cleared_Transaction_Amount__c);
            }
            if(lpt1.loan__Cleared__c == false && lpt1.loan__Reversed__c == false && lpt1.loan__Rejected__c == false){
            sum4 += lpt1.loan__Transaction_Amount__c;
            loan.Uncleared_Transaction_Amount__c = sum4;
             System.debug('!!!!!!!!!!!!!sum4'+sum4);
            System.debug('@@@@@@@@@@@@@loan.Uncleared_Transaction_Amount__c'+loan.Uncleared_Transaction_Amount__c);
            }
        
        }
        llaList.add(loan);
    }
    update llaList;
  
}

Tuesday 31 May 2016

The following trigger updates the field called “Hello” by the value “World” whenever we are creating an account or updating an account record. Create the field “Hello” on the Account Object (Data Type = text)

Trigger:

trigger HelloWorld on Account (before insert, before update) {
    list<account> accs = trigger.new;
    MyHelloWorld my = new MyHelloWorld();//creating instance of apex class
    my.addHelloWorld(accs);//creating method from the apex class
    
}
Class:

public class MyHelloWorld {
    public void addHelloWorld(List<account> accs){
        for(Account a:accs){
            If(a.Hello__c != 'World'){
                a.Hello__c = 'World';
            }
        }
    }
}

Batch Apex

1. What are transaction limits in apex? Total number of SOQL queries issued1 - 100 Total number of records retrieved by SOQL queries - 50...