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
KRamaKRama 

Getting complie error while executing an trigger

Hi,

 

I am trying to follow the following trigger

 

trigger leadDupCheck on Lead(before insert, before update) {
if (Trigger.new.Email != null) {
    Integer dupCount =[select count() from Lead WHERE email = :Trigger.new.Email];
     if ( dupCount > 0 ) {
       Trigger.new.email.addError('Lead is a duplicate');
      } else {
      }
  }
 }

 

 

I am able to excecute this trigger when used on the Object Lead, while trying to follow the same syntax on a custom object am getting an error

 

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST:SOBJECT:

 

i have replaced the object and field name appropriately

 trigger t on Candidate__c (before insert, before update) {
    if (trigger.new.Email__c != null){
        integer ecount = [select count() from Candidate__c WHERE Email__c = :Trigger.new.Email__c];
        if (ecount > 0){
            Trigger.new.Email__c.addError('Candidate already exists');
        }
    }
}

 

Please let me know what this error is about and how to proceed further

 

thanks

KD

SteveBowerSteveBower
My offhand guess would be that Trigger.new is not a single SObject, but a List of objects.  Look into writing bulk safe triggers.  Best, Steve.
KRamaKRama

Thanks Steve. Following your suggestion when created  a trigger for bulk I was able to execute it for the desired result. Thanks again for the response and pointer.

 

KD