You need to sign in to do that
Don't have an account?

I faced probloms while writing the Dynamic Approval Process based on the Apex and Trigger
I got error:- Error: Invalid Data. Review all error messages below to correct your data.
Attempt to de-reference a null object
while writing the following code.
trigger AutomateApprove on Opportunity(After insert, After update) { for (Integer i = 0; i < Trigger.new.size(); i++) { try { //Insure that previous value not equal to current, else if there is any field update on approval process action //there will be recurrence of the trigger. if(Trigger.new[i].Next_Step__c == 'Submit' && Trigger.old[i].Next_Step__c != 'Submit') { submitForApproval(Trigger.new[i]); } else if(Trigger.new[i].Next_Step__c == 'Approve' && Trigger.old[i].Next_Step__c != 'Approve') { approveRecord(Trigger.new[i]); } else if(Trigger.new[i].Next_Step__c == 'Reject' && Trigger.old[i].Next_Step__c != 'Reject') { rejectRecord(Trigger.new[i]); } }catch(Exception e) { Trigger.new[i].addError(e.getMessage()); } }
please give me solution
Trigger.old is only populated for update and delete operations. In your case the trigger is firing after an insert (as well as an update) so lines such as:
will throw an error. I reckon you need something like:
All Answers
Trigger.old is only populated for update and delete operations. In your case the trigger is firing after an insert (as well as an update) so lines such as:
will throw an error. I reckon you need something like:
Thank you very much.............
Now it working
ok, Its working successfully .But i faced problems while writing the test class for this trigger cover the code .
Please give me the code for the test class to cover the code .Please....