Skip to main content

Posts

Showing posts with the label trigger

Latest Post

How to Set Up Two-Factor Time-Based One-Time Password (TOTP) Authentication on iPhone Without Third-Party Apps

Unlocking an additional layer of safety to your iPhone is less difficult than you might suppose. With Two-Factor Time-Based One-Time Password (TOTP) authentication, you may bolster your device's protection and other website safety without relying on 1/3-party apps. Here's how you could set it up:

How to Check for Duplicates in Salesforce using "From Date" and "To Date" with Apex Trigger

Introduction : In Salesforce, ensuring data integrity is crucial for maintaining accurate records. One common scenario is checking for duplicates based on specific criteria. In this blog post, we'll explore how to use an Apex Trigger to identify and prevent duplicates based on the "from date" and "to date" fields. Prerequisites: Before proceeding, make sure you have a basic understanding of Salesforce development and Apex Triggers. Scenario: Let's consider a custom object called "Event" that has two date fields: "From_Date__c" and "To_Date__c". We want to prevent users from creating duplicate events where the "from date" and "to date" overlap with existing records. Apex Trigger Code: To achieve this, we'll write an Apex Trigger on the "Event" object that runs before the records are inserted or updated. Here's the code: trigger PreventDuplicateEvents on Event (before insert, befor...

Trigger to check duplicates in salesforce using "from date" and "to date"

  Here is the Sample code to prevent update and insert records between from date and end date in salesforce. This trigger have two events:- before insert  and  before update trigger Duplicatecheck on <Obejct> (before insert,before update) {     set<object > ListOfrecords= new set<object >([SELECT id,Valid_Form__c,Valid_To__c FROM <object>]);     for(<object>  obj1 : ListOfrecords) {         for(<object> obj2: Trigger.new) {             if(obj2.VS_State__c== obj1.VS_State__c && obj2.vs_Tax_Type__c == obj1 .vs_Tax_Type__c){                 if((obj2.Valid_To__c >= obj1.Valid_Form__c&& obj2.Valid_To__c <= obj1 .Valid_To__c ) ||                    (obj2.Valid_Form__c>= obj1.Valid_Form__c&& obj2.Valid_To__c <= obj1 .Valid_To__c ) ||   ...

Streamline Your Apex Triggers with a Trigger Framework in Salesforce

 Introduction: Developing Apex triggers in Salesforce requires careful consideration of best practices to ensure efficient and maintainable code. One approach to achieve this is by implementing a trigger framework. A trigger framework provides a structured and scalable way to handle triggers, reducing code duplication and improving overall code quality. In this blog post, we will explore the benefits of using a trigger framework in Salesforce and discuss how to implement it effectively. Let's dive in and learn how to streamline your Apex triggers with a trigger framework. 1. Understanding the Need for a Trigger Framework: - Highlight the challenges of managing complex and interdependent triggers without a framework. - Discuss the importance of code maintainability, reusability, and reducing technical debt in trigger development. 2. Key Components of a Trigger Framework: - Explain the core components of a trigger framework, such as trigger handler classes, trigger context objects, a...

How to Write Apex Triggers in Salesforce with Code Examples cheat Sheet

Here's a cheat sheet for Apex triggers with code examples: 1. Trigger Structure: trigger TriggerName on ObjectName (trigger_events) {     // Trigger logic and code here } 2. Trigger Events: before insert: Fires before records are inserted into the database. before update: Fires before records are updated in the database. before delete: Fires before records are deleted from the database. after insert: Fires after records are inserted into the database. after update: Fires after records are updated in the database. after delete: Fires after records are deleted from the database.

Prevent to insert or update duplicates in salesforce

Sometimes we need to check duplicate while inserting or updating reocrds in salesforce. We can achieve this by using trigger. here is sample code for how to prevent insert or update record which is already exist between two dates.                                                                                                                                                                                                         Read More...