You need to sign in to do that
Don't have an account?
Khalid mn
If inserting two Account with same phone no then delete one account on insertion..
Hi,
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...
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) { phoneSet.add(Acc.phone); } // 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
This is correct? The if body is empty..
If it is 2nd case.... this trigger will check only existing records of salesforce. Instead of deleting existing records you can try preventing new records from being inserted.
Hi Khalid,
Is this your complete code ?
May I know what action you are taking in IF block section ?
Regards,
Priya ranjan
Thanks
Ankit