+ Start a Discussion
shan876shan876 

ADDError Help please

I have a save button and wrote the controller as so...

Basically the VF Page brings up all the quoteitems that want/need to be edited...

If any of those exceed the limit specified then they can not save it...

Here is my code:

 

public PageReference save() { integer i=0; for ( i=0; i< quoteLineItems.size(); i++ ) { SFDC_520_QuoteLine__c[] ql = [Select Sales_Discount__c from SFDC_520_Quoteline__c where id =:quoteLineItems[i].id]; if (ql[0].Sales_Discount__c > rsl[0].License__c && UserInfo.getProfileId() == '00e00000006olyLAAQ') { quoteLineItems[i].Sales_Discount__c.addError('The discount levels displayed in this quote exceed limitations. Please contact your administrator or manager if you believe that you have received this in error.'); } else{ upsert quoteLineItems; if ( todelete.size() > 0 ) { delete todelete; } queryQuoteLines(quote.id); return quotePR(); } } return null; }

 So then I tried to rearrange it and this works when all of them exceed but if one of the quoteline discounts does not exceed then it lets the user save it????

 

public PageReference save() { integer i=0; for(SFDC_520_QuoteLine__c ql : quoteLineItems){ if (ql.Sales_Discount__c > rsl[0].License__c && UserInfo.getProfileId() == '00e00000006olyLAAQ') { ql.Sales_Discount__c.addError('The discount levels displayed in this quote exceed limitations. Please contact your administrator or manager if you believe that you have received this in error.'); } else{ upsert quoteLineItems; if ( todelete.size() > 0 ) { delete todelete; } queryQuoteLines(quote.id); return quotePR(); } } return null; }