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
sree sfdcsree sfdc 

How to solve this error:Compile Error: line 31:23 no viable alternative at character '–' at line 31 column 23

Hi 
This is my code please help me 
VF Page
-------------
<apex:page controller="pagination1">
<apex:form >
<apex:pageBlock id="details">
<apex:pageblockTable value="{!accountlist}" var="account">

<apex:column value="{!account.name}"/>
<apex:column value="{!account.rating}"/>
<apex:column value="{!account.phone}"/>
<apex:column value="{!account.NumberOfEmployees}"/>
</apex:pageblockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Fisrt" action="{!first}" reRender="details" disabled="{!prev}"/>
<apex:commandButton value="Previous" action="{!prev}" reRender="details" disabled="{!prev}"/>
<apex:commandButton value="Next" action="{!nxt}" reRender="details" disabled="{!nxt}"/>
<apex:commandButton value="Last" action="{lst}" reRender="details" disabled="{!nxt}"/>

</apex:pageBlockButtons>

</apex:pageBlock>


</apex:form>
 
</apex:page>

Apex 
-------------
public class pagination1 {

   public class Pagination
{
private integer totalRecs = 0;
private integer OffsetSize = 0;
private integer LimitSize= 10;
public Pagination()
{
totalRecs = [select count() from account];
}
public List<account> getacclist()
{
List<account> acc = Database.Query('SELECT Name, rating, phone, numberofemployees,FROM account LIMIT :LimitSize OFFSET :OffsetSize');
System.debug('Values are'+ acc);
return acc;
}
public void First()
{
OffsetSize = 0;
}
public void previous()
{
OffsetSize = OffsetSize - LimitSize;
}
public void next()
{
OffsetSize = OffsetSize + LimitSize;
}public void Last()
{
OffsetSize = totalrecs – math.mod(totalRecs,LimitSize);
}
public boolean getprevious()
{
if(OffsetSize == 0)
return true;
else
return false;
}
public boolean getnext()
{
if((OffsetSize + LimitSize) > totalRecs)
return true;
else
return false;
}
}
Best Answer chosen by sree sfdc
krprkrpr
I Have corrected your controller . The following code should work.

public class Pagination1
    {

    public String nxt { get; set; }

    public PageReference nxt() {
        return null;
    }


    public PageReference prev() {
        return null;
    }


    public String prev { get; set; }
        private integer totalRecs = 0;
        private integer OffsetSize = 0;
        private integer LimitSize= 10;
        public Pagination1()
        {
        totalRecs = [select count() from account];
        }
        public List<account> getAccountlist()
        {
        List<account> acc = Database.Query('SELECT Name, rating, phone, numberofemployees FROM account LIMIT :LimitSize OFFSET :OffsetSize');
        System.debug('Values are'+ acc);
        return acc;
        }
        public void First()
        {
        OffsetSize = 0;
        }
        public void previous()
        {
        OffsetSize = OffsetSize - LimitSize;
        }
        public void next()
        {
        OffsetSize = OffsetSize + LimitSize;
        }public void Last()
        {
        OffsetSize = totalrecs - math.mod(totalRecs,LimitSize);
        }
        public boolean getprevious()
        {
        if(OffsetSize == 0)
        return true;
        else
        return false;
        }
        public boolean getnext()
        {
        if((OffsetSize + LimitSize) > totalRecs)
        return true;
        else
        return false;
        }
    }

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Regards
Ram

All Answers

Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
It seems like on line OffsetSize = totalrecs – math.mod(totalRecs,LimitSize); after totalrecs minus sign(-) is replaced with hyphen(–).
If you have copied that line from somewhere I would reccomend you to type it manually.

-N.J
ShashForceShashForce
Hi,

This error is seen with query issues. There is a character '–' somewhere in the code which is not the same as the '-' difference operator. This happens sometimes when code is copy-pasted and the formatting is not correct. Please remove all the difference operators and retype them with the correct '-' character and this error should be resolved. Check the following statements in your code for the same:

OffsetSize = OffsetSize - LimitSize;

and

OffsetSize = totalrecs – math.mod(totalRecs,LimitSize); //(The operator character looks suspiciously incorrect here.)

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank
krprkrpr
I Have corrected your controller . The following code should work.

public class Pagination1
    {

    public String nxt { get; set; }

    public PageReference nxt() {
        return null;
    }


    public PageReference prev() {
        return null;
    }


    public String prev { get; set; }
        private integer totalRecs = 0;
        private integer OffsetSize = 0;
        private integer LimitSize= 10;
        public Pagination1()
        {
        totalRecs = [select count() from account];
        }
        public List<account> getAccountlist()
        {
        List<account> acc = Database.Query('SELECT Name, rating, phone, numberofemployees FROM account LIMIT :LimitSize OFFSET :OffsetSize');
        System.debug('Values are'+ acc);
        return acc;
        }
        public void First()
        {
        OffsetSize = 0;
        }
        public void previous()
        {
        OffsetSize = OffsetSize - LimitSize;
        }
        public void next()
        {
        OffsetSize = OffsetSize + LimitSize;
        }public void Last()
        {
        OffsetSize = totalrecs - math.mod(totalRecs,LimitSize);
        }
        public boolean getprevious()
        {
        if(OffsetSize == 0)
        return true;
        else
        return false;
        }
        public boolean getnext()
        {
        if((OffsetSize + LimitSize) > totalRecs)
        return true;
        else
        return false;
        }
    }

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Regards
Ram
This was selected as the best answer
sree sfdcsree sfdc
hi krpr,
thank u for ur great response.
it showing agin error like;

pagination1 Compile Error: The method String getNxt() is referenced by Visualforce Page (pagination1) in salesforce.com. Remove the usage and try again. at line 3 column 19