Looking to bulkify this trigger. Intention was to create a set of ID's that are of a certain record type, and then pass those into a method that will then check for empty fields. Didn't post all of the code for the TriggerHandler because there are other errors but I want to solve this issue first. Ultimately what I want to do is check each Contact record that is updated at a certain time, check to see if it has any Account/Contact relationship with a certain role, then check the Contact address to make sure it is complete.
Error: "Method does not exist or incorrect signature: void IsPricingLetter(List) from the type ContactTriggerHandler"
Trigger
trigger ContactTrigger on Contact (before update) {
if(trigger.isbefore){
if(trigger.isupdate){
//loop through trigger.new to see if it's a US record type
List<Contact> c = new List<Contact>();
for(Contact USContact : Trigger.new){
String recordtypename = 'CRM Contact US';
if(USContact.recordtype.name==recordtypename){
c.add(USContact.id);
}//End if statement
}//End for loop
ContactTriggerHandler.IsPricingLetter(c);
}//End If IsUpdate
}//End If IsBefore
}//End Class
Trigger Handler
public class ContactTriggerHandler {
public static void IsPricingLetter(List<Contact> con){
//Get list of relationship records that contain Pricing Letters role on the Contact ID being triggered.
List<Contact> conNew = new List<Contact>();
for (Contact USList : con){
conNew.add(USList);
}
This is the rest of the trigger handler, but this is incorrect. You can use this to get a better understanding of what I am looking for.
for(AccountContactRelation c : [SELECT ContactId FROM accountcontactrelation WHERE isActive=true
AND roles INCLUDES ('Pricing Letters') AND Contactid IN :conNew.id]){
//If triggering Contact ID is present, check for missing mailing address components or missing email address.
if(conNew.MailingStreet==null){
conNew.MailingStreet.addError('Mailing Street on a Pricing Letter Contact cannot be null.');
}//End If Mailing Street
if(conNew.MailingCity==null){
conNew.MailingCity.addError('Mailing City on a Pricing Letter Contact cannot be null.');
}//End If Mailing City
if(conNew.MailingPostalCode==null){
conNew.MailingPostalCode.addError('Mailing City on a Pricing Letter Contact cannot be null.');
}//End If Mailing Postal
if(conNew.MailingState==null){
conNew.MailingState.addError('Mailing State on a Pricing Letter Contact cannot be null.');
}//End If Mailing State
if(conNew.MailingCountry==null){
conNew.MailingCountry.addError('Mailing Country on a Pricing Letter Contact cannot be null.');
}//End If Mailing Country
if(conNew.Email==null){
conNew.Email.addError('Email Address on a Pricing Letter Contact cannot be null.');
}//End If Mailing Country
}//End For Loop
}//End IsPricingLetter Method
}//End Class
Thanks in advance.
Set<Id>
to a method is done the same way as you would pass any other type to a method. If you're getting an error message, you should edit your question to include the full text of the error, verbatim (if you try to paraphrase, you're almost guaranteed to leave out important information).Set<Id>
, but rather in how you're using it. The Id is not the SObject itself, so you can't dofor(SObject obj : myIdSet)
. Typically in trigger handlers, you'll see people passing in Lists or Maps of SObjects (not just a collection of the Ids). This is mainly to break the dependency on trigger context variables for testing. In your case though, changing your code to pass/accept aList<Contact>
will let you use.addError()
later on.ContactTriggerHandler
has the code you think it does in the org that you're seeing this error in (open the class in the developer console for that specific org). At the moment, this smacks of "accidentally forgot to deploy the updated code to this org".