• Prashant_pg
  • 0 Points
  • Member since 2020

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1
I have a scenario where if we insert two account at a time with same phone no then delete one account..
I tried below Trigger but there problem is if i am inserting one account with existing account phone no then it is working fine but on the insertion of two account it's not working...
can someone please help me...
trigger DelOneAcc on Account (before insert) {  
    // Here i am storing phone of account into set
    Set <String> phoneSet = new Set<String>();      
    // Iterate through each Account and add their phone number to their respective Sets   
    for (Account Acc:trigger.new) {        
    // New list to store the found phone numbers  
    List <Account> AccList = new List<Account>();      
    AccList = [Select Id, Name, Phone from account WHERE phone IN :phoneSet];     
    // Iterating through each account record to see if the same phone was found     
    for (Account Acc:AccList) {        
        If (AccList.size() > 1) {                             
    delete AccList; 
Thank You in Advance