How to get @mentioned user from Feed Item in Salesforce?

Sample Code:

String communityId = null;
String feedItemId = '0D529000001ABmQCAW';//Sample FeedItem Id

ConnectApi.FeedElement feedItem = ConnectApi.ChatterFeeds.getFeedElement(communityId, feedItemId);
List<ConnectApi.MessageSegment> messageSegments = feedItem.body.messageSegments;
for (ConnectApi.MessageSegment messageSegment : messageSegments) {
    if (messageSegment instanceof ConnectApi.MentionSegment) {
        ConnectApi.MentionSegment mentionSegment = (ConnectApi.MentionSegment) messageSegment;
        System.debug('Mentioned user name: ' +;
        System.debug('Mentioned user id: ' + mentionSegment.record);

How to query Feeds inserted by Feed Tracking?

FeedTrackedChanges is the sObject where Feeds inserted by Feed Tracking are present.

Sample Query:

SELECT ID, FieldName, OldValue, NewValue FROM FeedTrackedChanges


What are the common errors we get when moving components from Sandbox to Production in Salesforce?

1. Related components missing.

2. Lower Test code Coverage.

3. Package version variation in Sandbox and Production.

4. Long Running Test Classes due to SeeAllData=true.

5. Test Class Failures.

6. LOCK_ROW issues.


Streaming API example in Salesforce

1. Go to User Interface.

2. Enable "Streaming API".

3. Check whether your profile has API Enabled permission.

4. Go to this site and download the file -

5. Extract the downloaded file.

6. Open Command Prompt and execute the below commands;

cd cometd-2.2.0/cometd-javascript/common/target

jar xvf cometd-javascript-common-2.2.0.war org/cometd.js

Note: In command Prompt, make sure you navigate to the drive where it has been extracted.

7. Go to D:\cometd-2.2.0\cometd-javascript\common\target\org path. You will be able to find cometd.js file.

8. Go to D:\cometd-2.2.0\cometd-javascript\jquery\src\main\webapp\jquery path. In my case I extracted the file to D drive. You will be able to see the files as below:

9. Go Static Resources and create new Static Resources as below in Salesforce

File Name         Static Resource Name
cometd.js                    cometd
jquery-1.5.1.js             jquery
json2.js                     json2
jquery.cometd.js     jquery_cometd

10. Code for Visualforce and Apex.

Visualforce Page:

<apex:page controller="StreamingAPIController">
    <apex:includeScript value="{!$Resource.cometd}"/>
    <apex:includeScript value="{!$Resource.jquery}"/>
    <apex:includeScript value="{!$Resource.json2}"/>
    <apex:includeScript value="{!$Resource.jquery_cometd}"/>
    <script type="text/javascript">
        $(document).ready(function() {
            // Connect to the CometD endpoint
               url: window.location.protocol+'//'+window.location.hostname+'/cometd/24.0/',
               requestHeaders: { Authorization: 'OAuth {!$Api.Session_ID}'}

           // Subscribe to a topic. JSON-encoded update will be returned
           // in the callback
           $.cometd.subscribe('/topic/AccountUpdates', function(message) {
   function disconnect() {
   window.onbeforeunload = disconnect;
   <apex:form >
   <apex:actionFunction name="callRefresh" action="{!refresh}"/>
<apex:pageBlock >
    <apex:pageBlockTable value="{!listAccount}" var="a">
        <apex:column value="{!a.Name}"/>
        <apex:column value="{!a.AccountNumber}"/>

Apex Controller:

public class StreamingAPIController {        
    public StreamingAPIController() {
    public List<Account> getlistAccount() {
        return [SELECT Id, Name, AccountNumber FROM Account WHERE Active__c = true];
    public PageReference refresh() {
        return null;

11. Create a PushTopic using the below code in Developer Console.

PushTopic pushTopic = new PushTopic();
pushTopic.Name = 'AccountUpdates';
pushTopic.Query = 'SELECT Id, Name, AccountNumber FROM Account WHERE Active__c = true';
pushTopic.ApiVersion = 36.0;
pushTopic.NotifyForOperationCreate = true;
pushTopic.NotifyForOperationUpdate = true;
pushTopic.NotifyForOperationUndelete = true;
pushTopic.NotifyForOperationDelete = true;
pushTopic.NotifyForFields = 'Referenced';
insert pushTopic;

12. To test it, open the visualforce page. Open Accounts tab and create a new account with Active check box true. If you go back to the Visualforce page, the account created will be displayed there.


Get parent records with atleast one child record in SOQL

Sample Query:

SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM Contact)


Get parent records with 0 children in SOQL

Sample Query:

SELECT Id, Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Contact)


Public Calendars and Resources in Salesforce

Public Calendars:

Use public calendars to manage department or project schedules.

Resources Calendars:

Use resource calendars to manage resources such as conference rooms and projectors.

1. Go to Public Calendars and Resources.

2. Click "New".

3. Give any name. Make it active. Click Save.

4. Go to Home Page. Select any calendar view.

5. Click "Change".

6. Select the recently created Public Calendar to view it.


How to check whether a userid exists in List Custom settings in Salesforce?

Sample Code:

if ( CustomSettingsName__c.getValues(UserInfo.getUserId()) != null ) {
    //do something since it contains the user id


How to deploy LetterHead using Apache ANT Tool in Salesforce?

Sample Package.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="">


Salesforce certification verification

1. Go to the below site

2. Enter the Full Name or use the next search with Email.

3. Click "View Certifications".


How to deploy Custom Labels using Apache ANT Tool in Salesforce?

Sample Package.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="">


MISSING_ARGUMENT, Id not specified in an update call in LREngine

If you face MISSING_ARGUMENT, Id not specified in an update call in LREngine, use the below code while updating

if ( masters.size() > 0) { 
    update masters; 


Salesforce Interview questions with answers Part 33

1) Where you write code like .NET use Visual Source Safe , what Salesforce use ?

Salesforce keeps the code in

2) If there are multiple developers, whose code goes first into production what criteria u follow to send code ? how to send code to production 

Once the code is tested(UAT - User Acceptance testing) in Sandbox it will be moved to production.

3) How do you do version controlling in Salesforce?

We can use Tortoise SVN in Eclipse for this

4) Scenario : there is a company xyz has many like 1000 web pages with, u  need change to you do that with code ? how to do with your salesforce?

We can use SOSL to get the records and update them.


FIND {} IN Email Fields RETURNING Contact(Id, Email), Lead(Id, Email)

Example to get the records -

5) How many API you create in your project and how?

6) What database Salesforce uses? Is it cloud?


How to enable team selling in Salesforce?

Opportunity Teams help multiple users to better collaborate on opportunities by defining a role for each team member, setting record-level access individually, and viewing teams in list views and reports.

When enabled, the opportunity teams are available in Salesforce Lightning, Salesforce Classic, and the mobile app. Users may prepare default opportunity teams for speedy setup of new opportunities. Opportunity Teams are not the same as account teams.

1. Go to Setup --> Build --> Customize --> Opportunity --> Opportunity Team.

2. Enable Team Selling.

3. Select the layouts in Page Layout Selection.

4. Add team members using Opportunity Team related list.

Salesforce Interview questions with answers Part 32

1) What are the challenges you faced in your current job?

2) What customizations you did in your current project?

a. Workflows to automate 
b. Reports and Dashboards 
c. Approval process to approve records

3) What best practices you followed?

4) What is your team size?

Total team members. It depends upon the project. Say 10 to 20.

5) Salesforce end and end implementation process?

6) Can you tell some scenarios which you developed?

a. Sending expiry notification for credit card paid bills through batch apex
b. Sending Invoice pdf to customer once their payment is successful through trigger
c. Many Visualforce pages
d. Classes for Visualforce pages

7) Order of execution in Visualforce page

1. Constructor of the controller.
2. Action method of the page.
3. Getter methods.
4. If there are any client-side technologies on the page, such as JavaScript, the browser executes them. Example is window.onLoad().

If the page contains an <apex:form> component, all of the information necessary to maintain the state of the database between page requests is saved as an encrypted view state. The view state is updated whenever the page is updated.

How can we reset the governor limits within a test class?

Test.startTest() and Test.stopTest() are very useful when your test class hits Salesforce Governor Limits. These methods can be used to reset the governor limits within a test class.

Check the below link for more info


What is the difference between custom objects, custom settings and custom meta data?

What is Parallel Approval Process in Salesforce?

Parallel approval process allows specifying multiple approvers simultaneously.

When you select multiple approvers, then we have to choose any one of the following:

    a. Approve or reject based on the FIRST response.
    b. Require UNANIMOUS approval from all selected approvers.

The approver setting could be set to unanimous or first action. In Require UNANIMOUS approval from all selected approvers parallel approval process, all the approvers must approve a request, before it is considered as approved. But in case of Approve or reject based on the FIRST response, anyone of the Approvers can respond.


How to deploy Public Group using ant Salesforce?

Sample Package.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <Package xmlns="">  
  4.     <types>  
  5.         <members>*</members>  
  6.         <name>Group</name>  
  7.     </types>  
  9.     <version>31.0</version>  
  11. </Package>  

How to deploy Queue using ANT Salesforce?

Sample Package.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="">


How to deploy Role using ANT Salesforce?

Sample Package.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="">


How to query and update Child and Parent information from Child records in Salesforce?

Sample Code:

Contact c = [ SELECT Account.AccountNumber, LastName FROM Contact WHERE Id = '003U000001cdHIf'];
c.LastName = 'Testing';
c.Account.AccountNumber = '222';
update c;
update c.Account;


InvocableMethod Annotation

Use the InvocableMethod annotation to identify methods that can be run as invocable actions. Invocable methods are called with the REST API and used to invoke a single Apex method.

Invocable methods have dynamic input and output values and support describe calls.

For more info, check the below link


How to calculate years between two dates in Apex class in Salesforce?

Sample Code:

Date date1 =;
Date date2 =;
system.debug('No of months ' + date1.monthsBetween(date2));
String noOfYears = String.valueOf(date1.monthsBetween(date2) / 12) + ' Year(s) ' + String.valueOf(Math.mod(date1.monthsBetween(date2), 12)) + ' Month(s)';
system.debug('No of years ' + noOfYears);



What is mean by Winning Records and Losing Records in triggers?

When merge event occurs, in the deleted records, MasterRecordId field will be populated with the winning record id. The winning record will be updated with the values selected.

The losing records will be deleted and will be available in Recycle Bin.

Check the below links for more info,