• Adam Balme 13
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
I have a VF page that displays a live count of selected rows of a VF page. I'd like to also show a sum of a currency field for the selected records. Let's say the field is Total_Amount__c. 

How could I include this live sum in my page.

here is the code:
Vf page:
<apex:page controller="CountLiveController">
    <script>
        function test()
      {
          console.log('>>yes');
          methodOneInJavascript();
      }
        
        </script>
    <apex:form id="frm" >
        
        <apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="frm"/>

           <apex:pageBlock title="Accounts">

            <apex:pageBlockTable value="{!wrapList}" var="a">
                <apex:column headerValue="Select Account">
                    <apex:inputCheckbox value="{!a.selected}" onchange="test();"/> 
                    
                </apex:column>
                <apex:column headervalue="Account Name" value="{!a.acc.name}"/>
            </apex:pageBlockTable>
             <apex:pageBlockSection>
          Live Count::: {!Count}
            </apex:pageBlockSection>
        </apex:pageBlock> 
    </apex:form>
</apex:page>
Controller:
public class CountLiveController {
    public List<Account> acList{get;set;}
    public List<AccountWrapper> wrapList{get;set;} 
    public List<AccountWrapper> selectedWrap{get;set;}
    public Integer Count{get;set;}
    public CountLiveController()
    {
        acList=new List<Account>();
        selectedWrap = new List<AccountWrapper>();
        acList=[Select name from Account limit 10];// Show number of accounts as per requirement
        wrapList=new List<AccountWrapper>();
        for(Account a:acList)
        {
           AccountWrapper aw=new AccountWrapper(a);
           wrapList.add(aw); 
        }
        System.debug('>>wrapList'+wrapList);
    }

    public class AccountWrapper{
        public Boolean selected{get;set;}
        public Account acc{get;set;}
      public AccountWrapper(Account a)
      {
          acc=a;
          selected=false;
      }
    }
     
   public void methodOne()
   {
       selectedWrap.clear();
       for(AccountWrapper wrap:wrapList)
       {
          if(wrap.selected==true)
          {
             selectedWrap.add(wrap);
          }
          Count=selectedWrap.size(); 
         system.debug('::::'+selectedWrap);
       }  
   }
}

 
Hi,

I have this page which opens a visualforce page on an opportunity record. Its allows the user to select products from the opportunity to include on a newly created quote.

How do I get this to redirect to the newly created quote when the 'Create Quote' button is clicked.

The code woprks fine currently but the user is not redirected.

Many thanks
<apex:page standardController="Opportunity" extensions="CreateQuoteClass" lightningStylesheets="true">
    <apex:sectionHeader title="Opportunity Items"/>
    <apex:form >
        <apex:pageBlock title="Products Items">
            <apex:pageBlockTable var="qi" value="{!quotewrapperlist}" id="quoteitem">
                <apex:column headerValue="Action">
                    <apex:inputCheckbox value="{!qi.isChecked}"/>
                </apex:column>
                <apex:column headerValue="Product" value="{!qi.oliresult.name}"/>
                <apex:column headerValue="Quantity" value="{!qi.oliresult.Quantity}"/>
                <apex:column headerValue="Sales Price" value="{!qi.oliresult.Unitprice}"/>
                <apex:column headerValue="List Price" value="{!qi.oliresult.TotalPrice}"/>
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
                <apex:commandButton value="Create Quote" action="{!saveQuote}" immediate="false"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex class:
public class CreateQuoteClass {
    public String opportunitystringId {get;set;}
    public List<Opportunity> opportunityList {get;set;}
    public List<quotewrapper> quotewrapperlist {get;set;}
    public List<OpportunityLineItem> oliList{get;set;}
    
    public class quotewrapper
    {
        public Boolean isChecked {get;set;}
        public OpportunityLineItem oliresult {get;set;}
        
        public quotewrapper(Boolean isChecked, OpportunityLineItem oliresult)
        {
            This.isChecked = isChecked;
            This.oliresult = oliresult;
        } 
    }   
    
    public CreateQuoteClass(ApexPages.StandardController controller)
    {
        try{
            quotewrapperlist = new List<quotewrapper>();
            opportunitystringId  = ApexPages.CurrentPage().getparameters().get('Id');
            
            if(opportunitystringId!=null)
            {
                opportunityList = [SELECT Id,Name,CloseDate,AccountId,Pricebook2Id from Opportunity WHERE Id =:opportunitystringId];
                oliList = [Select Id,Name,Quantity,OpportunityId,UnitPrice,Product2Id,PricebookentryId,TotalPrice from OpportunityLineItem WHERE OpportunityId =:opportunitystringId];
            }
            
            if(oliList.size()>0)
            {
                for(OpportunityLineItem olObj:oliList)
                {
                    quotewrapper qobj =  new quotewrapper(false, olObj);
                    quotewrapperlist.add(qobj);
                }
            }
        }
        catch(Exception e)
        {
            System.debug('The following exception has occurred: ' + e.getMessage());
        }
        
    }
    
    public void saveQuote()
    {
        try{
            List<OpportunityLineItem> olilistNew = new List<OpportunityLineItem>();  
            List<QuoteLineItem>  quoteItemList = new List<QuoteLineItem>();
            
            for(quotewrapper qwr : quotewrapperlist)
            {
                if(qwr.isChecked==true)
                {
                    olilistNew.add(qwr.oliresult);
                }
            }
            
            List<Quote> quoteListNew = new List<Quote>();
            if(opportunityList.size()>0)
            {
                for(Opportunity opportunityObj : opportunityList)
                {
                    Quote quoteObj = new Quote();
                    quoteObj.Name=opportunityObj.Name;
                    quoteObj.OpportunityId = opportunityObj.Id;
                    quoteObj.Pricebook2Id =opportunityObj.Pricebook2Id;
                    quoteListNew.add(quoteObj); 
                }
            }
            if(quoteListNew.size()>0)
            {
                Database.SaveResult[] quoteItemSaveList = Database.insert(quoteListNew);
            }
            if(olilistNew.size()>0)
            {
                for(Quote qutObj: quoteListNew)
                { 
                    for(OpportunityLineItem oliObj : olilistNew)
                    {  
                        QuoteLineItem qlobj = new QuoteLineItem();
                        qlobj.Quantity=oliObj.Quantity;
                        qlobj.PricebookEntryId=oliObj.PricebookEntryId;
                        qlobj.QuoteId=qutObj.Id;
                        qlobj.Product2Id=oliObj.Product2Id;
                        qlobj.UnitPrice=oliObj.UnitPrice;
                        quoteItemList.add(qlobj);   
                        
                        
        
                    }
                }
                
                if(quoteItemList.size()>0)
                {
                    Database.SaveResult[] quoteItemSaveList = Database.insert(quoteItemList);
                    
                }
            }
        } 
        
        catch(Exception e)
        {
            System.debug('The following exception has occurred: ' + e.getMessage());
           
        }  
        
    
   
    }
}

 
I have a VF page that displays a live count of selected rows of a VF page. I'd like to also show a sum of a currency field for the selected records. Let's say the field is Total_Amount__c. 

How could I include this live sum in my page.

here is the code:
Vf page:
<apex:page controller="CountLiveController">
    <script>
        function test()
      {
          console.log('>>yes');
          methodOneInJavascript();
      }
        
        </script>
    <apex:form id="frm" >
        
        <apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="frm"/>

           <apex:pageBlock title="Accounts">

            <apex:pageBlockTable value="{!wrapList}" var="a">
                <apex:column headerValue="Select Account">
                    <apex:inputCheckbox value="{!a.selected}" onchange="test();"/> 
                    
                </apex:column>
                <apex:column headervalue="Account Name" value="{!a.acc.name}"/>
            </apex:pageBlockTable>
             <apex:pageBlockSection>
          Live Count::: {!Count}
            </apex:pageBlockSection>
        </apex:pageBlock> 
    </apex:form>
</apex:page>
Controller:
public class CountLiveController {
    public List<Account> acList{get;set;}
    public List<AccountWrapper> wrapList{get;set;} 
    public List<AccountWrapper> selectedWrap{get;set;}
    public Integer Count{get;set;}
    public CountLiveController()
    {
        acList=new List<Account>();
        selectedWrap = new List<AccountWrapper>();
        acList=[Select name from Account limit 10];// Show number of accounts as per requirement
        wrapList=new List<AccountWrapper>();
        for(Account a:acList)
        {
           AccountWrapper aw=new AccountWrapper(a);
           wrapList.add(aw); 
        }
        System.debug('>>wrapList'+wrapList);
    }

    public class AccountWrapper{
        public Boolean selected{get;set;}
        public Account acc{get;set;}
      public AccountWrapper(Account a)
      {
          acc=a;
          selected=false;
      }
    }
     
   public void methodOne()
   {
       selectedWrap.clear();
       for(AccountWrapper wrap:wrapList)
       {
          if(wrap.selected==true)
          {
             selectedWrap.add(wrap);
          }
          Count=selectedWrap.size(); 
         system.debug('::::'+selectedWrap);
       }  
   }
}

 

Hi, On Quote Line Items related list I have created a custom button. This custom button will create a visualforce page which will be rendered as pdf.

My issue is that if on the Quote Line Item related list I select more than one Quote Line Item, then all the selected Quote Line Items must be included in the pdf. I am a beginner as developer. So any help to get this done will be highly appreciated.

Also I followed few steps mentioned in this post - https://developer.salesforce.com/forums/?id=906F000000091nOIAQ, however I do not know how to return the selected ids back to vf page and how to make use of them in the vf page.

Please can someone help me with this.

Thank you in advance.

Regards,

Shalini.