How to take backup of code before Sandbox refresh in Salesforce?

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: ' + mentionSegment.name);
        System.debug('Mentioned user id: ' + mentionSegment.record);
    }
}

Cheers!!!

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

Cheers!!!

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.

Cheers!!!

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 - http://download.cometd.org/cometd-2.2.0-distribution.tar.gz

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">
    (function($){
        $(document).ready(function() {
            // Connect to the CometD endpoint
            $.cometd.init({
               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) {
               callRefresh();
            });
        });
   })(jQuery)
   function disconnect() {
       $.cometd.disconnect();
   }
   window.onbeforeunload = disconnect;
   </script>
   <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:pageBlockTable>
   
</apex:pageBlock>
   
</apex:form>
</apex:page>

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() {
        getlistAccount();
        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.


Cheers!!!

Get parent records with atleast one child record in SOQL

Sample Query:

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

Cheers!!!

Get parent records with 0 children in SOQL

Sample Query:

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

Cheers!!!

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.

Cheers!!!

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
}

Cheers!!!

How to deploy LetterHead using Apache ANT Tool in Salesforce?

Sample Package.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="">
<types>
<members>*</members>
<name>Letterhead</name>
</types> 
    <version>31.0</version>
</Package>

Cheers!!!

Salesforce certification verification

1. Go to the below site

http://certification.salesforce.com/verification

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



3. Click "View Certifications".


Cheers!!!

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

Sample Package.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="">
<types>
<members>*</members>
<name>CustomLabel</name>
</types>
    <version>31.0</version>
</Package>

Cheers!!!

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

Cheers!!!

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 Force.com

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 ...it has many like 1000 web pages with xyz@company.com, u  need change xyz@company.com to abc@company.com ..how you do that with code ? how to do with your salesforce?

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

Example:

FIND {xyz@company.com} IN Email Fields RETURNING Contact(Id, Email), Lead(Id, Email)

Example to get the records - http://www.infallibletechie.com/2016/01/what-is-return-type-of-sosl-search.html

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

http://www.infallibletechie.com/2014/01/different-apis-supported-in-salesforce.html

6) What database Salesforce uses? Is it cloud?

Database.com

Cheers!!!

How to enable team selling in Salesforce?

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


2. Enable Team Selling.


Cheers!!!

Salesforce Interview questions with answers Part 32

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

http://www.infallibletechie.com/search/label/Exceptions%20in%20%20Salesforce

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?

https://developer.salesforce.com/page/Apex_Code_Best_Practices

http://www.infallibletechie.com/2014/10/triggers-best-practices-in-salesforce.html

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?

http://www.infallibletechie.com/2015/11/life-cycle-of-salesforce.html

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

Cheers!!!

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

http://www.infallibletechie.com/2014/09/what-is-purpose-of-teststarttest-and.html

Cheers!!!

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.

Cheers!!!

How to deploy Public Group using ant Salesforce?

Sample Package.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="">
    <types>
        <members>*</members>
        <name>Group</name>
    </types>
    <version>31.0</version>
</Package>

Cheers!!!

How to deploy Queue using ANT Salesforce?

Sample Package.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="">
    <types>
        <members>*</members>
        <name>Queue</name>
    </types>
    <version>31.0</version>
</Package>

Cheers!!!

How to deploy Role using ANT Salesforce?

Sample Package.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="">
<types>
<members>*</members>
<name>Role</name>
</types> 
    <version>31.0</version>
</Package>

Cheers!!!

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;

Cheers!!!

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

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm

Cheers!!!

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

Sample Code:

Date date1 = System.today();
Date date2 = System.today().addMonths(23);
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);

Output:


Cheers!!!

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,

http://www.infallibletechie.com/2013/08/merging-in-salesforce.html

http://www.infallibletechie.com/2014/08/merge-trigger-example-in-salesforce.html

Cheers!!!