• pranav anand
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
public class PricebookEntryDetailController
{
    public PageReference products()
    {
        return null;
    }
    public Set<String> selectedRecordIds{get;set;}//Set for maintaining which Id's are selected
    public integer index = 0;
    public integer blockSize = 5; 
    public List<PBEwrapper> wrapperList{get;set;}
    public List<SelectOption> pricebookList;
    public String selectedPriceBookId{get;set;}
    public List<pricebookEntry> priceDetailList{get;set;}
    public Map<Id,PricebookEntry> cartItemsMap {get;set;}
   
    //constructor
    public PricebookEntryDetailController()
    {   
        selectedRecordIds = new Set<String>();
        wrapperList = new List<PBEwrapper>(); 
        priceDetailList = new List<pricebookEntry>();
       
    }
   
   
    // Get Availabel Price Books
    public List<SelectOption> getPricebookList()
    {
        pricebookList = new List<SelectOption>();
       
        for(Pricebook2 pb:[select id, name from pricebook2])
        {
            pricebookList.add(new selectoption(pb.id,pb.name));
        }
        return pricebookList;
    }

   
    // Product List 
    public List<PBEwrapper> getProducts()
    {
        wrapperList.clear();
        priceDetailList.clear();
       
        priceDetailList = Database.Query('SELECT Id,Product2.Name,Product2.productcode, UnitPrice FROM PricebookEntry where Pricebook2Id=: selectedPriceBookId limit :blockSize offset :index');
       
        //Product check list
        for(pricebookEntry entry : priceDetailList )
        {
             if( selectedRecordIds.contains(entry.Id))
                 wrapperList.add(new PBEwrapper(entry,true));
             else
                 wrapperList.add(new PBEwrapper(entry,false));
        }
       
        return wrapperList;
    }
   
   
    //to get page Number
    Public Integer PageNumber
    {
        get{return index/blockSize+1;}
        set;
    }

    // Go to next page of product list
    public void next()
    {
        //loop for maintaining which Id's are selected
        for(PBEwrapper p : wrapperList)
        {
            if (p.selected && !selectedRecordIds.contains(p.PriceEntry.Id))
                selectedRecordIds.add(p.PriceEntry.Id); 
            else if(!p.selected && selectedRecordIds.contains(p.PriceEntry.Id))
                selectedRecordIds.remove(p.PriceEntry.Id);
        }
       
        index += blockSize;
    }
   
    // Go to previous page of product list
    public void previous()
    {
        //loop for maintaining which Id's are selected
        for(PBEwrapper p : wrapperList)
        {
            if(p.selected && !selectedRecordIds.contains(p.PriceEntry.Id))
                selectedRecordIds.add(p.PriceEntry.Id);
            else if(!p.selected && selectedRecordIds.contains(p.PriceEntry.Id))
                selectedRecordIds.remove(p.PriceEntry.Id);
        }
       
        index -= blockSize; 
    }
   
   
    // Total No. of products in pricebook
    public Integer totalRecs
    {
        get
        {
            totalRecs = 0;
            if(selectedPriceBookId!= Null || selectedPriceBookId != '')
                totalRecs = [select count() from pricebookEntry where Pricebook2Id=: selectedPriceBookId];
           
            return totalRecs;
        }
        set;
    }
   
    // To Make next button disbled if there is no next page
    public Boolean gethasNext()
    {
        if((index + blockSize) >= (totalRecs-index))
            return true;
        else
            return false;
    }
   
    //To Make pevious button disbled if there is no previous page
    public Boolean gethasPrevious()
    {
        if(index == 0)
            return true;
        else
            return false;
    }
   
   
    //Redirect to cart page
    public PageReference AddToCart()
    {
        for(PBEwrapper p : wrapperList)
        {
            if(p.selected && !selectedRecordIds.contains(p.PriceEntry.Id))
                selectedRecordIds.add(p.PriceEntry.Id);
            else if(!p.selected && selectedRecordIds.contains(p.PriceEntry.Id))
                selectedRecordIds.remove(p.PriceEntry.Id);
        }
        cartItemsMap = new Map<Id,PricebookEntry>([SELECT Id,Product2.Name,Product2.productcode, UnitPrice FROM PricebookEntry where Id IN: selectedRecordIds]);
        PageReference cartPage = Page.PricebookEntryDetails2;//here is new VF page Redirect through (Add To Cart) Button
        cartPage.setRedirect(false);
        return cartPage;
    }
 
    //To delete the selected records
    public void DeletingRow( )
    {
        String cartItemId =  Apexpages.currentPage().getParameters().get('recordId');
        cartItemsMap.remove(cartItemId);
    }
   
    // Redirect to main page
    public PageReference BackToMainPage()
    {
        PageReference mainpage = Page.PricebookEntryDetails;//here is the main VF page redirect through Button
        mainpage.setRedirect(false);
        return mainpage;
    }
   
    //wrapper class
    class PBEwrapper
    {
        public PricebookEntry PriceEntry{get;set;}
        public Boolean selected{get;set;}
        public PBEwrapper(PricebookEntry pbe,Boolean selected)
        {
            PriceEntry = pbe;
            this.selected = selected;
        }
    }
}
Hi,

I want to do a Math.mod operation on a string (contains numeric values only) in an apex class. The maximul length of the string is 19.
Here is a sample value : 57901220028758151855

The problem is when I try to convert this to Long using Long.valueOf(string) , there is a type exception : invalid long
So I tried to get the long value using : Decimal.valueOf(string).longValue() , but when I check the value using System.debug  & it is = 2560987807629497007 , not the same as the original, so the mod result is also not correct.
I have to convert to Int, or Long because those are the only 2 types accepted by Math.mod(). and the max length of Integer is too small for these numeric strings.

The same operation is being performed in a validation rule using MOD (VALUE(string),divisor) with no problems.

Please help.

Regards,

A Me

  • September 12, 2014
  • Like
  • 0