function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JAGJOT SINGHJAGJOT SINGH 

Error: Invalid Data. Apex trigger AmountTask caused an unexpected exception, contact your administrator: AmountTask: execution of AfterUpdate caused by: System.NullPointerException: Argument cannot be null.: Trigger.AmountTask: line 44, column 1

trigger

public class createoppojjb{

    public static void account(set<id> AcountID)
    {
      
 
  List<Opportunity> oppList = [Select id, Name, AccountId, Amount from Opportunity where AccountId IN : AcountID];
        
        Map<Id,List<Opportunity>> mapOpp = new Map<Id,List<Opportunity>>();
        
        for(Opportunity opp : oppList){
            if(mapOpp.containsKey(opp.AccountId)){
            
                List<Opportunity> oppAcountID = mapOpp.get(opp.AccountId);
                oppAcountID.add(opp);
                mapOpp.put(opp.AccountId,oppAcountID);
            }
            else{
                List<Opportunity> oppAcountID = new List<Opportunity>();
                oppAcountID.add(opp);
                mapOpp.put(opp.AccountId,oppAcountID);
            
            }
        
        }
        
        
        List<Opportunity> opp;
        Double Amount = 0;
        String Idd;
        
        for(Id oppId : mapOpp.keySet()){
            
            opp = mapOpp.get(oppId);
            System.debug(opp);
            
            for(Opportunity amt : opp){
                Amount += amt.Amount;
                System.debug(Amount);
            }
            
        }
        
        Boolean flag = true;
        List<Opportunity> names = new List<Opportunity>([Select Id, Name, Amount from Opportunity where Id IN : opp]);
        
        System.debug('names  '+names + ' ' + flag);
        
        for(Opportunity oppName : names){
            if(oppName.Name == 'Test'){
                System.debug(Amount);
            }
        }
        }
        }


class

trigger CreateOpp on Account (after update, after insert) {
  if((Trigger.IsAfter && Trigger.isUpdate)) {

  Set<Id> accID = new Set<Id>();
   for(Account acc:Trigger.New) {
            if(acc.Name != 'null') {
            accID.add(acc.id);
            }
        }
    if(accID.size()>0) {
            createoppojjb.Addaccopp(accID);
        }
   }     
}
Best Answer chosen by JAGJOT SINGH
Harshit Garg 6Harshit Garg 6
Hi Singh,
 
trigger CreateOpp on Account (after update, after insert) {
  if((Trigger.IsAfter && Trigger.isUpdate)) {

  Set<Id> accID = new Set<Id>();
   for(Account acc:Trigger.New) {
            if(acc.Name != 'null') {
            accID.add(acc.id);
            }
        }
    if(accID.size()>0) {
            createoppojjb.account(accID);
        }
   }   
}

Please use that above trigger

Thanks,
Harshit Garg

All Answers

Harshit Garg 6Harshit Garg 6
Hi Singh,
 
trigger CreateOpp on Account (after update, after insert) {
  if((Trigger.IsAfter && Trigger.isUpdate)) {

  Set<Id> accID = new Set<Id>();
   for(Account acc:Trigger.New) {
            if(acc.Name != 'null') {
            accID.add(acc.id);
            }
        }
    if(accID.size()>0) {
            createoppojjb.account(accID);
        }
   }   
}

Please use that above trigger

Thanks,
Harshit Garg
This was selected as the best answer
JAGJOT SINGHJAGJOT SINGH
same  err sir
Harshit Garg 6Harshit Garg 6
Hi Singh,

Your trigger name is CreateOpp . That error is not coming through this trigger...that error coming through another trigger.

May be trigger name is - Amounttask.

Please check your another trigger.

Thanks,
Harshit Garg
Eric PepinEric Pepin
Post the code for the trigger that is actually throwing the exception or nobody will be able to help you.
JAGJOT SINGHJAGJOT SINGH

Hello Sir,

Mr Harshit Garg,

your suggetion working. my other trigggers create a errors.now code is working sir,

 

Thanks Alot,
Jagjot Singh

Harshit Garg 6Harshit Garg 6
HI Jagjot,

If my suggestion work for you..Please choose my ans as the best ans.

Thanks,
Harshit Garg