• vikas chand 18
  • NEWBIE
  • 5 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
Hi Developers,

I am write a trigger on Contact Object. trigger work on single record but on bulk data its not working properly.
My code is Here
trigger UpdateContactName on Contact (before insert){
    set<id> setAccountId=new set<id>();
    if (Trigger.isAfter) {
        if (Trigger.isInsert)  {
            for(contact con : Trigger.new){
                if(con.accountId != null){
                   setAccountId.add(con.AccountId);   
                }
                list<string> conId = new list<string>();
                for(contact c : [select id, FirstName, lastName from contact where AccountId IN : setAccountId]){
                    conId.add(c.Id);
                }
                for(contact cont : trigger.new){
                    cont.FirstName = '';
                    cont.lastName = '';
                    cont.FirstName = 'Pr';
                    cont.lastName = string.valueof(conId.size());
                }
                
            }
        } 
    } 
}
Any one can correct my code or any suggetions 
Thanks in advance
 
 write a trigger on Account, While inserting a account  name value as ‘someName’ ended with ‘text’ ex: ‘renuText’.
 it should through an error On Account Object if name field has 'text' 
  • January 31, 2018
  • Like
  • 0
I am trying to find an easy way to locate and remove duplicate accounts.  I haven't located a good way, so was curious if anyone would have any suggestions.
Thank you,
Kiley