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
Anshuman ParhiAnshuman Parhi 

Create a checkbox on contact object and Write a trigger to check that checkbox whenever a new contact is created.

Hello guys

I am having one scenario , when i will create a new contact record then one checkbox(custom field)  should get checked automatically which is  present in same contact object.

If I get any help then it will be really helpful.
Best Answer chosen by Anshuman Parhi
Suraj Tripathi 47Suraj Tripathi 47
Hi Anshuman,
Greetings!
 
trigger CheckBoxOnContact on Contact (before insert) {
    for(Contact con : trigger.new) {
        con.CheckBox__c = true;
    }
}

If you find your Solution then mark this as the best answer. 

Thank you!

Regards,
Suraj Tripathi

All Answers

ShivankurShivankur (Salesforce Developers) 
Hi Anshuman,

Try this steps:
  1. Setup | Create | Workflows & Approvals | Workflow Rules | New Rule
  2. Select the Object: Contact
  3. Evaluation Criteria: created
  4. Rule Criteria: criteria are met
  5. Criteria: Checkbox not equal to TRUE
  6. Click Save & Next
  7. From under Immediate Workflow Actions, click Add Workflow Action to select Field Update
  8. Select the Field to Update: Checkbox
  9. Set it to TRUE
  10. Click Save
  11. Hit Done
  12. Activate
Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.
Anshuman ParhiAnshuman Parhi
Hi  @Shivankur
i have done by this steps....but my requirement is i have to do this by trigger.....so can u help me out.
Suraj Tripathi 47Suraj Tripathi 47
Hi Anshuman,
Greetings!
 
trigger CheckBoxOnContact on Contact (before insert) {
    for(Contact con : trigger.new) {
        con.CheckBox__c = true;
    }
}

If you find your Solution then mark this as the best answer. 

Thank you!

Regards,
Suraj Tripathi
This was selected as the best answer