Sunday 18 December 2016

Salesforce Advanced Interview Questions

           Salesforce Advanced Interview Questions 


1.write sample trigger to update Account phone on its related contacts.


TriggerName: AccountHandlerTrigger


trigger AccountTriggerHandler on Account (after update) {

AccountHandlerClass.updateContacts2(Trigger.newMap);
}



/*******************************************************************
Class Name: AccountHandlerClass

Purpose:    1. This is the Trigger Handler class for Account object




public class AccountHandlerClass {

/*******  Sample method 1 *********/

 public static void updateContacts2(map<id,account> newAccountMap){
   
list<contact> lstCons =[select id,name,phone,Accountid from contact where Accountid in :newAccountMap.keySet()];
system.debug('lstCons :'+lstCons);
list<contact> updCons = new list<contact>();
if(!lstCons.isEmpty()){
for(contact c : lstCons){
if(c.Phone != newAccountMap.get(c.AccountId).phone){
c.Phone = newAccountMap.get(c.AccountId).phone;
updCons.add(c);
}
}
}
   update updCons;
}

}


2.write Soql query to Accounts with contact. 

list<account> acc = [select Id,name from Account where Id In (select AccountId from Contact)];

system.debug('acc : '+acc.size());



3.if a controller has a series of extensions then which extension will execute first.




If both extension having same method, whichever methods are defined in the “leftmost” extension, or, the extension that is first in the comma-separated list will execute first.


====================================================================
<apex:page standardController="Account" extensions="Extension1,Extension2">
    <apex:form>
        Displaying name from Extensions : "{!Name}"
    
    </apex:form>
</apex:page>
====================================================================
public class Extension1 {    
    public Extension1(ApexPages.StandardController controller){}
    public static string getName(){      
        return 'Prasad';
    }

}



public class Extension2 {      
    public Extension2(ApexPages.StandardController controller){}
  
    public static string getName(){       
        return 'Kalyan';
    }
    
}


=======================================================================
4.Transaction Control using SavePoint and Rollback in Salesforce.

SavePoint and Rollback will help us to maintain transaction for DML statement.
Suppose you  have written multiple lines of DML statements in a try block, If any error occurs during DML Operations, the operation will be rolled back to the most recent save point and the entire transaction will not be aborted.

   Savepoint sp;
try{
   sp = Database.setSavepoint();
  
   Account a = new Account();
   a.Name = 'Test Account';
   insert a;
  
   Contact c = new Contact(Account = a.Id);
   c.FirstName = 'Biswajeet';
   c.LastName = 'Samal';
   insert c;
  }
catch(Exception e){
    Database.RollBack(sp);
}

More Info : 


5.can we do a Callout from with in a Trigger ?



6.How to get Custom Settings in Apex Test code?


@isTest
public class BIIB_testClassHelper{

/*
 * Creating custom settings data in creation in test class .
 *  Avoid @isTest(SeeAllData = True) in test classes..
 */

public static testMethod void customsettingcreation(){
  
Id SampleRecordtypeID=Schema.SObjectType.Case.getRecordtypeinfosbyname().get('Recordtype Name').getRecordtypeId();
string Country = 'USA';

Custom_Settings__c cusutomsetting = new Custom_Settings__c();
cusutomsetting.RecordType_ID__c=SampleRecordtypeID;
cusutomsetting.CountryName__c=Country;

insert cusutomsetting;

   }
}



8.Trigger to update All contact names in Account Field.

===================================================================
trigger ContactTrigger_Handler on Contact (after insert,after delete) {
    
    if(trigger.isinsert && trigger.isAfter){
        updaetcontactnamefield.updateaccount(Trigger.new);
    }
    
     if(trigger.isdelete && trigger.isAfter){
        updaetcontactnamefield.updateaccount(Trigger.old);
    }

}

====================================================================
public class updaetcontactnamefield{
    public static void updateaccount(list<contact> contacts){
        set<id> accountIds = new set<id>();
        
        if(!contacts.isEmpty()){
            for(contact c:contacts){
                accountIds.add(c.accountid);
            }
        }
        
        list<account> lstAcc = new list<account>();
        for(Account acc : [Select id, name, description, 
                           (Select Id, name, LastName From Contacts) 
                           From Account Where Id In : accountIds])
        {
            List<String> lstSrting = new List<String>();
            for(Contact con : acc.contacts)
            {
                lstSrting.add(con.lastname);
            }
            acc.description = String.join(lstSrting, ',');
            lstAcc.add(acc);
        }
      update lstAcc;
    }
    
}

====================================================================

9.How to setup Field Level Security (FLS) for Person Account Fields.

OR
Why I am not able to find list of Person Account fields in Field Level Security (FLS) settings when navigated to fields on Account Object.
Ans :


Field Level Security (FLS) of Person Account fields ar controlled by Contact Fields. So, if you want to setup FLS of Person Account Fields navigate to fields of Contact and it will be reflected on Person Account.

10.In below code snippet , What is your observation and what is going wrong ?


trigger TestBeforeDelete on Lead (before Delete) {

for(Lead l : Trigger.Old)
{
l.addError('error');
}

String msgBody = 'Test Email';
String Subject = 'Test from Cogni Force on Lead';
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'abc@gmail.com'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('abc@gmail.com');
mail.setSenderDisplayName('Cogniforce Test Simulator');
mail.setSubject(Subject);
mail.setPlainTextBody(msgBody);
mail.setHTMLBody(msgBody);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
Ans :
It will not send any email. Because “adderror” prevents all transactions from committing including emails.

10.How To Start Loading Data From 101 Row Of The CSV File In Data Loader?


In Dataloader Settings we need to specify Start Row no:

11.Calling future method from batch class?


Future method cant be called from future or Batch.


recommend the use of System.Queueable call instead of @Future. You can create a class that is constructed with any kind of argument that you want to hand in, like so:
public class DeferredHandler implements System.Queueable{
    public void execute(System.QueueableContext objContext)    {
        //do your @Future stuff here 
    }
}
And invoke him from inside your batch like this:
//defer stuff
System.Queueable job = new DeferredHandler(key2val);
System.enqueueJob(job);


12.How we can display serial-nos in standardlistcontroller.

<apex:page standardController="Account" recordSetVar="accounts" tabstyle="account" sidebar="false">
  <apex:pageBlock >
      <apex:variable var="rowcount" value="{!0}" />      
    <apex:pageBlockTable value="{!accounts}" var="a" >
       <apex:column>
        {!rowcount} <apex:variable var="rowcount" value="{!rowcount+1}" />
    </apex:column>
      <apex:column value="{!a.name}"/>
      <apex:column value="{!a.phone}"/>
    </apex:pageBlockTable>
  </apex:pageBlock>

</apex:page>

Monday 5 December 2016

Salesforce Winter17 Developer Maintenance (401)

1.Which capability does the Lightning Mass Action feature allow beyond standard Actions?
A. Firing a single action on multiple objects at once.
B. Firing multiple actions on multiple objects at once.
C. Firing a single action on multiple records at once.
D. Firing multiple actions on multiple records at once.
2.What does the new ISCLONE function check when comparing two items?
A. If an item has the ability to be cloned.
B. If an item was cloned when created.
C. If one Item is a clone of another.
D. If an Item has ever been cloned.
3.Where is the exported template saved in an Org when using Lightning Bolt for Communities?
A. Community Brand Manager
B. Community Creation wizard
C. Installed Packages
D. Personal App Exchange
4.What must be shared between two objects to invoke one process from another using Process Builder?
A. Owner
B. Master-Detail
C. Junction Object
D. Unique ID
5.Which two pieces of information should be recorded on the Work Type object?
Choose 2 answers
A. The estimated complexity of a Task.
B. The skills recommended to complete a Task.
C. The list of activities to complete a Task.
D. The estimated duration of a Task.
E. The needed equipment to complete a Task


Salesforce Winter17 Administrator Maintenance (201)

1.Universal Containers’ sales reps use the Lightning Experience. They need to send quotes to their prospects. How can this be accomplished?
A. Create a quote from the product and email as a link.
B. Create a quote from the opportunity and email as a link.
C. Create a quote from the opportunity and email as a PDF.
D. Create a quote from the lead and email as a PDF.
2.Which three Chatter Feed functionalities are available in the lightning experience?
Choose 3 answers
A. Chatter comments automatically post without refresh.
B. Videos play directly in the Chatter feed.
C. Users can edit Chatter feed posts and comments.
D. Chatter Instant Messages without refresh.
E. Users can launch a Chatter Meeting directly from the feed.
3.Which two features are available in Partner Communities using the Customer Service template?
Choose 2 answers
A. Users can create their own list views.
B. Field level help displays to the user.
C. Report charts can be added to the layout.
D. Sales Path available for opportunities only.

4.The VP of Marketing at Universal Containers would like to track which campaigns led to opportunities. They would like to evenly attribute revenue across all campaigns that touched the opportunities. Which two tools should the administrator configure to meet the VP’s request?
Choose 2 answers
A. Create a custom campaign influence attribution model.
B. Add the Campaign Results section to the opportunity page layout and assign users the campaign influence permission so they can edit the fields.
C. Add the Influenced Opportunities related list to the campaign page layout and add the Campaign Influence to the opportunity page layout.
D. Clone the standard campaign influence model into a custom model.
E. Add the Influenced Opportunities related list to the opportunity page layout and add the Campaign Influence to the campaign page layout.

5.The sales manager at Universal Containers would like a dashboard component to list sales reps by opportunity pipeline amount with high and low values highlighted in different colors. With the Lightning Experience enabled, how should the system administrator configure the component to meet the sales manager’s need?
A. Create a metric component for each rep in descending order with conditional highlighting in Lightning.
B. Create a table component, conditional highlighting and sort the columns within Lightning.
C. Create a table component and sort the columns in Lightning. Add conditional highlighting in classic.
D. Create a table component, conditional highlighting in Lightning and sort the columns in classic.


Tuesday 15 November 2016

Find flow details using ID

Find flow details using ID:

Using workbench:
in workbench we need to select Restexplorer:

Syntax:
/services/data/v37.0/tooling/sobjects/flow/id





Test class for product and pricebook

Test class for product and pricebook:

Product2 prod = new Product2(Name = 'Laptop X200',
                                     Family = 'Hardware');
        insert prod;
       
        Id pricebookId = Test.getStandardPricebookId();
       
        PricebookEntry standardPrice = new PricebookEntry(
            Pricebook2Id = pricebookId, Product2Id = prod.Id,
            UnitPrice = 10000, IsActive = true);
        insert standardPrice;
       
        Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
        insert customPB;
       
        PricebookEntry customPrice = new PricebookEntry(
            Pricebook2Id = customPB.Id, Product2Id = prod.Id,
            UnitPrice = 12000, IsActive = true);
        insert customPrice;
       
        List<PricebookEntry> pbez = [SELECT ID, Product2Id, Pricebook2.isStandard, Pricebook2.isActive, isActive FROM PricebookEntry];
       
        system.debug(pbez[0].Pricebook2.isStandard);
        system.debug(pbez[0].Pricebook2.isActive);




test class best practices in salesforce

Test class best practices in sales-force:


we need to use System.assert / System.assertEquals in the test. How would you know you are             getting  what is expected from the test? There have to be assert statements.
we need to avoid @isTest(seeAlldata = true) ?
        we have to setup our own data for testing purpose and should not rely on the Org data.
Provide a description of what you are test is doing(comments).
we need have setup method for all your data creation.
we should test for both positive and negative scenarios.
Tests are run as System Administrator only, is this how we do in the real system also? If not test        users needs to be created and by using  System.runAs () it has to tested as appropriate.
•     we should have only what exactly you are testing in between  Test.StartTest() and          Test.Stoptest().


Following are applicable for all the test classes.
The Ideal test class should be somewhat like this

@isTest
public class nameOfTestClass {

// any statics you want to define

// Have your setup methods defined here


/**
* Comments for the test method1
*
**/



static testMethod void testNameOfTheMethod1(){

// All the set up should be here

test.startTest();

// only what you want to test should be here.

test.stopTest();

}
/**
* Comments for the test method2
*
**/

static testMethod void testNameOfTheMethod2(){

// All the set up should be here

test.startTest();

// only what you want to test should be here.

test.stopTest();
}
}

Test Class Best practises










Apex Exception Email

Apex Exception Email:


1.Actually the 'Send Apex Warning Emails' settings on the User record only controls whether or not you get Apex warning emails every time that an Apex scrip surpasses more than 50% of any governor limit.

2.Runtime exception messages (which is what the "Developer script execution" emails are about) always get sent to the 'Last Modified By' user of the Apex class that generates the exception.

3.The only way to disable those emails is to have another user update the Apex class(es) in question. Marking your user record as Inactive in the Org might also work, but I'm not sure.

4.UPDATE: 
This is possible now with the Winter 16 release. Under Setup go to "Apex Exception Email" to specifiy what email(s) you want to receive error messages. Here is an exceprt from the release notes:

Increase Java Heap Space

Increase Java Heap Space:

we need to follow below steps to increase Heap Space

1.PC Properties
2.Advanced System Settings
3.Environment Variables
4.System Variables
5.Select NEW.


Java heap space increment

Monday 19 September 2016

Salesforce ANT Deployment

Prerequisites:


down load ant zip file :apache-ant-1.9.7
and sample package : salesforce_ant_37.0

we will have jar file in salesforce_ant_37.0
copy above jar file and paste in apache-ant-1.9.7 lib file..


In Path settings we need to add JDK and Apache ant file path files.

EX : 1.C:\Program Files\Java\jdk1.8.0_101\bin
     2.C:\Program Files\apache-ant-1.9.7\bin



More info : please check below link.
http://www.mkyong.com/ant/how-to-install-apache-ant-on-windows/

ISCHANGE function



ISCHANGE function..


This function is available only in:
  • Assignment rules
  • Validation rules
  • Field updates
  • Workflow rules if the evaluation criteria is set to Evaluate the rule when a record is: created, and every time it’s edited.


Thursday 28 July 2016

Approval Process in Sales-force using Apex and Trigger

public void submitForApproval(Opportunity opp)
    {
        // Create an approval request for the Opportunity
        Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval automatically using Trigger');
        req1.setObjectId(opp.id);
        req1.setNextApproverIds(new Id[] {opp.Next_Approver__c});

        // Submit the approval request for the Opportunity
        Approval.ProcessResult result = Approval.process(req1);

    }

More info:

http://www.jitendrazaa.com/blog/salesforce/dynamic-approval-process-based-on-the-apex-and-trigger/

Lookup Filters field dependency in sales-force

Lookup Filters field dependency in sales-force

EX :  product family is parent.
           product is child.


Thursday 30 June 2016

Metadata Explorer Tools

Metadata_Explorer Tools
 
 







============================================================

 //return new ApexPages.Standardcontroller(attach).view();   

1.Actually the 'Send Apex Warning Emails' settings on the User record only controls whether or not you get Apex warning emails every time that an Apex scrip surpasses more than 50% of any governor limit.

2.Runtime exception messages (which is what the "Developer script execution" emails are about) always get sent to the 'Last Modified By' user of the Apex class that generates the exception. 

3.The only way to disable those emails is to have another user update the Apex class(es) in question. Marking your user record as Inactive in the Org might also work, but I'm not sure.

4.UPDATE: 
This is possible now with the Winter 16 release. Under Setup go to "Apex Exception Email" to specifiy what email(s) you want to receive error messages. Here is an exceprt from the release notes:

================================================================================

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