• Mrityunjay Pandey
  • NEWBIE
  • 0 Points
  • Member since 2017

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

The below trigger was fired after updating the field twice, but it was not fired before update.
 
trigger age on Account (before update) {

  Map<Id,Account> ageMap = new Map<Id,Account>(); 
  Account[] acct = [SELECT Id,Age__c FROM Account WHERE Id IN : Trigger.newMap.keySet()];
    
     for(Account a : trigger.new){
           

            if(a.age__c != null){
             
                ageMap.get(a.Id);
                a.Is_Age_Updated__c = true;
               
            }
            else{
                
             ageMap.get(a.Id);
             a.Is_Age_Updated__c = false;
            }                  
    }

}


 
  • February 02, 2018
  • Like
  • 0
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