I have an issue with regards to multiplication in apex. My apex class is called in lightning but the issue seems to be on a formula inside the class. Here is the formula and here are the parameters.

Note: pageSize is Integer and pageNumber is decimal.

Integer offset = ((Integer)pageNumber - 1) * pageSize;

Anyone knows about this issue? It seems that the issue is in the multiplication we get an "internal salesforce.com error" when multiplication operating occurs.

by the way we are using this for pagination of a table. here's the link: http://sfdcmonkey.com/2017/01/26/display-record-with-pager-buttons-lightning-component/

  • Try Integer.valueOf(pageNumber) instead – Shane Steinfeld Oct 8 '18 at 12:21

Such errors should not happen so it is probably a compiler bug related to this specific code. The simplest fix is to re-arrange your code until it compiles. One way to do that if pageNumber is never null is:

Integer offset = (pageNumber.intValue() - 1) * pageSize;

Sometimes you run into this issue when core compiler ( written in Java ) couldn't understand the problem and throws an exception which has not been handled in internal java code. You need to make some amendments in your statement and she if you still have the same issue.

Integer currentPageNum = pageNumber != null ? Integer.valueOf( pageNumber ) : 1;
Integer offset = currentPageNum * pageSize;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.