5 Mistakes A Salesforce Developer Can Commit Or Should Avoid

5 Mistakes A Salesforce Developer Can Commit Or Should Avoid

This Salesforce Blog is a developer’s experience in the Journey of Force.com development and customization. The problems faced by a day to day developer and the mistakes committed by them can sometimes be interesting and useful to a wide range of developers and administrators.

So let’s start the epic!!

Do Not Hardcode:

Once upon a time I was developing on a VF page and provided a link to a report(Our Standard Salesforce Reports in Visualforce Page:

So I hardcoded the URL for report as link in my VF page. The URL was working fine in sandbox and I was happy. Once I was done with development I migrated my changes to Production environment, Finally when I tested the application on the website I was unable to see the report on clicking the link.

But I got to know later that I cannot modify the apex class in production environment and I needed to fix it ASAP so it was all a big mess!

After scrutinizing the snag , I found that I had hardcoded the URL for my report and since the environment has changed  URL had stopped working.

So I finally  figured it out  using concept of dynamic URLs and used some code snippet like below:

“URL.getSalesforceBaseUrl().toExternalForm()+’/’+reportId”

Final Verdict: > DO NOT HARDCODE!!!

Avoid SOQL Errors:

While Developing have you encountered errors such as  “System.LimitException: Too many SOQL queries: 101” ?

This error System.LimitException : Too many SOQL queries: 101 is due to the fact, you are hitting on governor limit.

Our esteemed  Governor limits  says that you can run total 100 SOQL queries in a context and you are hitting the limit.

After a thorough study on the same I found that all the triggers fired will be counted in a single context or call. We need to ensure that total number of SOQL fired should be less than 100.

In order to pass this,  Many times i changed my  code in such a way that SOQL fired must be less than 100.

Sometimes I have also preferred if (only  we need to change the context)  using  @future annotation when I was required to run  the code asynchronously.

I made sure always  that the SOQL query I use should not be inside the for loop.

There are certain best practices which you would have to follow to avoid this error (to avoid hitting governor limit).

https://wiki.developerforce.com/page/Best_Practice:_Avoid_SOQL_Queries_Inside_FOR_Loops

http://salesforcedeveloperblog.blogspot.com/2011/05/best-practices-of-triggers.htmhttp://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_bestpract.htm

http://wiki.developerforce.com/page/Apex_Code_Best_Practices

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm

 Always follow the above practices to make sure you stay smiling at your workplace..

The challenging part is that one cannot increase the governor limit and can only follow best practices.

Streamline Multiple Triggers on same Object

 So here Is one more tricky situation:

Once I was working on a requirement (in short)  on the esteemed object Case to assign the account manager automatically. So I wrote a trigger which was  “Before Insert”.

I found that sometimes the account manager assigned was as expected and sometimes NOT!!

I was Bewildered !!

Like Always I started digging out checking debug logs, manual testing etc etc.

Finally Debug log was a ‘Maseeha’ telling me that I do have two more triggers with “Before Insert “ due to which system was unable to recognize the order of execution. Probably those codes were drafted by some other developers( of course my current and previous colleagues). I sat with them and finally came up with a single trigger with the same event on the object.

So in practice, Avoid multiple triggers with the same event on an object because it may discommode you at times.

Bulkify Your Code

So in the initial days of my Salesforce Development career, I faced something very terrible and good learning of course for me.

Let’s start with giving you some glimpse on my  poorly written code that only handles one record :


trigger BeforeInsert_Account on Account (before insert){

//This only handles the first record in the Trigger.new collection but if more than 1 Account initiated this trigger, those             additional records will not be processed

Account objAccount= Trigger.new[0];

List<Contact> contacts = [SELECT ID,salutation,firstName,lastName,email FROM Contact WHERE
 accountId = :acct.Id];

//and something something

} 

I tested the trigger and it worked fine and I was done by my job and then suddenly one day trigger hit the governor limits.

Like always I was bewildered. Got to know that one of my sweet colleague has written a batch apex to insert the Accounts and this was the whole sole reason.

Since I couldn’t ask my sweet colleague to undo the batch class, I need to do something.

After digging,I found that if a batch of records invokes my Apex code, all of those records need to be processed as a bulk, which hits governor limits.

And the issue was  that only one Account record was handled because the code explicitly accesses only the first record in the Trigger.new collection by using the syntax Trigger.new[0]. Instead, the trigger should properly handle the entire collection of Accounts in the Trigger.new collection.

Here is a sample of how I handled all incoming records from batch:

trigger BeforeInsert_Account on Account (before insert){

//This only handles the first record in the Trigger.new collection but if more than 1 Account initiated this trigger, those additional records will not be processed

Account objAccount= Trigger.new[0];

List<Contact> contacts = [select ID, salutation,firstName,lastName,email FROM Contact 
WHERE accountId = :acct.Id];
//and something something……
}

Notice how this revised version of the code iterates across the entire Trigger.new collection with a for loop. Now if this trigger is invoked with a single Account or up to 200 Accounts, all records will be properly processed.

So always put down strategy to write bulkified code.Make it as practice, though it will be not easy but good for long terms!!

Follow General Design Guidelines for Application Performance

As per my experience in designing Visualforce you may develop a very rich UI with nice pop-ups and images but when the users start using it ,it becomes nettlesome for them to click or navigate to buttons.

I have written these general guidelines to avoid performance impacts:

  • Always design pages around specific tasks, with a sensible workflow and navigation between tasks.The DOTS should be connected everywhere.
  • Never  overload pages with functionality and data. Visualforce pages with unbounded data or a large number of components, rows and  fields have poor ability and performance, and they risk hitting governor limits for view state, heap size, record limits, and total page size.
  • Always try to push back on requests to include non-essential functionality.
  • Must Build prototypes to validate concerns.

 References:

https://developer.salesforce.com/blogs/developer-relations/2015/01/apex-best-practices-15-apex-commandments.html

Salesforce Sandboxes – Key Player in Managing & Deploying Customization

Salesforce Sandboxes – Key Player in Managing & Deploying Customization

What is a Sandbox?

A Sandbox to a developer/administrator is like a playground for a child, it allows the developer/administrators to customize, play and configure the application development environment without affecting the actual production release versions. Sandboxes in Salesforce are used for app development, code management, version control, testing, and training without compromising the actual data and applications in your Salesforce production organization.

Types Of Sandboxes:

  Developer Sandbox Developer Pro Sandbox Partial Copy Sandbox Full Sandbox
What is their Usage? For coding and testing in an isolated environment For coding and testing in an isolated environment For  Testing environments and quality assurance task For testing environments and for performance and  load testing and staging
What do they include of  Production Environment? A copy of production organization’s configuration (metadata). A copy of production organization’s configuration (metadata). They have a larger storage limit than Developer sandboxes. A copy of production organization’s configuration (metadata), and a subset of production data as defined by a sandbox template. Replica of the production organization.
Licenses with which you can create Sandboxes  ·  Full Sandbox ·  PartialCopy Sandbox ·  Developer Pro Sandbox ·  Developer Sandbox · Full Sandbox · PartialCopy Sandbox · Developer Pro Sandbox · Full Sandbox · PartialCopy Sandbox · Full Sandbox

Sandboxes In SDLC Process

In a Salesforce app development life cycle, comes various phases of code development, unit testing, UAT etc. A simple example is: 

   In a case when different teams work on multiple areas simultaneously which finally have to be merged into a single organization, that is a single Production environment, with time the process becomes rather complex. It overcomes this a staging platform is created to repressively test the performance without affecting the production version. An example for the same is shown below: 

Managing Sandboxes For Release Management Process

Though there is no thumb rule or out of the box process defined on which organizations are dependent on handling their release management system. But still there are some points on sandboxes to be considered for running the process:

  • Make a practice to refresh the sandboxes after every release so that we make sure to leverage the new features and make sure that our environment is compatible with the new changes.
  • Also, it’s recommended to have a strategy to align the org releases with Salesforce releases, in order to reduce the efforts for refreshing sandboxes.
  • A Post Refresh Run List should be prepared and followed every time sandboxes are refreshed after a new release. Few things which should be included are:
    • Data Masking Needs
    • User Profile Modifications
    • Test Data Loads
    • Deployment Plan
    • Turn Off Scheduled Jobs
    • Manage Outbound Email.

Hope this would help you in getting an overview of what Salesforce sandboxes are.

Publishing An App On AppExchange

Publishing An App On AppExchange

What is AppExchange?

The AppExchange is the world’s first on-demand application-sharing service. It provides a way to browse, test drive, share and install applications developed on Salesforce’s on-demand AppExchange platform. Partners, developers, and anyone else who chooses to participate can offer their Apps on the AppExchange directory. This directory gives Salesforce users an easy way to find and install applications to expand their use of the AppExchange platform to new areas of customer relationship management (CRM) and beyond.

Register as a Salesforce.com Partner

To do this, go to http://www.salesforce.com/partners/join/  and fill the form. You’ll receive by email a login to the Salesforce.com Partner Portal, which allows you to do all sorts of necessary things in the Partner lifecycle, like creating special org’s, logging partner support cases, and getting access to special training materials, etc.

Install License Management App

If you’ll be publishing apps on the AppExchange, install the free License Management App (LMA) app. With the LMA, you can automatically receive notification every time your package (app) is installed or uninstalled, thus letting you track users and easily notify them of any upgrades you publish.

Publishing an App on AppExchange

To make your app or consulting service available on the AppExchange, you must create a listing:

  1. Log into your AppExchange Publishing Organization (APO) or the organization you will designate as your APO once you log in.
  2. Create a provider profile.
  3. Create a new listing.
  4. If your listing is an app instead of a service, submit the app’s package for security review.
  5. After your app is approved, click Make Public to make your listing available to the AppExchange community. Public consulting services do not need a review.

Create APO

Once you are signed up as a partner, create an AppExchange Publishing Org (APO). In the Partner Portal, you’ll see a big button at the top of the screen labeled, “Create A Test Org.” For org type, select “Partner Developer Org.” You will receive new credentials by email. Be sure to login and set your password before proceeding. Note that the system will pick a username for you. If you don’t like it, feel free to change it. The purpose of this org is to help you publish listings on AppExchange.

AppExchange Publishing Organizations operate on a hub and spoke model. The APO is the hub. It contains all of the information about your company but doesn’t contain any information about your apps. Apps should always be developed in an org other than your APO. When you are ready to publish an app, simply click on the “Your Organizations” link and add the developer edition where you package your app to your APO. Once you connect the org’s, you will be able to see information from your spoke org’s in your hub APO org.

Create a  Provider Profile

Creating an AppExchange provider profile will allow you to list and publish your AppExchange App. People browsing your listings see the profile information on the Provider tab. You can also create a provider profile for your linked organizations although this profile will not be public. To create your AppExchange profile, log into your Partner Dev Org and click on the link provided on the detail page of your latest package; then click on the Start Publishing button to create your AppExchange provider profile.

Create a new Listing

Listings are the primary marketing tool for promoting your app or consulting service on the AppExchange. The more information you add to your listing, the more likely it is that users can find it.

Once you have an AppExchange Provider Profile, you can go to the Publishing tab, where you can create a new listing. A new listing is always private until the app passes the security review. While private, your app has a link on the AppExchange (which you can send to potential users), but it is not listed publicly and does not show up in searches.

To create a listing on the AppExchange, you must log in to the publishing console of the site. If you are both the developer of an app and the person responsible for creating the listing content (aka the publisher), you can start your listing by simply logging into the AppExchange with your developer edition credentials. Alternatively, if these roles are delegated, both the developer and the listing publisher can work on the app and listing in parallel, log into the publishing console with their respective credentials, and then link the two together.

Security Review

Before Salesforce approves any listings, the app must undergo tests from their security review team. From the Offering tab, we can submit the package associated with the listing to AppExchange for approvals. An email is automatically generated and sent to the submitter asking for a Checkmarx security test and questionnaire to be completed. These include some general questions about the app if there are Apex classes and Visualforce components, etc. If the app fails the first round, don’t worry; go back and fix the problems that are noted by the Checkmarx test or from the AppExchange team.

The security review process follows these steps.

1) Prepare for the security review.
  • Read the security guidelines in this chapter.
  • Review the free resources listed on our Secure Cloud Development site.
  • Check out the Security Review Hub in the Partner Community for preparation tips.
  • Review the Requirements Checklist.
  • Review the OWASP Top Ten Checklist.
  • Run a free self-service source code analysis against code developed on the Force.com platform:
  • Run a free web application scan against your external web-application that is integrated with Force.com.
  • Manually test your app to ensure it meets review requirements not found by tools
  • Fix any issues found during testing.
 2) Initiate the security review.
  1. Log in to the AppExchange using the credentials for your APO.
  2. Click your name in the upper right corner and from the drop-down menu, select Publishing Console.
  3. If your app contains a managed package, click Start Review next to the package version that you want to submit.
  4. If your app uses the Salesforce API and does not contain a managed package, complete these steps.
    –  Click the Offering tab in your private listing.
    –  Select Your application is not a package and only uses the Salesforce API.
    –  Click Start Review.
  1. For each application, you’ll complete a security checklist and questionnaire. Provide the review team with a fully configured test environment that includes access information, login credentials, and all required automated scans.
  2. Pay the annual listing fee (for a paid app) and a one-time security review fee.

If your app is due for a subsequent security review, log a case in the Partner Community.

3) Review the results

There are three possible outcomes.

  • Approved:  You will immediately be allowed to list your application on the AppExchange. You might be provided an API token to access Professional Edition accounts. For more information on the Partner Program, including eligibility requirements, please visit us at www.salesforce.com/partners.
  • Provisionally Approved:  Low or medium risk issues were identified, which can be addressed fairly easily and do not pose a significant risk to Salesforce or its customers. You will be allowed to create a public listing for your application on the AppExchange. However, failure to remedy the noted issues within the specified time period will result in the removal of the application from AppExchange. You might be provided an API token to access Professional Edition accounts.
  • Not Approved:  High-risk issues were identified during the testing phase. You will not be allowed to list your application on the AppExchange until all issues have been addressed and reviewed by the AppExchange security team. If the application is already listed on the AppExchange, you will be provided 60 days to address issues. You will not receive an API token to access Professional Edition accounts.

 Go Public

Once you have passed the security review you may login to the AppExchange and make your listing live.  This is done from the publishing tab from the screenshot above. On this tab are Your Public Listings and Your Private Listings. On the private listings tab, the app will have a link saying “Make Public”. At this point, the app is available on the AppExchange for any and all to see. Also, Salesforce includes this recent addition in the weekly AppExchange Digest emails that are distributed, providing some free press for your app in the community.

Demand Tools

Demand Tools

What is Demand Tools

Demand Tool is the leading data quality & data cleansing toolset for salesforce.com customers worldwide. Demand Tools is a suite of 10+ individual data quality modules to control, standardize, de-duplicate, import and generally manipulate Salesforce and/or Force.com data. Designed to work in the Developer, Professional, Enterprise and Unlimited versions of Salesforce. Demand Tools is a client-based application that Salesforce administrator’s install on their Microsoft Windows computer.

How to install Demand Tools:-

Step 1: Go to https://www.crmfusion.com page.

Step 2: click on Download Trail Tab.

Step 3: Download Demand Tools 2.7 (32 bit or 64 bit).

Step 4: Double click on Demand Tools Setup and follow the instructions step by step.

After Successful installation, a window appears like below:-

Now if you want to use Demand Tools with your sandbox for a trail, first you need to click on Proxy/Endpoint Setup and then click on Use Custom Endpoint checkbox and Enter your custom Endpoint and press OK Button and then click on Sandbox Login Checkbox and then enter your Salesforce Username and password and then click on Login to Sandbox Button.

Note: Custom EndPoint Like-  https://test.salesforce.com/services/Soap/c/39.0
After this, a new window has opened like below:-

Here, enter your Salesforce.com Organization ID and after filled this, click on Create Trial Account Button. This trial account is valid for only five days from created date.

Demand Tools Modules

The Demand Tools has the number of modules but some important modules are described below:-

The Demand Tools MassImpact module is used to modify hundreds or thousands of EXISTING records WITHOUT importing or exporting. Like, update shipping addresses fields with data from the business address fields. This module can be used to perform data standardization functions to normalize data across records and Transferring account address information to associated contacts and Concatenating field values from multiple fields into one. You can create and save custom scenarios for future use.

The MassEffect module is used to perform Insert/Import, Update, Upsert, Delete, Export operation within Salesforce. This Module is used for many important cases like if you want to Migrate data from legacy systems to Salesforce and Insert Salesforce Content that resides locally on your PC (in .csv file) and you can create and Save field mapping for future use by creating the template which is used for all imports and updates.

Power Grid module is used to update mass records with an easy to use grid based view of the data.  Here, Fields can be updated directly inside the grid with the ability to review all changes before pushing the updates to Salesforce.  It is primarily designed for use with a maximum of about 20 K records at one time.  If you have recorded more than 20 k you can also use this but it takes more processing time. You can also perform delete operation on records within Salesforce.

The Reassign Ownership module can be used to mass transfer the ownership of ANY object in Salesforce and its related sub-objects in a single pass using either a set of user-specified conditions or an input file of ID’s to determine which records should be reassigned.  A single new owner can be specified, or a group of records can be assigned to multiple new owners, either randomly or by specifying match conditions. You can also Create Tasks or Summary Events to track ownership changes on the parent object record.

The Demand Tools MassBackup module allows the user to take backup with user-friendly interface and it creates a .mdb backup file of Salesforce data on your local computer.  The .mdb database that is created is fully relational and useful for different types of integrations. This module is supported with the 32bit version of Demand Tools. But the overall size of the resulting .mdb file also cannot exceed 2GB.

BulkBackup module also used for backup your Salesforce data but it uses Bulk API to export the data and save to .mdb (32bit only) or .csv files. It has user-friendly interface and this module will not work for Salesforce Professional Edition (PE) Users because BULK API is not supported by Salesforce in Professional Edition.

Report Edit module is a simple module that provides access to all custom Salesforce reports allowing for some basic operations to be performed like Rename Reports, Update Report Descriptions and Delete Reports. Only users with “Modify All Data” on their Salesforce Profile will be able to use Report Edit due to Salesforce’s complex report permission structure.

Pin It on Pinterest