Friday 25 May 2018


Triggers and Order of Execution


On the server, Salesforce:
1.      Loads the original record from the database or initializes the record for an upsert statement.
2.      Loads the new record field values from the request and overwrites the old values.
If the request came from a standard UI edit page,
 Salesforce runs system validation to check the record for:
o    Compliance with layout-specific rules
o    Required values at the layout level and field-definition level
o    Valid field formats
o    Maximum field length
When the request comes from other sources, such as an Apex application or a SOAP API call, Salesforce validates only the foreign keys. Prior to executing a trigger, Salesforce verifies that any custom foreign keys do not refer to the object itself.
Salesforce runs user-defined validation rules if multiline items were created, such as quote line items and opportunity line items.
3.      Executes all before triggers.
4.      Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any user-defined validation rules. The only system validation that Salesforce doesn't run a second time (when the request comes from a standard UI edit page) is the enforcement of layout-specific rules.
5.      Executes duplicate rules. If the duplicate rule identifies the record as a duplicate and uses the block action, the record is not saved and no further steps, such as after triggers and workflow rules, are taken.
6.      Saves the record to the database, but doesn't commit yet.
7.      Executes all after triggers.
8.      Executes assignment rules.
9.      Executes auto-response rules.
10.  Executes workflow rules.
11.  If there are workflow field updates, updates the record again.
12.  If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again.
13.  Executes processes.
If there are workflow flow triggers, executes the flows.
The pilot program for flow trigger workflow actions is closed. If you've already enabled the pilot in your org, you can continue to create and edit flow trigger workflow actions. If you didn't enable the pilot in your org, use the Flows action in Process Builder instead.
14.  Executes escalation rules.
15.  Executes entitlement rules.
16.  If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.
17.  If the parent record is updated, and a grandparent record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the grandparent record. Grandparent record goes through save procedure.
18.  Executes Criteria Based Sharing evaluation.
19.  Commits all DML operations to the database.
20. Executes post-commit logic, such as sending email

Wednesday 23 May 2018

   DML Statement in 'after trigger' and not in 'before trigger'?


According to document, first Before trigger fire and then after trigger fire.In between of these events all the records saved to database but doesn't committed yet
  • Before insert event
  • Data committed to database
  • After insert event

Means when you use before insert operation records are not committed to database so If we change the trigger context record's value then we don't need perform DML (This is Id is not generated because it is not committed to database)

  • Once it is committed to database means the record Id is generated and your trigger records in read only mode you can't update the values now(because it is committed to database).That's why we need to perform extra DML for updating records.


Note: If in after event if any error occurs then complete DML operation rollback.

Best way if you want to update the same record in trigger then always go with before event. This way you can skip the extra DML.

Saturday 19 May 2018

 On change functionality in JavaScript


<apex:page standardController="Account">
<script>
    function changeCase(elId){
        var x = document.getElementById(elId);
        x.value = x.value.toUpperCase();
    }
</script>
<apex:form >
   Change Entered Account Name to Upper Case (After Entering the name in lower case click on Enter):
<apex:inputField value="{!account.Name}" id="id1" onchange="changeCase('{!$Component.id1}');"/>
</apex:form> 
</apex:page>

Friday 18 May 2018


         Creating or Refreshing a Sandbox from Production in Salesforce

                   We can create sandbox only from ProductionThe number of sandbox's we can create depends on the license which we have.
 

 SandBox Creation Steps:

  step1. Setup-------->Datamanagement---------->sandbox------> New SandBox.

  step2. Enter a name and description for the sandbox.we can only change the
             name when we create or refresh a sandbox.Sandbox name should Reflect
            the purpose of this sandbox, such as “QA.”(its best Practise).


  step3. Choose type of sandbox to create.
              if it is Partial data Sandbox you need to select Sandbox Template.
  step4. Create.

  The process may take several minutes, hours, or even days, depending on the size and type of your organization.The first time you create a sandbox, Salesforce activates the sandbox for you.

  Refresing Sandbox :

Setup-------->Datamanagement---------->sandbox

  You’ll see a list of your sandboxes. Sandboxes that you can refresh have a Refresh link next to the sandbox name.
      Edit | Del | Refresh | Login  Sandboxname    Status(inUse)

                      On clicking refresh button Salesforce starts copying data to the sandbox(If it is Full sand box)  status turns to Copying.After Salesforce finishes copying data to the sandbox,inProgress turns into Activate button.
                                    
    Action                                 Sandboxname          Status

   Edit                                        test                            Copying


   Edit |  Activate |Discard         test                       Replacement ready

              you  need to activate the sandbox before you can use the refreshed data. Salesforce sends you an email when your sandbox is ready to activate. Activating a replacement sandbox that was created using the Refresh link  completely deletes the sandbox it is refreshing.


 All configuration and data in the prior sandbox copy will be lost, including any application or data changes you have made and there is no way to recover them back.Once Your production organization and its data will not be affected.


  After Activation of sandbox :

** You will receive a notification email when your newly created or refreshed sandbox has completed copying.

** login URL for Sandbox is https://test.salesforce.com by appending .sandbox_name to their Salesforce usernames.


  Example  username for a production organization is  test@companyname.com,
                      the sandbox is named “test”,
                      new sandbox  user name is test@companyname.com.test.


**   Salesforce automatically changes sandbox usernames, but not passwords.
      you need to use Production password to login sandbox.


**  Newly created sandboxes have the default email deliverability setting System email only.
     The System email only setting is especially useful for controlling email sent from sandboxes
     so that testing and development work doesn’t send test emails to your users

Sandbox Storage Limits

  •  Partial Data sandboxes have a 5 GB storage limit.
  •   Developer Pro sandboxes have a 1 GB storage limit.
  •   Developer sandboxes have a 200 MB storage limit.
  •  Full sandboxes have the same storage limit as your production organization.
  • Sandboxes don’t send email notifications when storage limits are reached, if you reach the storage limit of your sandbox, you cannot save new data in your sandbox.
  •  To check storage limits, from Setup, click Data Management | Storage Usage in your sandbox.

Note:
To create, refresh, activate, and delete sandbox user should have  “Modify All Data”   permission.

What emails are included in the "System Email Only" in Email Administration 

  1. Notifications sent after user email address change, 
  2. Security token reset
  3. Change set upload 
  4. Sandbox about to expire


   

           What is the difference between External ID and Unique ID?

External ID:

          This is a field that usually references an ID from another (external) system. For    instance, if the customer has an Oracle Financials system that they will be linking with Salesforce, it may be easier for them to be able to refer to the Oracle ID of account records from within Salesforce. So they would create an external ID in Salesforce and they would load the Oracle ID into that field for each account. They can then refer to that ID field, rather than the Salesforce id. 


Unique ID field

This is a setting for the field that will prevent you from using the same value in multiple records for the unique field. So if I create a 5 character text field and make it unique, and I create a record with the value "12345" I will not be able to create another record with that same value in the unique field. If I try to do so, I will get an error saying that the value is already in use.

Often, External Ids are set with the unique property so that the IDs will be unique to each record.



The fields with below data types can only be external Id

1. Number
2. Text
3. Email

During upsert operation,

1. If External Ids are matched, it will update the record.

2. If External Ids are not matched, it will create a new record.

3. If External Ids are matched more than once, it will throw an error.
How to set field as external Id field







Thursday 17 May 2018


MIXED_DML_OPERATION error in Salesforce

You can easily run into this error if you are trying to perform DML on setup and non-setup objects in the same transaction.

Non-Setup objects are standard objects like Account or any custom object.

Setup objects are Group, GroupMember, UserTerritory, Territory, etc.

For example, you cannot insert an account and then insert a user or a group member in a single transaction.

Test methods allow for performing mixed DML operations between the sObjects listed earlier and other sObjects if the code that performs the DML operations is enclosed within 
System.runAs method blocks. This enables you, for example, to create a user with a role and other sObjects in the same test.


 How to turn off Email Notifications in Salesforce?

The Email Notification can be turned off or the level can be changed using the below steps

1.       From Setup, click Email Administration --> Deliverability.
2.       Set the Access Level.

No access: Prevents all outbound email to and from users.
System email only: Allows only automatically generated emails, such as new user and password reset emails.
All email: Allows all types of outbound email. Default for new, non-sandbox organizations.