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
MNCGuntaka GMNCGuntaka G 

apex class called 'contactutility'

Dear Members, Can you please help me to complete the below task on apex class called 'contactutility' HAVE TO CREATE A METHOD: method name: updateContactEmailOptout access modifier:Private Return Type: Boolean

The method updateContactEmailOptout will be passed with a set of contact ID's. For each of this contacts querid from the salesforce if the contact has the email populated, update its email opt out field to 'true' By using salesforce practices like bulk handing
Abhishek BansalAbhishek Bansal
Hi,

Please find your required code below :
Public Class ContactUtility {
	private Boolean updateContactEmailOptout(Set<id> conIds){
		Boolean isAnyContactUpdated = false;
		List<Contact> listOfContactsToBeUpdated = new List<Contact>();
		for(Contact con : [Select HasOptedOutOfEmail from Contact where Email != null AND HasOptedOutOfEmail = false AND Id IN :conIds]){
			con.HasOptedOutOfEmail = true;
			listOfContactsToBeUpdated.add(con);
		}
	}
	if(listOfContactsToBeUpdated.size() > 0){
		update listOfContactsToBeUpdated;
		isAnyContactUpdated = true;
	}
	return isAnyContactUpdated;
}


Let me know if you need more help on this.

Thanks,
Abhishek Bansal