Showing posts with label Interview Questions. Show all posts
Showing posts with label Interview Questions. Show all posts

Monday, July 3, 2017

How To Dispaly The DropDown Values With CheckBoxes Vertically In Visual Force

In my previous post I have explained to how to display the drop down values with check boxes so we will use the same post but In this post I will explain how to display that list vertically rather than horizontally.

In <apex:SelectCheckBoxes> tag we have an attribute called 'layout' which will decides the direction of the display .If you set that to layout="pageDirection" then it will displays automatically in vertical.

Source Code:


In VisualForce Page:

<apex:selectcheckBoxes value="{!selFruits}" layout="pageDirection">
 <apex:selectOption itemLabel="Mango" itemValue="Mango" />
 <apex:selectOption itemLabel="Apple" itemValue="Apple" />
 <apex:selectOption itemLabel="Banana" itemValue="Banana" />
 <apex:selectOption itemLabel="Guava" itemValue="Guava"/>
        <apex:selectOption itemLabel="Orange" itemValue="Orange"/>

</apex:selectcheckBoxes>

In Apex Class:

Public List<String> selFruits{get;set;} // This should be list not Single String


OutPut:




Thanks for visiting..hope this helps you!

Saturday, July 1, 2017

System.ListException: Before Insert or Upsert list must not have two identically equal elements

We will receive this error when your adding same instance of record to list twice i.e.If your adding same record twice to the list you will end up with error.

Sample Code With Error

List<Case> listCase = new List<Case>();
Case cs = new Case();
cs.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Bus').getRecordTypeId();
cs.Status ='Approved';
cs.Origin = 'Inbound Call';
listCase.add(cs);

Case cs1 = new Case();
cs1.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Bus').getRecordTypeId();
cs1.Status ='Approved';
cs1.Origin = 'Inbound Call';
listCase.add(cs);  // I should add cs1 instance but I added cs which are already in list

insert listCase;

If you run the above code you will receive an error while inserting System.ListException: Before Insert or Upsert list must not have two identically equal elements ,that is because of adding same case record twice to the list ,you can see duplicate element in yellow color where actually it should be cs1 but added cs which is already there in list.

To avoid this error you can cross check your code whether your adding some where same instance of object twice to the list.

Error Free Code


List<Case> listCase = new List<Case>();
Case cs = new Case();
cs.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Bus').getRecordTypeId();
cs.Status ='Approved';
cs.Origin = 'Inbound Call';
listCase.add(cs);

Case cs1 = new Case();
cs1.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Bus').getRecordTypeId();
cs1.Status ='Approved';
cs1.Origin = 'Inbound Call';
listCase.add(cs1);   //Corrected here adding cs1 instance to list 

insert listCase;


Thanks for visiting..hope this helps you!

Thursday, January 12, 2017

What is Default Backend formats for Date and DateTime in Salesforce

Today I'm going to share an exiting hidden feature of salesforce. We will be using regularly date and datetime fields in salesforce. I will discuss few points about these fields now.

Scenario:

 I have one datetime field in my object which typically stores the date time .Now I have created one record in that object passing some date and time to that field.Lets assume that the value is 11 Jan 2017 and time as 3Am(03:00:00) .I have successfully created a record and my time zone is IST .
Now I open my developer console and trying to query the same record with the help of datetime(11Jan 2016 3Am) then my query ends up with no result.Why is it ?What happened?

Root Cause:

 Now I have taken some other field(Id or String) from same object to debug actually what happening in the backend and included this datetime field in query.The value for datetime field is showing some thing like 10 Jan 2017 and time as 9pm (21:30:00) but when I added same field to page layout or in visual force page I'm getting the 11 Jan 2017 and time as 3Am(03:00:00) .Then I went through many blogs and docs of salesforce and came to know that by default the Salesforce will stores all Date and Datetime fields in database in the format of Coordinated Universal Time (UTC) which also know as Greenwich Mean Time (GMT) and it will not consider what is the logged in user time zone.



Solution:

So due to above mentioned statement the converted value of IST 11 Jan 2017 and time as 3Am(03:00:00) will comes as 10 Jan 2017 and time as 9pm (21:30:00) because we are ahead of +5:30 compared to GMT/UTC.

So when you were working with date or datetime fields better you will make sure that you follow all these conversions to get the exact data.

Whenever showing these date or datetime fields in pagelayout or visual force page salesforce automatically converts that GMT/UTC value to logged in user respective timezone so that is the reason we are able to see 11 Jan 2017 and time as 3Am(03:00:00) on layouts and vf pages instead of 10 Jan 2017 and time as 9pm (21:30:00)

Salesforce already provides some internal date and datetime functions to make all these conversions.
We will see more details about all these functions in my next post.

Thanks for visiting..hope this helps you!









Tuesday, December 13, 2016

Sample GROUP BY Clause in SOQL

Sample SOQL query to fetch case count based on the owner.

SELECT Owner.name, COUNT(CaseNumber)
FROM Case
GROUP BY Owner.name




Thank you...Enjoy!

Friday, July 15, 2016

Limitations of @InvocableMethod annotation in Salesforce

@InvocableMethod:

This Annotation will be used whenever you want to invoke an apex method from the Process Builder then that method must be declared as @InvocableMethod ,otherwise it can't be accessed in Process Builder .@InvocableMethod annotation have some limitations when your using it.

Limitations of @InvocableMethod Annotation:

  • Invocable method will not accept more than one argument as a method parameter
  • Only static methods can be invocable methods
  • More than one invocable method is not allowed per class

Method with Invocable Annotation Example:

public class UserHistoryProcessor
{
   @InvocableMethod 
  public static void updateUserHistory(List<Id> userIds)
  {
    //related code here
  }
 
}


Thanks for visiting...Enjoy!

Salesforce Interview Questions -Compact Layouts

1. What is Compact Layout?

    The devices like in Mobile (Salesforce1) we will be running out with space constrains . So with the help of Compact Layouts we can  highlight the record key fields at glance .These layouts will help you to arrange necessary fields at record's highlight area.

2. If you haven't created compact layout what will happens in Salesforce1?

    It's not required to create a compact layout in salesforce .If you haven't created system will uses a predefined system generated read only compact layout

3. What fields will be included in default compact layouts?

    It will includes only Name field as part of compact layout

4. How many fields will be shown as part of record highlights section ?

   In Salesforce1 first 4 fields will be included
   In Lightning Experience first 5 fields will be included

5. How many fields you can add to Compact Layouts?

   10 fields

6. What are unsupported field types in compact layouts?
  • Text areas
  • Long text areas
  • Text areas
  • Multi-select pick lists
7. Can we assign different compact layouts to different users?
   
    No,only one compact layout will be assigned to all users

Thanks for visiting..hope this helps you!

Compact Layouts Salesforce Interview Questions

1. What is Compact Layout?

    The devices like in Mobile (Salesforce1) we will be running out with space constrains . So with the help of Compact Layouts we can  highlight the record key fields at glance .These layouts will help you to arrange necessary fields at record's highlight area.

2. If you haven't created compact layout what will happens in Salesforce1?

    It's not required to create a compact layout in salesforce .If you haven't created system will uses a predefined system generated read only compact layout

3. What fields will be included in default compact layouts?

    It will includes only Name field as part of compact layout

4. How many fields will be shown as part of record highlights section ?

   In Salesforce1 first 4 fields will be included
   In Lightning Experience first 5 fields will be included

5. How many fields you can add to Compact Layouts?

   10 fields

6. What are unsupported field types in compact layouts?
  • Text areas
  • Long text areas
  • Text areas
  • Multi-select pick lists
7. Can we assign different compact layouts to different users?
   
    No,only one compact layout will be assigned to all users

Thanks for visiting...Enjoy!


Business Scenarios That Are Not Supported in Lightning Experience

Salesforce Lightning Experience:

Each object in world will have it's own Pros and Cons .Based on the situations we have to pick the things which suits best for your functionality .Similarly Lightning Experience has it's own advantages as well as disadvantages compared to Salesforce Classic.At this point of time it's better saying not supported instead of framing it as a disadvantages because Salesforce Team is working very hard to bring all the features that supports in Salesforce Classic to Salesforce Lightning .It will take some time.

In this post I'm gone explain you some of the business scenarios that will support in Salesforce Classic and but not in Salesforce Lightning.
  • If your current business is related to Quotation generation with help of Standard Quotes in Salesforce that will not be supported in Salesforce Lightning .
  • If your Sales process team using any kind of forecasting mechanism to manage your company pipeline that will not supported in Salesforce Lightning.
  • If your sales team using Sales console to manage the multiple leads at a time that feature is also not available in Salesforce Lightning.
Above listed business scenarios are few examples .Please follow the same blog to find many other Pros and Cons related to Salesforce Lightning in upcoming posts.

Thanks for visiting...Enjoy!




Thursday, July 14, 2016

How To Access Global Quick Actions in Salesforce Lightning Experience

Follow below steps to Access Global Quick Action in Lightning Experience

1. Goto Setup in LE and locate + plus symbol next to App Launcher



2. Click on Plus symbol to access available Global Quick Actions



3. Click on New Task to create a task from home page then in right hand side at bottom a form will be open to create a Task .Fill it and click save to create a quick Task



Thanks for visiting...Enjoy!

List of Annotations in Salesforce Apex

Usually Annotation means which will specifies the behavior or modifies the way how the particular class or method behaves in salesforce. Based on annotations the functionality or behavior and usage of particular class or method we can simply identify.

  • Each annotation will starts with '@' symbol and followed by name of the annotation
  • To declare a method/class with annotations it must be declared immediately before method/class  
Method with Annotation Example

public class UserHistoryProcessor
{
   @InvocableMethod 
  public static void updateUserHistory(List<Id> userIds)
  {
    //related code here
  }
 
}

List of Available Annotations in Apex

  • @isTest
  • @InvocableMethod
  • @InvocableVariable
  • @future
  • @AuraEnabled
  • @ReadOnly
  • @RemoteAction
  • @TestSetup
  • @TestVisible
  • @Deprecated
Apex REST annotations:
  • @RestResource(urlMapping='/yourUrl')
  • @HttpDelete
  • @HttpGet
  • @HttpPatch
  • @HttpPost
  • @HttpPut
we will discuss about each and every annotations with examples in next post please keep following the blog for latest updates

Thanks for visiting...Enjoy! 

How To Enable a Lightning Experience In Salesforce Orgs

Please follow the below steps to enable a lightning experience in Salesforce

1. Go to Setup---->In Left side navigation click on Lightning Experience link

 2. Go to Enable the New Salesforce Experience 

3. Draw as shown in image to enable the lightning experience


 4. Click on Finish Enabling Lightning Experience button to finsih it up.

5. Go to Setup--->Click on Switch to Lightning Experience link to open Lightning Experience



Thanks for visiting...Enjoy!

Wednesday, July 13, 2016

How to Change the Default Navigation Menu Items in Salesforce Lightning Experience.

We already started exploring on lightning experience ,which is an latest UI which will helps the Sales reps to access necessary data at glance to close more deals with lightning speed.In this post I will explain how to change the default navigation menu options in lightning experience.

Navigation Menu:

Below Screen shows what is meant by Navigation Menu in lightning experience .It usually contains all objects tabs.To change the tabs or to reorder the tabs in side navigation please follow further steps



1. Goto Setup--->Apps--->Navigation Menu--->Click on New button as shown below.


2.Enter Label Name and Description for Navigation Menu and click on Next button

3.Please Select/Deselect the Required Tabs from Available Items/Navigation Menu Items respectively


4.Please Select the list of Profiles to whom you want to apply these Navigation Menu



5.Click on Save and Finish Button and Reload the complete page and see the changes in Menu



Thanks for visiting...Enjoy!

List of the Editions That Supports Lightning Experience

As we already known that Salesforce have many types of editions to support for Small sized organisations to Large sized organisations.To understand whether your current org supports the lightning experience or not please look at the below table.


Supported Editions
Unsupported Editions
·         Group Edition
·         Professional Edition
·         Enterprise Edition
·         Performance Edition
·         Unlimited Edition
·         Developer Edition

·         Personal Edition
·         Contact Manager Edition
·         Database.com Edition
·         Chatter.com Edition



Thanks for visiting...Enjoy!

Tuesday, July 12, 2016

System.QueryException: List has no rows for assignment to SObject

Usually we will come across this type issue in many places and in many situations also .In the same way I have come across the same issue in one of the my class and I have done some work around it to fix this issue.I will explain this one with an example which may brings you an complete understanding about the issue.

Scenario:
I have 3 objects called Time_Track__c,Expert__c and User.Expert__c and User having a lookup relationship where User (Sforce_User__c) is acting as parent for Expert object and Time_Track__c and Expert__c also having lookup relationship where Time_Track__c is acting as child for Expert (Expert_Name__c) object .I have an visual force page which is using Time_Track__c  as a Standard Controller and I am having some extension class on same page .In the constructor of the extension class I am trying to query on Expert__c object based on logged in user to assign this expert to new time track as shown below

Source Code:
public class TrackExtn {
  public Time_Track__c timeTrack{get;set;} 

  public TrackExtn(ApexPages.StandardController controller) {
    timeTrack = new Time_Track__c();        
    timeTrack= (Time_Track__c)controller.getRecord();
       
    if(controller.getId()==null)
    {
       Expert__c exp = new Expert__c();
       //In below line you will receive List has no rows for assignment to SObject
       exp = [Select id from Expert__c where Sforce_User__c=:UserInfo.getUserId() limit 1];
       timeTrack.Expert_Name__c = exp!=null?exp.id:null;
           
    }

    }
}

Error:

When you execute the above code at run time if your having at least one matching Expert__c record for logged in user it will work very smoothly .If there is no matching Expert__c record for logged in user will end up with System.QueryException: List has no rows for assignment to SObject . Even if the matching record is not there it should continue fir the next lines with out throwing any error but here it's failing and terminating the complete execution. To handle this we need to follow below work around solution.


Workaround Solution:

We need to convert the Query result holder from SObject type to List<SObject> type that will resolve the issue .Please look at the below code for the work around solution

public class TrackExtn {
  public Time_Track__c timeTrack{get;set;} 

  public TrackExtn(ApexPages.StandardController controller) {
    timeTrack = new Time_Track__c();        
    timeTrack= (Time_Track__c)controller.getRecord();
      
    if(controller.getId()==null)
    {
        //Convert Sobject type to List<Sobject> type to store query result
        List<Expert__c> listexp =new List<Expert__c>();
        listexp = [Select id from Expert__c where Sforce_User__c =:UserInfo.getUserId() limit 1];
        System.debug('loggedinTech ..'+listexp );
        td.Technician__c = listexp.isEmpty()?null:listexp[0].id;
           
    }

    }
}

Thanks for visiting...Enjoy!

Monday, July 11, 2016

System.QueryException: Only variable references are allowed in dynamic SOQL/SOSL.

Error:

Whenever your working with Dynamic SOQL construction you should be very careful regarding the Single Quotes(',') or Open/Close parentheses'(' ')'  and bind variables(':') in query string.If your also getting the same error as mentioned above please refer below code.

Source Code:

public void fetchOrders()
{
List<Order__c> listOrders = new List<Order__c>();
String selWOStatus ='Test'  // Usually value for this comes from visual force page

String q ='SELECT Id, Name, Location__c,End_Date__c,Createddate FROM Order__c where 
           Location__r.OwnerId=:'+UserInfo.getUserId();
                        
if('All'.equalsIgnoreCase(selWOStatus))
  q + = ' AND (Createddate =LAST_N_MONTHS:6 OR End_Date__c < NEXT_N_MONTHS:6) LIMIT 1000'; 

else
  q + =' AND (Status =\''+String.escapeSingleQuotes(selWOStatus)+'\' 
         AND Createddate = LAST_N_MONTHS:6) LIMIT 1000';

System.debug('q....'+q); 

listOrders  = Database.query(q);

System.debug('listTSOOrders....'+listOrders);

}

When you run this above code at run time you will end up with System.QueryException: Only variable references are allowed in dynamic SOQL/SOSL .This is due to the (':') bind variable usage in dynamic query construction which will cause the error and that causes missing a single quote for logged in user ID as shown query string coming at run time as shown below

Actual Query String at Run time:

'SELECT Id, Name, Location__c,End_Date__c,Createddate 
FROM Order__c 
where Location__r.OwnerId=:00560000004LFQkAAO 
AND (Status ='Test' AND Createddate = LAST_N_MONTHS:6) LIMIT 1000';

Excepted Query String at Run time:


'SELECT Id, Name, Location__c,End_Date__c,Createddate 
FROM Order__c 
where Location__r.OwnerId='00560000004LFQkAAO'
AND (Status ='Test' AND Createddate = LAST_N_MONTHS:6) LIMIT 1000';


Work Around Solution
Remove bind variable from query string and add single quotes before and after the user id

public void fetchOrders()
{
List<Order__c> listOrders = new List<Order__c>();
String selWOStatus ='Test'  // Usually value for this comes from visual force page

String qry ='SELECT Id, Name, Location__c,End_Date__c,Createddate FROM Order__c where 
           Location__r.OwnerId=\''+UserInfo.getUserId()+'\'';
                        
if('All'.equalsIgnoreCase(selWOStatus))
  qry + = ' AND (Createddate =LAST_N_MONTHS:6 OR End_Date__c < NEXT_N_MONTHS:6) LIMIT 1000'; 

else
  qry + =' AND (Status =\''+String.escapeSingleQuotes(selWOStatus)+'\' 
         AND Createddate = LAST_N_MONTHS:6) LIMIT 1000';

System.debug('qry....'+qry); 

listOrders  = Database.query(qry);

System.debug('listTSOOrders....'+listOrders);

}


Thanks for visiting...Enjoy!

How To Fetch Next 6 Months or Last 6 Months Records From Salesforce

If your trying to fetch records from Salesforce based on some date values likes today ,tomorrow,last few days/months/weeks/years or next few days/months/weeks/years we can make use of the Salesforce Date Literals to simplify the SOQL query as much as possible and each literal is a range of time beginning with midnight (12:00:00).



Below sample code will explains you how to build a dynamic SOQL query using NEXT_N_MONTHS and LAST_N_MONTHS date literals to fetch Next 6 months and Last 6 Months records from Salesforce.

Sample Code:


public void fetchOrders()
{
List<Order__c> listOrders = new List<Order__c>();
String selWOStatus ='Test'  // Usually value for this comes from visual force page

String qry ='SELECT Id, Name, Location__c,End_Date__c,Createddate FROM Order__c where 
           Location__r.OwnerId=\''+UserInfo.getUserId()+'\'';
                        
if('All'.equalsIgnoreCase(selWOStatus))
  qry +=' AND (Createddate =LAST_N_MONTHS:6 OR End_Date__c < NEXT_N_MONTHS:6) LIMIT 1000';
  
else if('Open'.equalsIgnoreCase(selWOStatus))
  qry +=' AND (End_Date__c < NEXT_N_MONTHS:6 AND (Status !=\'Closed\' AND 
         Status !=\'Canceled\' AND Status !=\'Converted\')) LIMIT 1000';
    
else
  qry +=' AND (Status =\''+String.escapeSingleQuotes(selWOStatus)+'\' 
         AND Createddate = LAST_N_MONTHS:6) LIMIT 1000';

System.debug('q....'+qry); 

listOrders  = Database.query(qry);

System.debug('listTSOOrders....'+listOrders);

}


Thanks for visiting...Enjoy!

Friday, July 8, 2016

How to Show Place Holder For Input Fields in Visual Force Page

Source Code


<apex:page standardController="Account">
    <apex:form >
    <apex:sectionHeader title="Place Holder in Salesforce"/>
      <apex:pageBlock title="Account Information">
       <apex:pageBlockSection >
           <apex:inputField value="{!account.name}" html-placeholder="I Love Coding...You?"/>
           <apex:inputField value="{!account.AccountNumber}" html-placeholder="478788788"/>
           <apex:inputField value="{!account.Site}" html-placeholder="srinivas4sfdc.com"/>
           <apex:inputField value="{!account.Fax}" html-placeholder="A77GHSH"/>
       </apex:pageBlockSection>         
      </apex:pageBlock>
    </apex:form>
  </apex:page>

Output




Thanks for visiting...Enjoy!

System.StringException: Invalid id Error in Salesforce

Usually this kind of error we will be receiving in test classes.This is due to when your working with any kind of relationship fields in objects.Let me explain with an example below

Error:

We have a two objects called Order__c and Time__c and these two objects are having a lookup relationship where Order__c is Child and Time__c is a parent.Now i have to create a test record for Time__c along with Order__c and then I want to update Time__c record Order__c with null value.
@isTest 
private class TestTimeEntry {
    static testMethod void validateTime() {
        Order__c ord = new Order__c();
        ord.Name ='Test Order';
        insert ord;
        
        Time__c tm1 = new Time__c();
        tm1.Order__c = ord.id;
        tm1.name = 'test time';
        insert tm1;
        
        Time__c tm2 =[Select id,name,Order__c from Time__c where id=:tm1.id];
        tm2.Order__c =''; //At runtime we will receive Error here
        update tm2;
    }
}

Root Cause:

So when you run this test class you will receive a runtime error called System.StringException: Invalid id  at an update statement due to assigning an empty string(empty space) to Order__c.Usually all relationship fields will accepts Ids or null key word. 

Work Around Solution
So when your trying to assign an empty value for relationship field we have to specify null keyword instead of an empty space('')
@isTest 
private class TestTimeEntry {
    static testMethod void validateTime() {
        Order__c ord = new Order__c();
        ord.Name ='Test Order';
        insert ord;
        
        Time__c tm1 = new Time__c();
        tm1.Order__c = ord.id;
        tm1.name = 'test time';
        insert tm1;
        
        Time__c tm2 =[Select id,name,Order__c from Time__c where id=:tm1.id];
        tm2.Order__c =null; //An empty space replaced with null keyword
        update tm2;
    }
}



Thanks for visiting...Enjoy!


Spring 16 Salesforce Developer 401 Maintenance Exam Questions

1.Which standard field can be updated using formula rules in process builder?
  • Created Date 
  • Owner ID
  • Deleted
  • ID

2.What must be true when accessing a user's private reports and dashboards?Choose 2 answers
  • Having the "Manage All Private Reports and Dashboards" permission.
  • Using the "allPrivate" with the "scope" condition in a SOQL query.
  • Using the "allPrivate" with the "where" condition in a SOQL query.
  • Having the "Administrator Access to Private Files" permission.

3.What is true about Data Loader?Choose 3 answers
  • It can be used with SAML Authentication.
  • It can be used with both Mac and PC.
  • It can be used with OAuth Authentication
  • It can be used with Password Authentication.
  • It can be used with only a PC.

4.Which Quick Actions can contain a "Custom Success Message?"Choose 2 answers
  • Visit a website
  • Update a Record
  • Log a Call
  • Send an Email

5.What is true about the file sharing "Set by Record?"
  • It is used to infer sharing via the record type.
  • It is used to infer sharing via the parent record
  • It is used to infer sharing via the record owner
  • It is used to infer sharing via the associated record.

Thanks for visiting...Enjoy

Wednesday, July 6, 2016

Winter 16 Salesforce Developer Maintenance Exam Questions

1. In a Salesforce organization using state and country picklists, what feature allows a Lightning Experience user to choose the correct address when entering information in a standard address field?
  • Auto-completion for standard address fields.
2. What is an enhancement to Process Builder? Choose 2 answers
  • Administrators receive a fault email when a process fails due to user inactivity 
  • More than one schedule can be enabled for a single action 

3. What is an enhancement to Salesforce Files? Choose 2 answers
  • A file owner can freeze a file to prevent additional shares of the file.
  • An administrator can control whether users can upload files from Salesforce.

4. What is an enhancement to working with records in Chatter Groups? Choose 2 answers
  • When a group is @mentioned on a record, that record becomes a Group Record.
  • Group Records are displayed in the groups related lists.

5. By default, which users have access to Lightning Experience once it has been enabled?
  • All users with Standard Salesforce profiles

Thanks for visiting...Enjoy!