+ Start a Discussion
Andrew TelfordAndrew Telford 

Method does not exist or incorrect signature: [List<Contact>].addError(String)

Hi

I am getting the following error when I am in the developer console and if I attempt to trigger the process on the contact layout.
 
Method does not exist or incorrect signature: [List<Contact>].addError(String)

What I am trying to do is return a message as an error to the contact screen in the event that the number of contacts meeting a specific criteria is exceeded.

 
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
//
//  Name:
//      CI_MagicMover
//
//  Purpose:
//      This is a script to ensure that the user only has a certain number of contacts listed 
//      as a Magic Mover
//  
//  Created by:
//      Andrew Telford
//
//  Date: 
//      2015-07-22
//
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------

trigger CI_MagicMover on Contact (before update) {
    Contact[] sContact;

    sContact = Trigger.new;

//	Create the object to store the current ID
//----------------------------------------------------------------------------------------------
    Set<ID> contactID = new Set<ID>();
    Set<ID> ownerID = new Set<ID>();

//	Set Variables
//----------------------------------------------------------------------------------------------
    integer magicLimit = 20;

//  Collect the Contact ID from the current record
//----------------------------------------------------------------------------------------------
    FOR(Contact objCont : sContact)
    {
        contactID.add(objCont.Id);
        ownerID.add(objCont.OwnerId);
    }

//	Select all the records that this user might have as a Magic Mover
//----------------------------------------------------------------------------------------------
    integer intContacts = [SELECT count() FROM Contact WHERE OwnerID IN :ownerID AND CCC_Adviser__c = TRUE];

    FOR( Contact cont : trigger.new)
    {
        IF (intContacts > magicLimit)
        {
// Error occrs here
            sContact.addError('The Owner of this contact already has ' + magicLimit + ' Contacts on the Magic Movers List');
        }
        else
        {
// Error occurs here
            sContact.addError('Contact Count is: ' + intContacts);
        }
    }

}

 
Best Answer chosen by Andrew Telford
pconpcon
You'll need to add it to the contact directly instead of to the list
 
cont.addError('...');

the addError method does not exist on lists, only on individual sObjects

All Answers

pconpcon
You'll need to add it to the contact directly instead of to the list
 
cont.addError('...');

the addError method does not exist on lists, only on individual sObjects
This was selected as the best answer
Andrew TelfordAndrew Telford
Thanks ... that did the trick. 

I swear that I had tried that at some point.

Thanks again.