- Name three Governor Limits.
- When do you use a before vs. after trigger?
Before Trigger:
- In case of validation check in the same object.
- Update the same object.
After Trigger:
- Insert/Update related object,not the same object.
- Notification Email.
- What’s the maximum batch size in a single trigger execution?
200
- What are the differences between 15 and 18 digit record IDs?
Salesforce record Id uniquely identifies each record in salesforcce. Salesforce record Id can either be 15 digit or 18 digit. 15 digit salesforce record id is case sensitive and 18 digit salesforce record id is case insensitive. Every record in salesforce is identified by unique record Id in every salesforce organization.
- 15 digit case-sensitive version is referenced in the UI and also visible in browser
- 18 digit case-insensitive version which is referenced through the API
The last 3 digits of the 18 digit Id is a checksum of the capitalization of the first 15 characters, this Id length was created as a workaround to legacy system which were not compatible with case-sensitive Ids. The API will accept the 15 digit Id as input but will always return the 18 digit Id.
In this post I will explain the process to convert 15 digit salesforce Id to 18 digit salesforce Id.
Visualforce Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<
apex:page
controller
=
"idConvertor"
>
<
apex:form
>
<
apex:pageBlock
>
<
apex:pageMessages
id
=
"showmsg"
></
apex:pageMessages
>
<
apex:pageBlockButtons
>
<
apex:commandButton
value
=
"Convert"
action
=
"{!convert}"
/>
</
apex:pageBlockButtons
>
<
apex:pageBlockSection
>
<
apex:inputText
value
=
"{!inputId}"
label
=
"Input Id:"
/>
<
apex:outPutText
value
=
"{!outputId}"
label
=
"Output Id:"
/>
</
apex:pageBlockSection
>
</
apex:pageBlock
>
</
apex:form
>
</
apex:page
>
Apex Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public
with sharing
class
idConvertor {
public
String inputId{get;set;}
public
String outputId{get;set;}
public
PageReference convert(){
outputId = convertId(inputId);
return
null
;
}
String convertId(String inputId){
string suffix =
''
;
integer flags;
try
{
for
(integer i =
0
; i <
3
; i++) {
flags =
0
;
for
(integer j =
0
; j <
5
; j++) {
string c = inputId.substring(i *
5
+ j,i *
5
+ j +
1
);
if
(c.toUpperCase().equals(c) && c >=
'A'
&& c <=
'Z'
) {
flags = flags + (
1
<< j);
}
}
if
(flags <=
25
) {
suffix +=
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
.substring(flags,flags+
1
);
}
else
{
suffix +=
'012345'
.substring(flags -
26
, flags-
25
);
}
}
}
catch
(Exception exc){
ApexPages.addmessage(
new
ApexPages.message(ApexPages.severity.ERROR,
'Please enter Valid 15 digit Id'
));
}
String outputId = inputId+suffix;
return
outputId;
}
}
- What is custom setting.Provide an example of when a Custom Setting would be used during development?
Custom settings are very useful when it comes to storing static or reusable information in Salesforce, plus it also can work as a switch to turn your application rules ON and OFF. For both Admins and Developers, Custom Settings act as a golden child in the Salesforce family. Under the hood Custom Settings are much like Custom Objects and are accessible via their own API, but you can’t have triggers on a Custom Setting and the available field types are more limited. They do count towards your Custom Objects governor limit however.
There are two types of settings – List and Hierarchical. In this post we are going to look at each of them and suggest typical ways in which you can use them.
List Custom Settings
List settings are structured similar to records held in a custom object. They allow you to store org-wide static data that is frequently used, and therefore cached for performance. Data in List settings do not vary by user and profile, there is no ownership, field level security or record security, and it is available organisation wide (i.e. public for all). It’s best used for data lists, especially reference code lists, and great for when you want to convert code values from one system to another or any other mapping or list.
You may ask why we need to use List settings when same thing can be done through a Custom Object? Well the answer is simple. Custom Settings are stored in the application cache and do not count against SOQL limits when fetched. Also they are much quicker to implement, easier to maintain and they won’t use up one of your precious Custom Tab limits to maintain. They can also only be updated by a System Administrator (or Configure Application profile permission user). Custom Settings have their own methods to access them – we will have a look below at an example on how we can use getInstance() and getAll() methods.
Lets consider a scenario where your customer Service team wants to differentiate between incoming email address with domain names. They want their partner emails to be redirected to different queue with some additional business logic to be applied. For creating a new Custom Settings go to Setup – Develop – Custom Settings, Click New and enter details.
Once you have created the custom setting, you need to define the fields to add to it. The following are the data types that are available for custom settings fields.
In the image below we are storing a few email domain names in custom settings and later fetching them via Apex using getInstance() and getAll() methods. The purpose of this list is to allow us to select the correct Partner details based on company’s domain name. By using the custom setting we can quickly find the mappings we need without querying for a matching field on the Account record (where we may have millions of records).
The following code snippet is an example of one of the ways to use List custom settings in Apex:
In addition to holding lists of static data, List Custom Settings are also useful for:
- Holding environment credentials: Webservice endpoints for production, uat, prepod and dev are likely to be different – don’t hardcode them!
- To hold environment ids: If you have rules, buttons or links that need to utilize specific Salesforce Id values these are going to be different across your environments or may change over time. Rather than hard coding a user or profile id in a Rule, Formula or Apex code you can use a custom setting to hold values such as an ‘Escalation User Id’.
- To hold environment values: You may have rules about opportunities greater than $100k however this limit make change in the future dur to changes in market conditions. Hold the value in a List custom setting if it applies globally to all users (without question) and you need to reference it in Apex. Hold it in a Hierarchical setting if there’s a chance you need to switch it off by user or profile or have different values, or if you need to access the value in a Workflow, Formula Field or Validation Rule.
Custom Settings as a Switch
Hierarchical Custom Settings are defined once and can hold a unique set of values for the Organisation, each Profile or each individual User. Salesforce automatically grabs the lowest level of setting for the running user when a getInstance() call is made, or when accessed in a configuration such as a Validation Rule, Workflow or Formula Field. Note that only Hierarchical settings can be accessed declaratively whereas List settings are for Apex/Visualforce only.
Using hierarchical settings can provide the functionality of a switch, which you can use as ON or OFF to disable Integrations, Triggers, Workflow Rules, Assignment Rules and Validation Rules for all users, specific profiles or individual users. This is possible when you use hierarchical custom settings with a checkbox field to control your system functions, but you could also use it to control internal debugging log levels for example.
Using hierarchical settings lets you control down to an individual user for whom it is de-activated, so you can force a data validation rule for some users and disable it for others. For triggers it is even more useful because triggers cannot be de-activated in a production org without carrying out time consuming deployments (once to switch off and then to switch on again), with no guarantee of how long each deployment will take (depending on the instance queues, org usage and number of unit tests in the org to be run each time).
This becomes especially useful when performing data fixes or data migration, or if needing to disable a failing trigger or Apex functionality in a live org (saving hours in performing the redeployments). Because of the hierarchical nature you can isolate to an individual user, so you could disable all triggers firing during a Data Load for an Admin user to drastically reduce the time to upload data or for an Admin when fixing data errors to switch off emails being sent to customers from Workflows. No more need to deactivate rules one by one and re-activate them when you’ve finished, and work no longer has to always be performed ‘out-of-hours’.
Below is an example of how a hierarchal custom setting can be implemented. You can add new records as Profiles or individual Users to bypass any Apex Triggers or Validation Rules.
In this example we create a validation rule to prevent a User from closing a case with any Open activities, and use $Setup.Your_Custom_Setting with an AND condition in our validation rule to switch this off centrally:
AND
(
ISPICKVAL( Status , “Closed”) ,
ISCHANGED( Status ) ,
Open_Activities__c <> 0 ,
$Setup.MP_Global_Settings__c.Fire_Validation_Rules__c
)
As you can see if you built all your validation rules, workflow rules and triggers using this technique it is an extremely powerful way of controlling behaviour across the entire application.
You can set the default Organisation Level value (as seen in image below) to fire all Validation, Workflow, Assignment and Triggers rules for all Users. To bypass any profile or user, add a record in Custom settings. In the example below only triggers will fire for System Administrator Profile and no rules will fire for User Ali Zafar, even though he is a System Administrator because the lowest level of custom setting is applied automatically. Also, note that the user personal settings will override all his other settings.
This technique can be expanded upon for a number of other reasons:
- To switch application functionality on/off: Useful for orgs with multiple divisions who want different behaviours. Try to create re-usable settings by function such as ‘Reassign Old Leads to Queues’ rather than generic divisional settings such as ‘Run Marketing Rules’.
- To control change management: Similar to the above, when implementing a suite of changes where you need to be able to ‘rollback’ the function in the event of an issue, or you wish to soft launch a feature, consider implementing a Hierarchical custom setting to let you test the change in production for a single user or profile before releasing to all users.
- To provide dynamic page overrides: Different Visualforce or standard pages can be called in a Button or Apex Visualforce Controller based on the Custom Settings for a particular profile or user. This can even be used to include different logos or branding.
- To extend the Profile with custom attributes: Profiles cannot currently be extended with custom fields, so use a Hierarchical Custom Setting to define the fields you need to add at a Profile level. For example, a Sales Commission % field which is used in a formula field. This can then be further overridden by individual user and potentially saving on Profile proliferation!
- To switch Visualforce components on/off: Users can hide sections on Page Layouts but they can’t hide sections on a Visualforce page (ok they can collapse the section but it isn’t remembered between sessions). You can create “Show Financials”, “Show KPIs”, “Show Case History” checkbox options to switch this data off on Visualforce pages using the Rendered attribute to control visibility. Useful when you don’t want to hide the data completely through Field Level Security, just simplify the pages, and very useful for showing different features to Community users by Profile or User and even saving results by user to collapse or hide sections.
- When should you build solutions declaratively instead of with code?
Here are some use cases and examples for functionality that can easily be build declaratively, without writing a single line of code:
- Instead of writing Triggers, we can automate Field Updates using Workflow – automatically populating a field with a default value or updating a field based on the value of another field is a pretty common requirement. Workflow can address the basic use cases just as well as writing an Apex Trigger.
- Use Formula Fields and Roll-Up Summary Fields for field calculations instead of writing a Visualforce page and calculate the field values in a controller extension – a good example is a simple Order Management app. On the Order Lines, the order line total is calculated by multiplying the item price with the ordered quantity. A formula field can easily achieve this. And if we want to have the sum of all order line totals on the order header, we can use a Roll-up Summary field, as long as there is a Master-Detail relationship between the order and the order lines object.
- Enforce Business Rules with Validation Rules whenever possible instead of Triggers and code
Don’t want to allow users to save the order if a piece of information is missing? Validation Rules is a fast and easy-to-use alternative to writing custom Visualforce pages and controllers or Apex Triggers.
- Use Approval Processes and Flows to implement logic and processes
A lot of complex custom business logic and business processes can be defined using these two powerful tools. And probably the nicest benefit is that Approval Processes and Flows visualize the process, which makes it much easier to understand what’s going on than looking at lines and lines of Apex code.
- Using Standard vs. Custom Objects
We see this more often than one would think. Before creating a new custom object, check if there’s a standard object available that can address the functional requirements and/or can be customized to close the gap. Not only will this potentially save a lot of time, but also help control the number of custom objects in Salesforce, which is limited as we all know. A great example here is the Orders object that was released with Salesforce Spring ‘14. Before the Orders object was a Standard object, developers spent a lot of time and resources building functionality that is now available out-of-the-box. Keep in mind that there are three major Salesforce releases per year, so Salesforce is constantly adding new features and functionality. It’s always a good idea to check both the Salesforce1 Platform Release Notes and theForce.com Release Pages here on Salesforce Developers for new standard objects and/or new features that may have required custom building in the past.
- Give an example of a standard object that’s also junction object.
- Describe a use case when you’d control permissions through each of the following:
– Profiles
– Roles
– Permission Sets
– Sharing Rules
- When should an org consider using Record Types?
- What are some use cases for using the Schema class?
- A trigger is running multiple times during a single save event in an org. How can this be prevented?
- Why is it necessary for most sales teams to use both Leads and Contacts?
- What is the System.assert method and when is it commonly used?
- What are the differences between SOQL and SOSL?
- Order the following events after a record is saved:
– Validation rules are run
– Workflows are executed
– “Before” triggers are executed
– “After” triggers are executed
- What is Trigger.old and when do you normally use it?
- When should you use a lookup instead of a master-detail relationship?
- What are the advantages of using Batch Apex instead of a trigger?
- What are the pros and cons when using a Workflow Rule Field Update vs. a Formula Field?
- What are the differences between a Map and a List?
- What are the advantages of using Batch Apex instead of a trigger?
- Describe a use case for Static Resources.
- Provide an example of when a Matrix report would be used. How about a Joined report?
- A group of users must be prevented from updating a custom field. What’s the most secure method of preventing this?
- When would you use the @future annotation?
- List three different tools that can be used when deploying code.
- When should an Extension be used instead of a Custom Controller?
- What are the advantages of using External Id fields?
- What are the uses of the <apex:actionFunction> tag?
- What are the differences between static and non-static variables in Apex?
- What are some best practices when writing test classes?
- What does the View State represent in a Visualforce page?
- What are three new features in the most recent Salesforce release?
- Describe the benefits of the “One Trigger per Object” design pattern.
- Write a SOQL query that counts the number of active Contacts for each Account in a set.
- Declaratively create logic in your org that prevents two Opportunities from being created on a single Account in a single day.
- Declaratively create logic in your org that prevents closed Opportunities from being updated by a non System Administrator profile.
- Can we create Trigger on Attachment ?
- How many Types of cloud in Salesforce.difference between Sales,Service and Custom Cloud?
- What is Web to Lead ?
- What is Case escalations rules ?
- What is Email Service and Email Template ?
- What is workflow ?
- What is profile ,Permission set and Role in Salesfroce ?
- What Is queue ?
- Difference Between Trigger.new & Trigger.old ?
- Difference between trigger.newMap and trigger.oldMap ?
- What is Sharing & without Sharing in apex Salesforce ?
- What is Collection in Salesforce ?
- How we populate value in Object using Trigger ?
- What is best Practice of Visualforce page and Apex Class ?
- Can we override profile permissions through Role ?
- Execution of life cycle of Apex Code ?
- Which Interface used in schedule class & Batch class ?
- Can we call a Normal Class in Schedule Class ?
- How we run Batch In Queue ?
- What is the Campaign & how its work ?
- How we convert the Lead & which fields are Optional ?
- Difference between Action Function & Remote Function ?
- How to implement many to many relationship in salesforce ?
- What is difference between many to many relationship & Lookup relationship ?
- What is Audit Trail ?
- What is field Set ?
- Difference between Custom setting and custom object ?
- How we make created by field to Writeable ?
- What is WhoID and WhatID in salesforce ?
- What is chatter and how we implement in salesforce ?
- What is communities and how many types of communities used in salesforce ?
- Difference between Rest Api and SOAP Api ?
- Governor limits in salesforce ?
- What is OWD in salesforce and what is Default OWD master Detail ?
- How many type of Report used in Salesforce ?
- What is Event and Task in salesforce ?
- How many types we can Deployed code in production ?
- How we enable History of any Object ?
- What is controller and standard controller and what is difference in both ?
- How we perform DML operation on page load ?
- What is Standard set Controller ?
- What is Data Migration ?
- How many line write in Apex class -10000
- What is Access specifier and what is Scope ?
- What is View State ?
- How we remove Heap Size Issue ?
- Can we used more than one Controller in visualfroce page ?
- What is auto Response Role ?
- What is Role hierarchy and where we can see this ?
- What is final and static keyword and where we used ?
- What is Apex variable and where we use of this ?
- How we show two object data in row and column ?
- What Is external ID ?
- What is import wizard.Limitations of this and difference between data Loader & import wizard.
- What is Test class and how variable context used in apex Trigger ?
- What is group and how many type of group in salesforce ?
- What is connected App in salesforce ?
- What is meta data ?
- Can we deploy a class less than 75% of code coverage in production ?
- What is console and how we used.Can we override standard save functionality ?
- Can we call one future method to another future method ?
- Difference between SOQL and SOSL
- How to convert 15 digit to 18 digit ID in formula field in Salesforce ?
CASESAFEID() is used to convert 15 digit ID to 18 digit ID in formula field in salesforce.
Before Trigger:
- In case of validation check in the same object.
- Update the same object.
- Insert/Update related object,not the same object.
- Notification Email.
200
Salesforce record Id uniquely identifies each record in salesforcce. Salesforce record Id can either be 15 digit or 18 digit. 15 digit salesforce record id is case sensitive and 18 digit salesforce record id is case insensitive. Every record in salesforce is identified by unique record Id in every salesforce organization.
- 15 digit case-sensitive version is referenced in the UI and also visible in browser
- 18 digit case-insensitive version which is referenced through the API
The last 3 digits of the 18 digit Id is a checksum of the capitalization of the first 15 characters, this Id length was created as a workaround to legacy system which were not compatible with case-sensitive Ids. The API will accept the 15 digit Id as input but will always return the 18 digit Id.
In this post I will explain the process to convert 15 digit salesforce Id to 18 digit salesforce Id.
Visualforce Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| < apex:page controller = "idConvertor" > < apex:form > < apex:pageBlock > < apex:pageMessages id = "showmsg" ></ apex:pageMessages > < apex:pageBlockButtons > < apex:commandButton value = "Convert" action = "{!convert}" /> </ apex:pageBlockButtons > < apex:pageBlockSection > < apex:inputText value = "{!inputId}" label = "Input Id:" /> < apex:outPutText value = "{!outputId}" label = "Output Id:" /> </ apex:pageBlockSection > </ apex:pageBlock > </ apex:form > </ apex:page > |
Apex Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| public with sharing class idConvertor { public String inputId{get;set;} public String outputId{get;set;} public PageReference convert(){ outputId = convertId(inputId); return null ; } String convertId(String inputId){ string suffix = '' ; integer flags; try { for (integer i = 0 ; i < 3 ; i++) { flags = 0 ; for (integer j = 0 ; j < 5 ; j++) { string c = inputId.substring(i * 5 + j,i * 5 + j + 1 ); if (c.toUpperCase().equals(c) && c >= 'A' && c <= 'Z' ) { flags = flags + ( 1 << j); } } if (flags <= 25 ) { suffix += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .substring(flags,flags+ 1 ); } else { suffix += '012345' .substring(flags - 26 , flags- 25 ); } } } catch (Exception exc){ ApexPages.addmessage( new ApexPages.message(ApexPages.severity.ERROR, 'Please enter Valid 15 digit Id' )); } String outputId = inputId+suffix; return outputId; } } |
Custom settings are very useful when it comes to storing static or reusable information in Salesforce, plus it also can work as a switch to turn your application rules ON and OFF. For both Admins and Developers, Custom Settings act as a golden child in the Salesforce family. Under the hood Custom Settings are much like Custom Objects and are accessible via their own API, but you can’t have triggers on a Custom Setting and the available field types are more limited. They do count towards your Custom Objects governor limit however.
There are two types of settings – List and Hierarchical. In this post we are going to look at each of them and suggest typical ways in which you can use them.
List Custom Settings
List settings are structured similar to records held in a custom object. They allow you to store org-wide static data that is frequently used, and therefore cached for performance. Data in List settings do not vary by user and profile, there is no ownership, field level security or record security, and it is available organisation wide (i.e. public for all). It’s best used for data lists, especially reference code lists, and great for when you want to convert code values from one system to another or any other mapping or list.
You may ask why we need to use List settings when same thing can be done through a Custom Object? Well the answer is simple. Custom Settings are stored in the application cache and do not count against SOQL limits when fetched. Also they are much quicker to implement, easier to maintain and they won’t use up one of your precious Custom Tab limits to maintain. They can also only be updated by a System Administrator (or Configure Application profile permission user). Custom Settings have their own methods to access them – we will have a look below at an example on how we can use getInstance() and getAll() methods.
Lets consider a scenario where your customer Service team wants to differentiate between incoming email address with domain names. They want their partner emails to be redirected to different queue with some additional business logic to be applied. For creating a new Custom Settings go to Setup – Develop – Custom Settings, Click New and enter details.
Once you have created the custom setting, you need to define the fields to add to it. The following are the data types that are available for custom settings fields.
In the image below we are storing a few email domain names in custom settings and later fetching them via Apex using getInstance() and getAll() methods. The purpose of this list is to allow us to select the correct Partner details based on company’s domain name. By using the custom setting we can quickly find the mappings we need without querying for a matching field on the Account record (where we may have millions of records).
The following code snippet is an example of one of the ways to use List custom settings in Apex:
In addition to holding lists of static data, List Custom Settings are also useful for:
- Holding environment credentials: Webservice endpoints for production, uat, prepod and dev are likely to be different – don’t hardcode them!
- To hold environment ids: If you have rules, buttons or links that need to utilize specific Salesforce Id values these are going to be different across your environments or may change over time. Rather than hard coding a user or profile id in a Rule, Formula or Apex code you can use a custom setting to hold values such as an ‘Escalation User Id’.
- To hold environment values: You may have rules about opportunities greater than $100k however this limit make change in the future dur to changes in market conditions. Hold the value in a List custom setting if it applies globally to all users (without question) and you need to reference it in Apex. Hold it in a Hierarchical setting if there’s a chance you need to switch it off by user or profile or have different values, or if you need to access the value in a Workflow, Formula Field or Validation Rule.
Custom Settings as a Switch
Hierarchical Custom Settings are defined once and can hold a unique set of values for the Organisation, each Profile or each individual User. Salesforce automatically grabs the lowest level of setting for the running user when a getInstance() call is made, or when accessed in a configuration such as a Validation Rule, Workflow or Formula Field. Note that only Hierarchical settings can be accessed declaratively whereas List settings are for Apex/Visualforce only.
Using hierarchical settings can provide the functionality of a switch, which you can use as ON or OFF to disable Integrations, Triggers, Workflow Rules, Assignment Rules and Validation Rules for all users, specific profiles or individual users. This is possible when you use hierarchical custom settings with a checkbox field to control your system functions, but you could also use it to control internal debugging log levels for example.
Using hierarchical settings lets you control down to an individual user for whom it is de-activated, so you can force a data validation rule for some users and disable it for others. For triggers it is even more useful because triggers cannot be de-activated in a production org without carrying out time consuming deployments (once to switch off and then to switch on again), with no guarantee of how long each deployment will take (depending on the instance queues, org usage and number of unit tests in the org to be run each time).
This becomes especially useful when performing data fixes or data migration, or if needing to disable a failing trigger or Apex functionality in a live org (saving hours in performing the redeployments). Because of the hierarchical nature you can isolate to an individual user, so you could disable all triggers firing during a Data Load for an Admin user to drastically reduce the time to upload data or for an Admin when fixing data errors to switch off emails being sent to customers from Workflows. No more need to deactivate rules one by one and re-activate them when you’ve finished, and work no longer has to always be performed ‘out-of-hours’.
Below is an example of how a hierarchal custom setting can be implemented. You can add new records as Profiles or individual Users to bypass any Apex Triggers or Validation Rules.
In this example we create a validation rule to prevent a User from closing a case with any Open activities, and use $Setup.Your_Custom_Setting with an AND condition in our validation rule to switch this off centrally:
AND
(
ISPICKVAL( Status , “Closed”) ,
ISCHANGED( Status ) ,
Open_Activities__c <> 0 ,
$Setup.MP_Global_Settings__c.Fire_Validation_Rules__c
)
(
ISPICKVAL( Status , “Closed”) ,
ISCHANGED( Status ) ,
Open_Activities__c <> 0 ,
$Setup.MP_Global_Settings__c.Fire_Validation_Rules__c
)
As you can see if you built all your validation rules, workflow rules and triggers using this technique it is an extremely powerful way of controlling behaviour across the entire application.
You can set the default Organisation Level value (as seen in image below) to fire all Validation, Workflow, Assignment and Triggers rules for all Users. To bypass any profile or user, add a record in Custom settings. In the example below only triggers will fire for System Administrator Profile and no rules will fire for User Ali Zafar, even though he is a System Administrator because the lowest level of custom setting is applied automatically. Also, note that the user personal settings will override all his other settings.
This technique can be expanded upon for a number of other reasons:
- To switch application functionality on/off: Useful for orgs with multiple divisions who want different behaviours. Try to create re-usable settings by function such as ‘Reassign Old Leads to Queues’ rather than generic divisional settings such as ‘Run Marketing Rules’.
- To control change management: Similar to the above, when implementing a suite of changes where you need to be able to ‘rollback’ the function in the event of an issue, or you wish to soft launch a feature, consider implementing a Hierarchical custom setting to let you test the change in production for a single user or profile before releasing to all users.
- To provide dynamic page overrides: Different Visualforce or standard pages can be called in a Button or Apex Visualforce Controller based on the Custom Settings for a particular profile or user. This can even be used to include different logos or branding.
- To extend the Profile with custom attributes: Profiles cannot currently be extended with custom fields, so use a Hierarchical Custom Setting to define the fields you need to add at a Profile level. For example, a Sales Commission % field which is used in a formula field. This can then be further overridden by individual user and potentially saving on Profile proliferation!
- To switch Visualforce components on/off: Users can hide sections on Page Layouts but they can’t hide sections on a Visualforce page (ok they can collapse the section but it isn’t remembered between sessions). You can create “Show Financials”, “Show KPIs”, “Show Case History” checkbox options to switch this data off on Visualforce pages using the Rendered attribute to control visibility. Useful when you don’t want to hide the data completely through Field Level Security, just simplify the pages, and very useful for showing different features to Community users by Profile or User and even saving results by user to collapse or hide sections.
Here are some use cases and examples for functionality that can easily be build declaratively, without writing a single line of code:
- Instead of writing Triggers, we can automate Field Updates using Workflow – automatically populating a field with a default value or updating a field based on the value of another field is a pretty common requirement. Workflow can address the basic use cases just as well as writing an Apex Trigger.
- Use Formula Fields and Roll-Up Summary Fields for field calculations instead of writing a Visualforce page and calculate the field values in a controller extension – a good example is a simple Order Management app. On the Order Lines, the order line total is calculated by multiplying the item price with the ordered quantity. A formula field can easily achieve this. And if we want to have the sum of all order line totals on the order header, we can use a Roll-up Summary field, as long as there is a Master-Detail relationship between the order and the order lines object.
- Enforce Business Rules with Validation Rules whenever possible instead of Triggers and code
Don’t want to allow users to save the order if a piece of information is missing? Validation Rules is a fast and easy-to-use alternative to writing custom Visualforce pages and controllers or Apex Triggers. - Use Approval Processes and Flows to implement logic and processes
A lot of complex custom business logic and business processes can be defined using these two powerful tools. And probably the nicest benefit is that Approval Processes and Flows visualize the process, which makes it much easier to understand what’s going on than looking at lines and lines of Apex code. - Using Standard vs. Custom Objects
We see this more often than one would think. Before creating a new custom object, check if there’s a standard object available that can address the functional requirements and/or can be customized to close the gap. Not only will this potentially save a lot of time, but also help control the number of custom objects in Salesforce, which is limited as we all know. A great example here is the Orders object that was released with Salesforce Spring ‘14. Before the Orders object was a Standard object, developers spent a lot of time and resources building functionality that is now available out-of-the-box. Keep in mind that there are three major Salesforce releases per year, so Salesforce is constantly adding new features and functionality. It’s always a good idea to check both the Salesforce1 Platform Release Notes and theForce.com Release Pages here on Salesforce Developers for new standard objects and/or new features that may have required custom building in the past.
– Profiles
– Roles
– Permission Sets
– Sharing Rules
– Validation rules are run
– Workflows are executed
– “Before” triggers are executed
– “After” triggers are executed
CASESAFEID() is used to convert 15 digit ID to 18 digit ID in formula field in salesforce.