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
Nina CampbellNina Campbell 

Required fields on leads and creating tasks?

Hi!
On a lead record, we have a required field > Industry.  The problem is, people can add tasks to the lead and save them without being forced to enter the Industry on the Lead information.  How can I force them to add content to a lead before they can add a task or save an activity ie a call.
Thanks in advance.
@Karanraj@Karanraj
You can do it with the help of apex trigger in activity object. Try the below code
trigger checkLeadField on Task (before insert,before update) {
    
    Map<Id,Task> Idvalue = new Map<Id,Task>();
    for(Task tsk:trigger.New){
     if(tsk.WhoId != null ){
        Idvalue.put(tsk.whoId,tsk);
     }
    }
    
    for(Lead led : [Select Id from Lead where Id IN:Idvalue.keySet() and Industry = NULL]){
        IdValue.get(led.Id).addError('Lead Industry field must have value');
    }
}
Don't forget to check the trailhead module for apex trigger - https://trailhead.salesforce.com/project/salesforce_developer_workshop/creating_triggers