I have a class which i called from a custom button to send the record for approval. Before sending the record for approval I need to validate the record values and if any error is there I want to display it on standard page of the record. For this I have sobjectname.addError(). But is throwing a error :-
System.FinalException: SObject row does not allow errors
My code :-
global class SpecialPricingApproved_Controller{
webService static string SpecialPricingApproved_Request(ID oppid){
List<opportunity> oppList = new List<opportunity>();
for(Opportunity oppResult : [SELECT OwnerId, Manager_of_Manager__c, Max_Discount__c FROM opportunity WHERE ID = :oppid]){
if(oppResult.Max_Discount__c == 10.00 || oppResult.Max_Discount__c == null){
Opportunity oppError = new Opportunity();
oppError = oppResult;
oppError.addError('Max discount should be greater than 10 % for Approval');
return null;
}
if(oppResult.Manager_of_Manager__c == null){
oppList.add(oppResult);
Opportunity_Helper.addManagerofManager(oppList, true);
}
}
//Sending record for approval
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitted for Approval');
req1.setObjectId(oppid);
Approval.ProcessResult res = Approval.Process(req1);
return null;
}
}
My error :
A problem with the OnClick JavaScript for this button or link was encountered:{faultcode:'soapenv:Client', faultstring:'System.FinalException: SObject row does not allow errors Class.SpecialPricingApproved_Controller.SpecialPricingApproved_Request: line 22, column 1', }
Line no 22 is :
oppError.addError('Max discount should be greater than 10 % for Approval');
Can anyone help me to solve this error.