Saturday 4 October 2014

DML Options


We can use DML options while inserting or updating by setting desired options in Database.DMLOptions object. We can set options either by calling Databse.DMLOptions "SetOptions "method or by passing it as parameter to Database.insert or Database.Update methods.

Database.DMLOptions have following property

1. allowFieldTruncation : From Apex version 15 and higher if any field value is too large error message generated and operation gets failed. Using allowFieldTruncation we can truncate the string.

Syntax: Database.DMLOptions dml = new Database.DMLOptions();
          dml.allowFieldTruncation = true;


2. assignmentRuleHeader : Allow us to specifies if assignment rule to be used while creating Lead or Case

with assignmentRuleHeader we can set following options
    a. useDefaultRule : Indicates whether default (active) assignment rule to be used for Lead or Case.
    b. assignmentRuleId : Id of assignment rule for Lead or Case. 

 NOTE: For the Case sObject, the assignmentRuleID DML option can be set only from the API and is ignored when set from Apex. For example, you can set the assignmentRuleID for an active or inactive rule from the executeanonymous() API call, but not from the Developer Console. This doesn’t apply to leads—the assignmentRuleID DML option can be set for leads from both Apex and the API.


Syntax: Database.DMLOptions dmo = new Database.DMLOptions();
          dmo.assignmentRuleHeader.useDefaultRule = true;

          Lead newLead = new Lead(Company = 'Lead Corp', lastName ='Smith ');
          newLead.setOptions(dmo);
          insert newLead;


3. emailHeaderThe Salesforce user interface allows you to specify whether or not to send an email when the following events occur:
  • Creation of a new case or task
  • Creation of a case comment
  • Conversion of a case email to a contact
  • New user email notification
  • Lead queue email notification
  • Password reset
Using emailHeader property you can set

a. triggerAutoResponseEmail : Indicate whether to trigger auto response rules for Leads and Cases.

b. triggerOtherEmail : Indicate whether to trigger email outside the organisation.

c. triggerUserEmail : Indicate whether to trigger email that is sent to users in organisation


Syntax: Account newAccount = new Account(Name = 'Test Account');
insert newAccount ;
             
Contact newContact = new Contact(email ='puneetmishrasfdc@gmail.com', firstName='test', lastName='Lead', accountId = newAccount.Id);

Database.DMLOptions dmo = new Database.DMLOptions();
dmo.emailHeader.triggerAutoResponseEmail = true;

Case newCase = new Case(subject = ' Salesforce Limit ', contactId = newContact.Id);
insert newcase;

4. localeOptions : The localeOptions property specifies the language of any labels that are returned by Apex.

5. optAllorNone : The optAllOrNone property specifies whether the operation allows for partial success. If optAllOrNone is set to true, all changes are rolled back if any record causes errors. The default for this property is false and successfully processed records are committed while records with errors aren't. 

2 comments:

  1. I was searching for the better blog on Sales force CRM techniques to understand what CRM is and what is the use? Your blog is the right one I found to get depth knowledge. Thanks for sharing your wonderful ideas.
    Regards
    Salesforce.com training in chennai
    Salesforce crm Training in Chennai

    ReplyDelete

  2. Wonderful blog on Cloud domain, Thank you sharing the informative article with us. Hope your article will reach top of the SERP result to the familiar cloud related queries
    Regards:
    Cloud Computing Courses | Cloud computing course in Chennai

    ReplyDelete