function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
realtimetasks1.3941822547955107E12realtimetasks1.3941822547955107E12 

trigger on lead object

Making the field "opt in" automatically populate when a new lead or contact is created, while making it possible to uncheck manually if necessary.
Ramu_SFDCRamu_SFDC
This can be accomplished by workflow rules as well. But if you want to go with Triggers you may write the below 'Before Insert' code for Leads and similar one for contacts as well.

trigger leadcheckbox on Lead(before insert) {
    for(Lead Ld: Trigger.new){        
           Ld.Checkbox__c = true;        
    }
}