• Jack Seven
  • NEWBIE
  • 0 Points
  • Member since 2013

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

trigger Order on Project_Item__c (after insert, after update, after delete) {
Set<Id> setId = new Set<Id>();
for(Project_Item__c pi:trigger.new)
      setId.add(pi.Master_Detail__c);
Map<Id,Project__c> mapProject = new Map<Id, Project__c>([SELECT Id, Total_Open_custom__c,  Total_Pipeline_custom__c FROM Project__c WHERE Id in:setId]); 

for(Project_Item__c item:trigger.new){
      if(item.status__c=='Open'){
           if(mapProject.get(item.Master_Detail__c).Total_Open_custom__c==null){
                 mapProject.get(item.Master_Detail__c).Total_Open_custom__c=item.Total_Amount__c;
           }else{
                 mapProject.get(item.Master_Detail__c).Total_Open_custom__c+=item.Total_Amount__c;
             }
       }else if(item.status__c=='Pipeline'){
                 if(mapProject.get(item.Master_Detail__c).Total_Pipeline_custom__c==null){
                       mapProject.get(item.Master_Detail__c).Total_Pipeline_custom__c=item.Total_Amount__c;
                 }else{
                       mapProject.get(item.Master_Detail__c).Total_Pipeline_custom__c+=item.Total_Amount__c;
                 }
       }
}
if(trigger.isDelete){
      for(Project_Item__c pi1 : trigger.new){
if(pi1.status__c=='Open'){
if(mapProject.get(pi1.Master_Detail__c).Total_Open_custom__c==null){
mapProject.get(pi1.Master_Detail__c).Total_Open_custom__c=pi1.Total_Amount__c;
}else{
mapProject.get(pi1.Master_Detail__c).Total_Open_custom__c-=pi1.Total_Amount__c;
}
}else if(pi1.status__c=='Pipeline'){
if(mapProject.get(pi1.Master_Detail__c).Total_Pipeline_custom__c==null){
mapProject.get(pi1.Master_Detail__c).Total_Pipeline_custom__c=pi1.Total_Amount__c;
}else{
mapProject.get(pi1.Master_Detail__c).Total_Pipeline_custom__c+=pi1.Total_Amount__c;
}
}
}
}
update mapProject.values();
}

 

When i deleted item of Project_Item__c, it showed a message : The first validation error encountered was "Apex trigger Order caused an unexpected exception, contact your administrator: Order: execution of AfterDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.Order: line 3, column 1".

 

Please help me!

i want to add 2 buttons on the Project details : 'Mass update Items', 'Mass create items'
When click, it should open a screen where we can mass update/create.

How can i do? please, help me!

i want to add 2 buttons on the Project details : 'Mass update Items', 'Mass create items'
When click, it should open a screen where we can mass update/create.

How can i do? please, help me!

i want to add 2 buttons on the Project details : 'Mass update Items', 'Mass create items'
When click, it should open a screen where we can mass update/create.

How can i do? please, help me!