• Itbkannan
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies

I'm trying to implement a trigger to prevent duplicate contacts from being entered.  The criteria is that it should prevent the contact from being added if the first and last name and any of the phone numbers match those of an existing contact, or if the email matches an existing contact regardless of whether the name matches or not.

 

Here's the code I'm trying to get it to accept:

 trigger ContactDuplicateTrigger on Contact (before insert) {
for (Contact c : Trigger.new){
Contact[] contacts= [select id from Contact where
    (FirstName = :c.FirstName and LastName = :c.LastName) and
    (Phone=:c.Phone or MobilePhone=:c.MobilePhone or HomePhone=:c.HomePhone or OtherPhone=:c.OtherPhone or Home_Phone_2__c=:c.Home_Phone_2__c)
    or Email = :c.Email];
if (contacts.size() > 0) {
c.LastName.addError('Contact cannot be created - Contact already exists with the same email or name-phone combination.');
}
}
}

 

Here's the error it gives me:

 

 Error: Compile Error: expecting right square bracket, found 'or' at line 6 column 4

 

I tried adding in parentheses to group the logic correctly, but I wonder if Apex support it.  Can someone help me with the syntax to enforce the desired logic?

 

Thank you!

I have executed following query to retrieve owner details of the account,

 

Select a.Owner.Fax, a.Owner.Phone, a.Owner.Email, a.Owner.Title, a.Owner.Name, a.Owner.FirstName, a.Owner.LastName, a.Owner.Username, a.OwnerId From Account a

 

But somehow only following fields are retreived:

{Name=Demo System, Email=demo@akritiv.comFirstName?=Demo, Id=005A0000000YnfSIAS,LastName?=System}  

 

You will see that Owner Name,Email values are coming but phone title etc are not coming. 

 

Anybody has any idea on this. Please let me know. 



Can someone tell me what I'm missing here.  In the debug log it says no records found after I update an OpportunityLineItem record:

 

Trigger.oppLineItem_prod_data_trigger2: line 20, column 33: SOQL query with 0 rows finished in 3 ms

 

trigger oppLineItem_prod_data_trigger2 on OpportunityLineItem (after insert, after update) { Set<String> opportunityLineItemIDs = new Set<String>(); List<OpportunityLineItem> updtOpportunityLineItems = new List<OpportunityLineItem>(); OpportunityLineItem[] opportunityLineItems = new List<OpportunityLineItem>(); OpportunityLineItem[] oliList = [select pricebookentry.product2.bu_code__c FROM OpportunityLineItem where id in :opportunityLineItemIDs]; for(OpportunityLineItem oli : oliList) { oli.bu_code__c = oli.pricebookentry.product2.bu_name__c; } update oliList; }