Tuesday, 28 February 2017

Salesforce Essentials - 17( Formula field to add 1 month exact in close date)

Formula field to add 1 month exact in close date

YEAR(CloseDate) + FLOOR((MONTH(CloseDate) + 1 - 1)/12), 
CASE(MOD(MONTH(CloseDate) + 1, 12 ), 0, 12, MOD(MONTH(CloseDate)+ 1, 12 )), 
CASE(MOD(MONTH(CloseDate) + 1,12), 9, 30, 4, 30, 6, 30, 11, 30, 2, 
IF(MOD(YEAR(CloseDate) + FLOOR((MONTH(CloseDate) + 1)/12), 400) = 0 || (MOD(YEAR(CloseDate) + FLOOR((MONTH(CloseDate) + 1)/12), 4) = 0 && MOD(YEAR(CloseDate) + FLOOR((MONTH(CloseDate) + 1)/12), 100) <> 0 

Monday, 27 February 2017

Salesforce Essentials - 16 (Day, Month and Year from Date)

Sample Code (Use this in apex class):

Date gettingdate;
Integer dy = gettingdate.day();
Integer monh = gettingdate.month();
Integer yer = gettingdate.year();

Sunday, 26 February 2017

Salesforce Essentials - 15 ( RENDERING THE PAGE AS PDF)


Use the renderAs directive in the tag, to render
the page as a PDF.

A Visualforce page rendered as a PDF file displays either in the browser or is downloaded, depending on the browser’s settings. Specific behavior depends on the browser, version, and user settings, and is outside the control of Visualforce.

If the PDF fails to display all the characters, adjust the fonts in
your CSS to use a font that supports your needs.

The following page includes some account details and renders as a PDF file.

Reference - https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_output_pdf_renderas.htm

Monday, 20 February 2017

Salesforce Essentials - 14 ( Managed or Unmanaged Packages)


Packages come in two forms:

  • Unmanaged
  • Managed


Unmanaged packages are typically used to distribute
open-source projects or application templates to provide
developers with the rudimentary building blocks for an application.

Once the components are installed from an unmanaged
package, the components can be edited in the organization they
are installed in.

The developer who engendered and uploaded the unmanaged
package has no control over the installed components, and can't
change or upgrade them.


Managed packages are typically utilized by salesforce.com partners to distribute and sell
applications to customers.

These packages must be engendered from a Developer Edition organization.

Utilizing the AppExchange and the License Management

Application (LMA), developers can sell and manage utilizer-predicated licenses to the app.

Manage packages are withal plenarily upgradeable. To ascertain seamless upgrades, certain
destructive changes like abstracting objects or fields may not be performed in a managed

Managed packages additionally offer the following benefits:
  • Astute property auspice for Apex.
  • Built-in versioning support for API accessible components
  • Remote access support (OAuth)
  • The competency to branch and patch an antecedent version
  • The competency to seamlessly push patch updates to subscribers
  • Unique denominating of all components to ascertain conflict free installs

Reference :https://developer.salesforce.com/docs

Wednesday, 8 February 2017

Salesforce Essentials - 13 ( Anonymous Block)

An anonymous block is Apex code that does not get
stored in the metadata, but that can be compiled and
executed using one of the following:

• Developer Console

• Force.com IDE

• The executeAnonymous Web services API call:

ExecuteAnonymousResult executeAnonymous(String

You can utilize incognito blocks to expeditiously evaluate
Apex on the fly, such as in the Developer Console or
the Force.com IDE, or to indite code that changes
dynamically at runtime

Note the following about the content of an incognito block (for executeAnonymous(), the code String):

* Can include utilizer-defined methods and exceptions.
* Utilizer-defined methods cannot include the keyword static.
* You do not have to manually commit any database changes.
* If your Apex trigger consummates prosperously, any database changes are automatically committed. If your Apex trigger does not consummate prosperously, any vicissitudes made to the database are rolled back.
* Unlike classes and triggers, incognito blocks execute as the current utilizer and can fail to compile if the code breaches the utilizer's object- and field-level sanctions.
* Do not have a scope other than local. For example, though it is licit to utilize the ecumenical access modifier, it has no denotement. The scope of the method is inhibited to the innominate block.

* When you define a class or interface (a custom type) in an incognito block, the class or interface is considered virtual by default when the innominate block executes. This is true even if your custom type wasn’t defined with the virtual modifier. Preserve your class or interface in Salesforce to eschew this from transpiring. Note that classes and interfaces defined in an incognito block aren’t preserved in your organization.


Sunday, 5 February 2017

Salesforce Essentials - 12 ( Schedulable Apex)

To schedule an Apex class to run at regular intervals, first write an Apex class that implements the Salesforce-provided interface Schedulable.
The scheduler runs as system—all classes are executed, whether or not the user has permission to execute the class.
To monitor or stop the execution of a scheduled Apex job using the Salesforce user interface, from Setup, enter Scheduled Jobs in the Quick Find box, then select Scheduled Jobs.

To invoke Apex classes to run at specific times, first implement
the Schedulable interface for the class, then specify the schedule
using either the Schedule Apex page in the Salesforce user
interface, or the System.schedule method.

The following example implements the Schedulable interface for
a class called mergeNumbers:

global class scheduledMerge implements Schedulable {

global void execute(SchedulableContext SC)


mergeNumbers M = new mergeNumbers();




Wednesday, 1 February 2017

Salesforce Essentials - 11 (Apex Triggers - Context Variable )


Triggers can be created through the UI under or through a Force.com
IDE project.

– In the Force.com IDE, right-click the src folder and select New |
Apex Trigger.

– In the UI, it depends if the triggering object is a standard or custom

For standard objects, navigate to Your Name | Setup | Customize
| Object | Triggers.

For custom objects, navigate to Your Name | Setup | Create |
Objects | Object | Triggers.

You can also view all triggers in the org via Your Name | Setup | Develop |
Apex Triggers.

In order to be executed, triggers must have the Is Active checkbox selected.

Triggers Context Variables

All triggers have implicit variables contained in the System.Trigger class that allow developers to access runtime context.

– isInsert, isBefore, etc.: Returns true if DML or timing is accurate for the

– size: Returns the total number of records, both old and new.

– new: Returns a list of the new versions of the sObject records.

Only for insert and update triggers. Modifiable only when used
with before triggers.

–  newMap: Returns a list or a map of Ids for the new versions of the sObject records.

Only for update or after insert triggers.

– old/oldMap: Similar, but with the old versions of the records.

Only for update and delete triggers.