• Shruthi MN 19
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 13
    Replies
I have written a schedule class to update the lead source to web if the lead source is null. I have written test class as well. But code coverage is 0% can anyone help me so that code coverage is 100%

Class 

global class LeadMaintanace implements Schedulable{
    global void execute(SchedulableContext SC) {
        List<Lead> li =[Select Id,Name from Lead where LeadSource = 'null' LIMIT 10];
        List<Lead> lu= new  List<Lead>();
        if(!li.isEmpty()){
            for(Lead ld:li){
                ld.LeadSource = 'Web';
                lu.add(ld);
            }
                }
        update lu;
    }

}

test class

@isTest
public class TestLeadMaintanace {
    @testsetup
    static void setup(){
        List<Lead> li = new List<Lead>();
        for(Integer i;i<10;i++){
            Lead ld = new Lead(Company = 'Proseraa',LastName ='MN',Status = 'Working - Contacted');
            li.add(ld);
            
            
        }
        update li;
        
    }
    static testmethod  void TestJobSchedule(){
        string sch = '0 30 12 2 20 ?';
        Test.startTest();
        string jobid=System.Schedule('SchedulableClass',sch, new LeadMaintanace());
        List<Lead> li =[Select Id from Lead where LeadSource=null limit 10];
        system.assertEquals(10,li.size());
        test.stopTest();
        
    }
    
    
}
@istest
private class Accountupdate {
    @istest
    static void tetslead(){
        List<Account> l= new List<Account>();
        Account a= new Account();
        a.Name='surya';
        a.Phone='123';
        l.add(a);
        insert l;
   
    Test.startTest();
    Accountupdate ap= new Accountupdate();
    Id jobid= Database.executeBatch(ap);
    Test.stopTest();
    }
}

class

global class Accountupdate implements Database.Batchable<sObject>
{

    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT Id,Name,Phone FROM Account ';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Account> scope)
    {
        for ( Account a : scope)
        {
           a.Phone='123';
        }
        update scope;
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}

I am getting below error

User-added image
User-added image

I have written a code to add all opportunity amount on quota object and display the list of all opportunity

I am getting the above error

Now I have added inline edit for the same on VF page

<apex:page controller="listopponquota" lightningStylesheets="true" action="{!docallouts}">
    <apex:form > 
        <apex:pageBlock rendered="true" >
            <apex:pageBlockTable value="{!oppList}" var="v">
                <apex:column value="{!v.OwnerId}"/>
                
                <apex:column headerValue="Opportunity Name">
                    <apex:outputlink value="/{!v.Id}">{!v.Name}</apex:outputlink>
                </apex:column>
                <apex:column value="{!v.CloseDate}"/>
                <apex:column value="{!v.StageName}"/>
                <apex:column value="{!v.Amount}"/>
            </apex:pageBlockTable>
             <apex:outputField value="{!oppList}">
                      <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" 
                        hideOnEdit="editButton,deleteButton" event="ondblclick" 
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                  </apex:outputField>
        </apex:pageBlock>
    </apex:form> 
</apex:page>
I have written the below code to add all amount on quota object I am getting below error

User-added image

public with sharing class listopponquota {
     public list<Opportunity> oppList{get;set;}
    public list<quota__c> qutoaList{get;set;}
    public set<ID> oppIds = new set<ID>(); 
    
public void listopponquota()
    {
        String selectedVal ='';
        oppList = new list<Opportunity>();
        qutoaList = new list<quota__c>();
        oppList();
    }
    
    
    
    public pageReference oppList() {
        Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
        system.debug('Id-->'+qId);    
        List<quota__c> quotaList1 = new List<quota__c>();
        List<Opportunity> oppList1 = new List<Opportunity>();
        
        quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c,Actual_Amount__c, OwnerId from quota__c where Id   =: qId Limit 1];
        oppList1 = [Select Id, Name, CloseDate, StageName,OwnerId,Amount From Opportunity where StageName = 'Closed Won'];
        
        system.debug('quotaList1-->'+quotaList1);
        if(quotaList1.size() > 0){
            for(quota__c q : quotaList1){
                
                for(Opportunity opp : oppList1){
                    system.debug('closedDate-->'+opp.CloseDate);
                    if(opp.CloseDate  >=  q.Start_Date__c  && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId){
                        oppList.add(opp);
                        oppIds.add(opp.id);
                    } 
                }                
            }
        }
        for(aggregateresult ag : [SELECT SUM(Amount) sum FROM Opportunity where ID =:oppIds]){
            system.debug('oppList-->'+double.valueof(ag.get('SUM')));
            for(quota__c q : quotaList1){
                if(q.Actual_Amount__c != double.valueof(ag.get('SUM'))){
                    q.Actual_Amount__c = double.valueof(ag.get('SUM'));
                    qutoaList.add(q);
                   
                }
            }
        }
        system.debug('oppList-->'+oppList.size());
        return null;
    }
    
    public void doCallout(){
        system.debug('qutoaList-->'+qutoaList.size());
        if(qutoaList.size()>0){
            Schema.getGlobalDescribe().get('Quota__c').newSObject();
            update qutoaList;
        }
        
    }
}
I have written the below code to update bulk records to add all opportunity amount on quota object. Since it is a bulk record I have used asynchronous bulk update records.


public with sharing class listopponquota {
     public list<Opportunity> oppList{get;set;}
    public list<quota__c> qutoaList{get;set;}
    public set<ID> oppIds = new set<ID>(); 
 
public void listopponquota()
    {
        String selectedVal ='';
        oppList = new list<Opportunity>();
        qutoaList = new list<quota__c>();
        oppList();
    }
    
    
    
    public pageReference oppList() {
        Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
        system.debug('Id-->'+qId);    
        List<quota__c> quotaList1 = new List<quota__c>();
        List<Opportunity> oppList1 = new List<Opportunity>();
        
        quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c,Actual_Amount__c, OwnerId from quota__c where Id   =: qId Limit 1];
        oppList1 = [Select Id, Name, CloseDate, StageName,OwnerId,Amount From Opportunity where StageName = 'Closed Won'];
        
        system.debug('quotaList1-->'+quotaList1);
        if(quotaList1.size() > 0){
            for(quota__c q : quotaList1){
                
                for(Opportunity opp : oppList1){
                    system.debug('closedDate-->'+opp.CloseDate);
                    if(opp.CloseDate  >=  q.Start_Date__c  && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId){
                        oppList.add(opp);
                        oppIds.add(opp.id);
                    } 
                }                
            }
        }
        for(aggregateresult ag : [SELECT SUM(Amount) sum FROM Opportunity where ID =:oppIds]){
            system.debug('oppList-->'+double.valueof(ag.get('SUM')));
            for(quota__c q : quotaList1){
                if(q.Actual_Amount__c != double.valueof(ag.get('SUM'))){
                    q.Actual_Amount__c = double.valueof(ag.get('SUM'));
                    qutoaList.add(q);
                   
                }
            }
        }
        system.debug('oppList-->'+oppList.size());
        return null;
    }
    
    public class FutureClassLimitsTest {

    @future(callout=true)
    public static void docallouts(){
  
        system.debug('qutoaList-->'+qutoaList.size());
        if(qutoaList.size()>0){
            
            update qutoaList;
        }
        
    }
}
User-added image
I have written a VF code to display all opportunity amount on quota amount feild but I am getting the below error

User-added image 

public with sharing class listopponquota {
    public list<Opportunity> oppList{get;set;}
    public list<quota__c> qutoaList{get;set;}
    public set<ID> oppIds = new set<ID>(); 
    
    public class listopponquota implements Queueable, Database.AllowsCallouts {
public void execute(QueueableContext context) {

    public listopponquota()
    {
        String selectedVal ='';
        oppList = new list<Opportunity>();
        qutoaList = new list<quota__c>();
        oppList();
    }
}
    }

    
    public pageReference oppList() {
        Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
        system.debug('Id-->'+qId);    
        List<quota__c> quotaList1 = new List<quota__c>();
        List<Opportunity> oppList1 = new List<Opportunity>();
        
        quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c,Actual_Amount__c, OwnerId from quota__c where Id   =: qId Limit 1];
        oppList1 = [Select Id, Name, CloseDate, StageName,OwnerId,Amount From Opportunity where StageName = 'Closed Won'];
        
        system.debug('quotaList1-->'+quotaList1);
        if(quotaList1.size() > 0){
            for(quota__c q : quotaList1){
                
                for(Opportunity opp : oppList1){
                    system.debug('closedDate-->'+opp.CloseDate);
                    if(opp.CloseDate  >=  q.Start_Date__c  && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId){
                        oppList.add(opp);
                        oppIds.add(opp.id);
                    } 
                }                
            }
        }
        for(aggregateresult ag : [SELECT SUM(Amount) sum FROM Opportunity where ID =:oppIds]){
            system.debug('oppList-->'+double.valueof(ag.get('SUM')));
            for(quota__c q : quotaList1){
                if(q.Actual_Amount__c != double.valueof(ag.get('SUM'))){
                    q.Actual_Amount__c = double.valueof(ag.get('SUM'));
                    qutoaList.add(q);
                     System.enqueueJob(q);
                }
            }
        }
        system.debug('oppList-->'+oppList.size());
        return null;
    }
    
    public void doCallout(){
        system.debug('qutoaList-->'+qutoaList.size());
        if(qutoaList.size()>0){
            update qutoaList;
        }
        
    }
}

Vf

<apex:page controller="listopponquota" lightningStylesheets="true" action="{!doCallout}">
    <apex:form > 
        <apex:pageBlock rendered="true" >
            <apex:pageBlockTable value="{!oppList}" var="v">
                <apex:column value="{!v.OwnerId}"/>
                
                <apex:column headerValue="Opportunity Name">
                    <apex:outputlink value="/{!v.Id}">{!v.Name}</apex:outputlink>
                </apex:column>
                <apex:column value="{!v.CloseDate}"/>
                <apex:column value="{!v.StageName}"/>
                <apex:column value="{!v.Amount}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form> 
</apex:page>
I have written a test class to add all amount on quota which lies between start and end date of quota

I am getting below error

User-added image

Test class
@isTest
public class Test_listopponquota {
    static testMethod void listopponquota(){
        
        Quota__c a = new  Quota__c(Name = 'Test');
        a.Assign_to_User__c = 'Shruthi MN';
        a.Start_Date__c = date.today();
         a.Start_Date__c = date.today() + 12;
        insert a;
        
        
        Opportunity o = new Opportunity();
        o.name = 'Test';
        o.StageName = 'Closed Won';
        o.CloseDate = date.today();
        o.Type = 'New Customers';
        
        insert o;
    }
   
}
apex
public with sharing class listopponquota {
     
    
    public list<Opportunity> oppList{get;set;}
    public list<quota__c> qutoaList{get;set;}
    public set<ID> oppIds = new set<ID>(); 
    
    public listopponquota()
    {
        String selectedVal ='';
        oppList = new list<Opportunity>();
        qutoaList = new list<quota__c>();
        oppList();
    }
    
    public pageReference oppList() {
        Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
        system.debug('Id-->'+qId);    
        List<quota__c> quotaList1 = new List<quota__c>();
        List<Opportunity> oppList1 = new List<Opportunity>();
        
        quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c,Actual_Amount__c, OwnerId from quota__c where Id   =: qId Limit 1];
        oppList1 = [Select Id, Name, CloseDate, StageName,OwnerId,Amount From Opportunity where StageName = 'Closed Won'];
        
        system.debug('quotaList1-->'+quotaList1);
        if(quotaList1.size() > 0){
            for(quota__c q : quotaList1){
                
                for(Opportunity opp : oppList1){
                    system.debug('closedDate-->'+opp.CloseDate);
                    if(opp.CloseDate  >=  q.Start_Date__c  && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId){
                        oppList.add(opp);
                        oppIds.add(opp.id);
                    } 
                }                
            }
        }
        for(aggregateresult ag : [SELECT SUM(Amount) sum FROM Opportunity where ID =:oppIds]){
            system.debug('oppList-->'+double.valueof(ag.get('SUM')));
            for(quota__c q : quotaList1){
                if(q.Actual_Amount__c != double.valueof(ag.get('SUM'))){
                    q.Actual_Amount__c = double.valueof(ag.get('SUM'));
                    qutoaList.add(q);
                     System.enqueueJob(q);
                }
            }
        }
        system.debug('oppList-->'+oppList.size());
        return null;
    }
    
    public void doCallout(){
        system.debug('qutoaList-->'+qutoaList.size());
        if(qutoaList.size()>0){
            update qutoaList;
        }
        
    }
}

Vf

<apex:page controller="listopponquota" lightningStylesheets="true" action="{!doCallout}">
    <apex:form > 
        <apex:pageBlock rendered="true" >
            <apex:pageBlockTable value="{!oppList}" var="v">
                <apex:column value="{!v.OwnerId}"/>
                
                <apex:column headerValue="Opportunity Name">
                    <apex:outputlink value="/{!v.Id}">{!v.Name}</apex:outputlink>
                </apex:column>
                <apex:column value="{!v.CloseDate}"/>
                <apex:column value="{!v.StageName}"/>
                <apex:column value="{!v.Amount}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form> 
</apex:page
Can anyone provide Test class for following use Case.
Consider all positive negative and bulk test case

Use case ::
Collection of Closed Won Opportunities
1. I have created a custom quota object
2. Create a VF page to display all the Closed won opportunities in the org Only if
1)The opportunitys cloased date lies between start and end date of quota
2)The User which is dispalyed in the assed to user should be the same as the owner
3) The record type is BDM

I have written the below test class for the same. I do not know how to write the logic can anyone help me with the same

Apex class

public with sharing class listopponquota {
    
    public list<Opportunity> oppList{get;set;}
    
    public listopponquota()
    {
        String selectedVal ='';
        oppList = new list<Opportunity>();
        oppList();
    }
    
    public pageReference oppList() {
        Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
        system.debug('Id-->'+qId);    
        List<quota__c> quotaList1 = new List<quota__c>();
        List<Opportunity> oppList1 = new List<Opportunity>();
        quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c, OwnerId from quota__c where Id   =: qId Limit 1];
        oppList1 = [Select Id, Name, CloseDate, StageName,OwnerId,Amount From Opportunity where StageName = 'Closed Won'];
        
        system.debug('quotaList1-->'+quotaList1);
        if(quotaList1.size() > 0){
            for(quota__c q : quotaList1){
                
                for(Opportunity opp : oppList1){
                    system.debug('closedDate-->'+opp.CloseDate);
                    if(opp.CloseDate  >=  q.Start_Date__c  && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId){
                        oppList.add(opp);
                    } 
                }                
            }
        }
        system.debug('oppList-->'+oppList);
        return null;
    }
}

Vf page

<apex:page controller="listopponquota" lightningStylesheets="true" >
    <apex:form > 
        <apex:pageBlock rendered="true" >
            <apex:pageBlockTable value="{!oppList}" var="v">
                <apex:column value="{!v.OwnerId}"/>
                
                <apex:column headerValue="Opportunity Name">
                    <apex:outputlink value="/{!v.Id}">{!v.Name}</apex:outputlink>
                </apex:column>
                <apex:column value="{!v.CloseDate}"/>
                <apex:column value="{!v.StageName}"/>
                <apex:column value="{!v.Amount}"/>
                            </apex:pageBlockTable>
            
            
        </apex:pageBlock>
    </apex:form> 
</apex:page>

Test class

@isTest
private class testclassquotaVfpage{
    static testMethod void listopponquota(){ 
        
        Quota__c op = new Quota__c ();
        op.Name = 'test_shruthi';
      
        op.Start_Date__c = Date.newInstance(2020,02,06);
        op.End_Date__c = Date.newInstance(2020,02,19);
        insert op;
        
        
        
    }
}
    Opportunity opp = new Opportunity(Name='test opp', StageName='stage', Probability = 95, CloseDate=system.today());

Opportunity opp = new Opportunity();
        opp.Name = 'test_shruthi';
        
        opp.type = 'New Customer';
        opp.CloseDate = system.today();
        opp.StageName ='Closed Won';
        // add all required fields here
        insert opp;
        



   Database.executeBatch(new ContactWithClosedWonOpportunities());

    Test.stopTest();
}

}



 
Can anyone help me fix the code I am getting the below error

search term must be longer than one character: s
Error is in expression '{!runQuery}' in component <apex:commandButton> in page productsearchpopupcontroller: Class.ProductSearchPopupController.runQuery: line 63, column 1
An unexpected error has occurred. Your development organization has been notified.

global class ProductSearchPopupController {
   
    public String query {get; set;}
    public List<PricebookEntry__c> products {get; set;}
    public List<wrapProduct> wrapProductList {get; set;}
    public List<PricebookEntry__c> selectedProduct{get;set;}
    public List<QuoteLineitem__c> quoteLineList{get;set;}
    public List<wrapProduct> selectedWrapperList{get;set;}
    public Boolean normalList{get;set;}
    public Boolean selectedList{get;set;}
    public Boolean block{get;set;}
    public Boolean block1{get;set;}
    public Boolean block2{get;set;}
    public String SalesPrice {get; set;}
    public integer Discount {get; set;}
    public String Quantity {get; set;}
    public String ServiceDate {get; set;}
    Id recordId;
   
    public ProductSearchPopupController(ApexPages.StandardController controller){
        recordId = controller.getId();
        SalesPrice='';
        Discount=0;
        Quantity='';
        ServiceDate='';
        system.debug('recordId '+recordId);
        wrapProductList = new List<wrapProduct>();
        selectedWrapperList = new List<wrapProduct>();
        normalList = true;
        selectedList = false;
        block = true;
        block1 = false;
        block2 = false;
        
    }
   
     public PageReference runQuery1(){
         
        List<PricebookEntry__c> searchResults=[select id, Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c from PricebookEntry__c];
        if(searchResults.size() >= 0){
            
            for(PricebookEntry__c a: searchResults) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapProductList.add(new wrapProduct(a));
                block = true;
                block1 = true;
                block2 = false;
            }
        }
        return null;
    }
    
    public PageReference runQuery(){
        wrapProductList = new List<wrapProduct>();
        if(query == null || query == ''){
            system.debug('query '+query);
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'Please enter Product to search for'));
               runQuery1();
           
        }

        system.debug('query '+query);
        List<List<PricebookEntry__c>> searchResults=[FIND :query IN ALL FIELDS RETURNING PricebookEntry__c (id, Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c)];
        if(searchResults[0]!=null){
            for(PricebookEntry__c a: searchResults[0]) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapProductList.add(new wrapProduct(a));
                block = true;
                block1 = true;  

                block2 = false;

            }
        }
        return null;
    }
    public PageReference ProceedWithSelectedToNextPage(){
        selectedWrapperList = new List<wrapProduct>();
        normalList = false;
        selectedList = true;
        for(wrapProduct selectedWrapObj: wrapProductList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
                selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
        PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
        pageRef.setRedirect(false);
        return pageRef;
    }
    public void processSelected() {
        selectedProduct = new List<PricebookEntry__c>();
        for(wrapProduct wrapProductObj : wrapProductList) {
            if(wrapProductObj.selected == true) {
                selectedProduct.add(wrapProductObj.acc);
                block = false;
                block1 = false;
                block2 = true;
               
            }
        }
    }
   
    public void GoBack() {
        block = true;
        block1 = true;
        block2 = false;
    }
   
    global class wrapProduct{
        public PricebookEntry__c acc {get;set;}
        public Boolean selected {get;set;}
        public wrapProduct(PricebookEntry__c p) {
            this.acc = p;
            this.selected = false;
        }
       
    }
   
    public pagereference saveproduct(){
        List<QuoteLineitem__c> quoteLineList = new  List<QuoteLineitem__c>();
         if(Test.isRunningTest()){
            insertTestData();
        }
        if(!selectedProduct.isEmpty()){
            for(PricebookEntry__c sp:selectedProduct){
                system.debug('sp '+sp);
                QuoteLineitem__c qli = new QuoteLineitem__c();
                qli.QuotesId__c = recordId;
                qli.ListPrice__c = sp.UnitPrice__c;
                qli.UnitPrice__c = sp.UnitPrice__c;
                qli.Product2Id__c = sp.Product2Id__c;    
                if(Discount!=0 || Discount!=null){
                    qli.Discount__c = Discount;
                }
                if(Quantity!=null){
                    qli.Quantity__c = Decimal.valueof(Quantity);
                }
                quoteLineList.add(qli);
            }
            
           
            if(quoteLineList.size() > 0){
                insert quoteLineList;
                PageReference pageRef = new PageReference('https://proseraa.lightning.force.com/lightning/r/Quotes__c/'+recordId+'/view');
                pageRef.setRedirect(true);
                return pageRef;
            }
        }
        return null;
    }
    public void insertTestData(){
        Product2__c testProduct = new Product2__c();
            testProduct.Name='Test product';
            insert testProduct;
            PricebookEntry__c testpbe = new PricebookEntry__c();
                testpbe.Name='Test PriceBookEntry';
                testpbe.UnitPrice__c =123;
                testpbe.Product2Id__c=testProduct.Id;
                insert testpbe;
            selectedProduct.add(testpbe);
    }
    
}
I written a code to add products on quoteline items. I want to display error message when a single letter is added. Can anyone correct the code.
'search term must be longer than one character: s'.

global class ProductSearchPopupController {
   
    public String query {get; set;}
    public List<PricebookEntry__c> products {get; set;}
    public List<wrapProduct> wrapProductList {get; set;}
    public List<PricebookEntry__c> selectedProduct{get;set;}
    public List<QuoteLineitem__c> quoteLineList{get;set;}
    public List<wrapProduct> selectedWrapperList{get;set;}
    public Boolean normalList{get;set;}
    public Boolean selectedList{get;set;}
    public Boolean block{get;set;}
    public Boolean block1{get;set;}
    public Boolean block2{get;set;}
    public String SalesPrice {get; set;}
    public integer Discount {get; set;}
    public String Quantity {get; set;}
    public String ServiceDate {get; set;}
    Id recordId;
   
    public ProductSearchPopupController(ApexPages.StandardController controller){
        recordId = controller.getId();
        SalesPrice='';
        Discount=0;
        Quantity='';
        ServiceDate='';
        system.debug('recordId '+recordId);
        wrapProductList = new List<wrapProduct>();
        selectedWrapperList = new List<wrapProduct>();
        normalList = true;
        selectedList = false;
        block = true;
        block1 = false;
        block2 = false;
        
    }
   
     public PageReference runQuery1(){
         
        List<PricebookEntry__c> searchResults=[select id, Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c from PricebookEntry__c];
        if(searchResults.size()>= 0 ){
            
            for(PricebookEntry__c a: searchResults) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapProductList.add(new wrapProduct(a));
                block = true;
                block1 = true;
                block2 = false;
            }
        }
        return null;
    }
    
    public PageReference runQuery(){
        wrapProductList = new List<wrapProduct>();
        if(query == null || query == ''){
            system.debug('query '+query);
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'Please enter Product to search for'));
               runQuery1();
           else if (searchText.length()<2)
 {
 Apexpages.addMessage(new Apexpages.Message(ApexPages.severity.INFO, 'Input box must contain at least two characters')); 
 }
        }

        system.debug('query '+query);
        
        List<List<PricebookEntry__c>> searchResults=[FIND :query IN ALL FIELDS RETURNING PricebookEntry__c (id, Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c)];
        if(searchResults[0]!=null){
            for(PricebookEntry__c a: searchResults[0]) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapProductList.add(new wrapProduct(a));
                block = true;
                block1 = true;  
                block2 = false;

            }
        }
        return null;
    }
    public PageReference ProceedWithSelectedToNextPage(){
        selectedWrapperList = new List<wrapProduct>();
        normalList = false;
        selectedList = true;
        for(wrapProduct selectedWrapObj: wrapProductList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
                selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
        PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
        pageRef.setRedirect(false);
        return pageRef;
    }
    public void processSelected() {
        selectedProduct = new List<PricebookEntry__c>();
        for(wrapProduct wrapProductObj : wrapProductList) {
            if(wrapProductObj.selected == true) {
                selectedProduct.add(wrapProductObj.acc);
                block = false;
                block1 = false;
                block2 = true;
               
            }
        }
    }
   
    public void GoBack() {
        block = true;
        block1 = true;
        block2 = false;
    }
   
    global class wrapProduct{
        public PricebookEntry__c acc {get;set;}
        public Boolean selected {get;set;}
        public wrapProduct(PricebookEntry__c p) {
            this.acc = p;
            this.selected = false;
        }
       
    }
   
    public pagereference saveproduct(){
        List<QuoteLineitem__c> quoteLineList = new  List<QuoteLineitem__c>();
         if(Test.isRunningTest()){
            insertTestData();
        }
        if(!selectedProduct.isEmpty()){
            for(PricebookEntry__c sp:selectedProduct){
                system.debug('sp '+sp);
                QuoteLineitem__c qli = new QuoteLineitem__c();
                qli.QuotesId__c = recordId;
                qli.ListPrice__c = sp.UnitPrice__c;
                qli.UnitPrice__c = sp.UnitPrice__c;
                qli.Product2Id__c = sp.Product2Id__c;    
                if(Discount!=0 || Discount!=null){
                    qli.Discount__c = Discount;
                }
                if(Quantity!=null){
                    qli.Quantity__c = Decimal.valueof(Quantity);
                }
                quoteLineList.add(qli);
            }
            
           
            if(quoteLineList.size() > 0){
                insert quoteLineList;
                PageReference pageRef = new PageReference('https://proseraa.lightning.force.com/lightning/r/Quotes__c/'+recordId+'/view');
                pageRef.setRedirect(true);
                return pageRef;
            }
        }
        return null;
    }
    public void insertTestData(){
        Product2__c testProduct = new Product2__c();
            testProduct.Name='Test product';
            insert testProduct;
            PricebookEntry__c testpbe = new PricebookEntry__c();
                testpbe.Name='Test PriceBookEntry';
                testpbe.UnitPrice__c =123;
                testpbe.Product2Id__c=testProduct.Id;
                insert testpbe;
            selectedProduct.add(testpbe);
    }
    
}

VF

<apex:page standardController="Quotes__c" extensions="ProductSearchPopupController" showHeader="false" sidebar="false" lightningStylesheets="true">
   
    <apex:form id="form" >
        <apex:pageMessages ></apex:pageMessages>
        
        <div style="width 100%">
            <apex:pageBlock title="Add Products" id="block" rendered="{!block}"> 
                <centre>
                    <div align="center"  >
                   <apex:pageBlockSection columns="1" id="section" > 
                        Enter the product to be added and select Go<br/>
                        
                        <apex:inputText value="{!query}" id="query" style="width: 1200px; height: 40px;"/> 
                    </apex:pageBlockSection> 
                  </div>
                </centre>
                <right>
                <apex:commandButton value="Go" action="{!runQuery}" style="align: right:100px;border-style:solid;
                     color:white; position:relative;background-color:rgba(13, 112, 165, 1);"/>
                <apex:commandButton value="Cancel" action="{!cancel}" style="float: centre:200px ;border-style:solid;
                     color:rgb(21, 137, 238); background-color:white;" />
                      </right>
            </apex:pageBlock>
                
            <apex:pageBlock id="block1" rendered="{!block1}" >
                <apex:pageBlockSection columns="1">
                    <apex:pageBlockTable value="{!wrapProductList}" var="accWrap">
                        <apex:column >
                            <apex:facet name="header">
                                <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                            </apex:facet>
                            <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                        </apex:column>
                        <apex:column headerValue="Name">
                            <apex:outputLink value="#">{!accWrap.acc.Name}</apex:outputLink>       
                        </apex:column>
                        <apex:column headerValue="Product Code">
                            <apex:outputText value="{!accWrap.acc.ProductCode__c}"  />       
                        </apex:column>
                        <apex:column headerValue="Product Description">
                            <apex:outputText value="{!accWrap.acc.Product2Id__r.Product_Description__c}"  />       
                        </apex:column>
                        <apex:column headerValue="Unit Price">
                            <apex:outputText value="{!accWrap.acc.UnitPrice__c}"  />  
                        </apex:column>
                        <apex:column headerValue="Standard Price">
                            <apex:outputText value="{!accWrap.acc.UseStandardPrice__c}"  />  
                        </apex:column>
                    </apex:pageBlockTable>  
                    <apex:commandButton value="Next"   action="{!processSelected}" style="float: right;border-style:solid;
                     color:white; background-color:rgba(13, 112, 165, 1);align-items: right;justify-content:right;"/>  
                </apex:pageBlockSection>
            </apex:pageBlock>
        </div>
        <div>
            <apex:pageBlock id="block2" rendered="{!block2}" >
                <apex:pageblockSection title="All Products" collapsible="false" columns="3">
                    <apex:pageBlockTable value="{!selectedProduct}" var="c" id="table2" title="Selected Products">
                        <apex:column value="{!c.Name}" headerValue="Product Name"/>
                        <apex:column headerValue="Sales Price">
                            <apex:inputText value="{!c.UnitPrice__c}" id="UnitPrice" /> 
                        </apex:column>
                        <apex:column headerValue="Discount">
                            <apex:inputText value="{!discount}" id="discount" /> 
                        </apex:column>
                        <apex:column headerValue="Quantity">
                            <apex:inputText value="{!quantity}" id="quantity" /> 
                        </apex:column>
                    </apex:pageBlockTable>  
                </apex:pageblockSection>
                <apex:commandButton action="{!GoBack}" value="Back" style="border-style:solid;
                     color:white; background-color:rgba(13, 112, 165, 1);"/>
                <apex:commandButton action="{!saveproduct}" value="Save" style="float: right;border-style:solid;
                     color:white; background-color:rgba(13, 112, 165, 1);"/>
                <apex:commandButton value="Cancel"  action="{!cancel}" style="float: right;border-style:solid;
                     color:rgb(21, 137, 238); background-color:white;"/>           
            </apex:pageBlock>
            </div>
           
        
    </apex:form>
</apex:page>


 
I am trying to add error message 

global class ProductSearchPopupController {
   
    public String query {get; set;}
    public List<PricebookEntry__c> products {get; set;}
    public List<wrapProduct> wrapProductList {get; set;}
    public List<PricebookEntry__c> selectedProduct{get;set;}
    public List<QuoteLineitem__c> quoteLineList{get;set;}
    public List<wrapProduct> selectedWrapperList{get;set;}
    public Boolean normalList{get;set;}
    public Boolean selectedList{get;set;}
    public Boolean block{get;set;}
    public Boolean block1{get;set;}
    public Boolean block2{get;set;}
    public String SalesPrice {get; set;}
    public integer Discount {get; set;}
    public String Quantity {get; set;}
    public String ServiceDate {get; set;}
    Id recordId;
   
    public ProductSearchPopupController(ApexPages.StandardController controller){
        recordId = controller.getId();
        SalesPrice='';
        Discount=0;
        Quantity='';
        ServiceDate='';
        system.debug('recordId '+recordId);
        wrapProductList = new List<wrapProduct>();
        selectedWrapperList = new List<wrapProduct>();
        normalList = true;
        selectedList = false;
        block = true;
        block1 = false;
        block2 = false;
        
    }
   
     public PageReference runQuery1(){
         
        List<PricebookEntry__c> searchResults=[select id, Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c from PricebookEntry__c];
        if(searchResults.size()>= 0 ){
            
            for(PricebookEntry__c a: searchResults) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapProductList.add(new wrapProduct(a));
                block = true;
                block1 = true;
                block2 = false;
            }
        }
        return null;
    }
    
    public PageReference runQuery(){
        wrapProductList = new List<wrapProduct>();
        if(query == null || query == ''){
            system.debug('query '+query);
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'Please enter Product to search for'));
               runQuery1();
           else if (searchText.length()<2)
 {
 Apexpages.addMessage(new Apexpages.Message(ApexPages.severity.INFO, 'Input box must contain at least two characters')); 
 }
        }

        system.debug('query '+query);
        List<List<PricebookEntry__c>> searchResults=[FIND :query IN ALL FIELDS RETURNING PricebookEntry__c (id, Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c)];
        if(searchResults[0]!=null){
            for(PricebookEntry__c a: searchResults[0]) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapProductList.add(new wrapProduct(a));
                block = true;
                block1 = true;  
                block2 = false;

            }
        }
        return null;
    }
    public PageReference ProceedWithSelectedToNextPage(){
        selectedWrapperList = new List<wrapProduct>();
        normalList = false;
        selectedList = true;
        for(wrapProduct selectedWrapObj: wrapProductList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
                selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
        PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
        pageRef.setRedirect(false);
        return pageRef;
    }
    public void processSelected() {
        selectedProduct = new List<PricebookEntry__c>();
        for(wrapProduct wrapProductObj : wrapProductList) {
            if(wrapProductObj.selected == true) {
                selectedProduct.add(wrapProductObj.acc);
                block = false;
                block1 = false;
                block2 = true;
               
            }
        }
    }
   
    public void GoBack() {
        block = true;
        block1 = true;
        block2 = false;
    }
   
    global class wrapProduct{
        public PricebookEntry__c acc {get;set;}
        public Boolean selected {get;set;}
        public wrapProduct(PricebookEntry__c p) {
            this.acc = p;
            this.selected = false;
        }
       
    }
   
    public pagereference saveproduct(){
        List<QuoteLineitem__c> quoteLineList = new  List<QuoteLineitem__c>();
         if(Test.isRunningTest()){
            insertTestData();
        }
        if(!selectedProduct.isEmpty()){
            for(PricebookEntry__c sp:selectedProduct){
                system.debug('sp '+sp);
                QuoteLineitem__c qli = new QuoteLineitem__c();
                qli.QuotesId__c = recordId;
                qli.ListPrice__c = sp.UnitPrice__c;
                qli.UnitPrice__c = sp.UnitPrice__c;
                qli.Product2Id__c = sp.Product2Id__c;    
                if(Discount!=0 || Discount!=null){
                    qli.Discount__c = Discount;
                }
                if(Quantity!=null){
                    qli.Quantity__c = Decimal.valueof(Quantity);
                }
                quoteLineList.add(qli);
            }
            
           
            if(quoteLineList.size() > 0){
                insert quoteLineList;
                PageReference pageRef = new PageReference('https://proseraa.lightning.force.com/lightning/r/Quotes__c/'+recordId+'/view');
                pageRef.setRedirect(true);
                return pageRef;
            }
        }
        return null;
    }
    public void insertTestData(){
        Product2__c testProduct = new Product2__c();
            testProduct.Name='Test product';
            insert testProduct;
            PricebookEntry__c testpbe = new PricebookEntry__c();
                testpbe.Name='Test PriceBookEntry';
                testpbe.UnitPrice__c =123;
                testpbe.Product2Id__c=testProduct.Id;
                insert testpbe;
            selectedProduct.add(testpbe);
    }
    
}
Hi

I am getting this error message if I add single letter for search. 'search term must be longer than one character: s
Error is in expression '{!runQuery}' in component <apex:commandButton> in page productsearchpopupcontroller: Class.ProductSearchPopupController.runQuery: line 63, column 1'

Below is the apex controller

global class ProductSearchPopupController {
   
    public String query {get; set;}
    public List<PricebookEntry__c> products {get; set;}
    public List<wrapProduct> wrapProductList {get; set;}
    public List<PricebookEntry__c> selectedProduct{get;set;}
    public List<QuoteLineitem__c> quoteLineList{get;set;}
    public List<wrapProduct> selectedWrapperList{get;set;}
    public Boolean normalList{get;set;}
    public Boolean selectedList{get;set;}
    public Boolean block{get;set;}
    public Boolean block1{get;set;}
    public Boolean block2{get;set;}
    public String SalesPrice {get; set;}
    public integer Discount {get; set;}
    public String Quantity {get; set;}
    public String ServiceDate {get; set;}
    Id recordId;
   
    public ProductSearchPopupController(ApexPages.StandardController controller){
        recordId = controller.getId();
        SalesPrice='';
        Discount=0;
        Quantity='';
        ServiceDate='';
        system.debug('recordId '+recordId);
        wrapProductList = new List<wrapProduct>();
        selectedWrapperList = new List<wrapProduct>();
        normalList = true;
        selectedList = false;
        block = true;
        block1 = false;
        block2 = false;
        
    }
   
     public PageReference runQuery1(){
         
        List<PricebookEntry__c> searchResults=[select id, Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c from PricebookEntry__c];
        if(searchResults.size()>= 0 ){
            
            for(PricebookEntry__c a: searchResults) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapProductList.add(new wrapProduct(a));
                block = true;
                block1 = true;
                block2 = false;
            }
        }
        return null;
    }
    
    public PageReference runQuery(){
         if(Test.isRunningTest()){
            query='Test';
        }
        wrapProductList = new List<wrapProduct>();
        if(query == null || query == ''){
            system.debug('query '+query);
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'Please enter Product to search for'));
               runQuery1();
            return null;
        }

        system.debug('query '+query);
        List<List<PricebookEntry__c>> searchResults=[FIND :query IN ALL FIELDS RETURNING PricebookEntry__c (id, Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c)];
        if(searchResults[0]!=null){
            for(PricebookEntry__c a: searchResults[0]) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapProductList.add(new wrapProduct(a));
                block = true;
                block1 = true;
                block2 = false;
            }
        }
        return null;
    }
    public PageReference ProceedWithSelectedToNextPage(){
        selectedWrapperList = new List<wrapProduct>();
        normalList = false;
        selectedList = true;
        for(wrapProduct selectedWrapObj: wrapProductList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
                selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
        PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
        pageRef.setRedirect(false);
        return pageRef;
    }
    public void processSelected() {
        selectedProduct = new List<PricebookEntry__c>();
        for(wrapProduct wrapProductObj : wrapProductList) {
            if(wrapProductObj.selected == true) {
                selectedProduct.add(wrapProductObj.acc);
                block = false;
                block1 = false;
                block2 = true;
               
            }
        }
    }
   
    public void GoBack() {
        block = true;
        block1 = true;
        block2 = false;
    }
   
    global class wrapProduct{
        public PricebookEntry__c acc {get;set;}
        public Boolean selected {get;set;}
        public wrapProduct(PricebookEntry__c p) {
            this.acc = p;
            this.selected = false;
        }
       
    }
   
    public pagereference saveproduct(){
        List<QuoteLineitem__c> quoteLineList = new  List<QuoteLineitem__c>();
        if(!selectedProduct.isEmpty()){
            for(PricebookEntry__c sp:selectedProduct){
                system.debug('sp '+sp);
                QuoteLineitem__c qli = new QuoteLineitem__c();
                qli.QuotesId__c = recordId;
                qli.ListPrice__c = sp.UnitPrice__c;
                qli.UnitPrice__c = sp.UnitPrice__c;
                qli.Product2Id__c = sp.Product2Id__c;    
                if(Discount!=0 || Discount!=null){
                    qli.Discount__c = Discount;
                }
                if(Quantity!=null){
                    qli.Quantity__c = Decimal.valueof(Quantity);
                }
                quoteLineList.add(qli);
            }
            
           
            if(quoteLineList.size() > 0){
                insert quoteLineList;
                PageReference pageRef = new PageReference('https://proseraa.lightning.force.com/lightning/r/Quotes__c/'+recordId+'/view');
                pageRef.setRedirect(true);
                return pageRef;
            }
        }
        return null;
    }
    
    
}

Below is the VF Code


<apex:page standardController="Quotes__c" extensions="ProductSearchPopupController" showHeader="false" sidebar="false" lightningStylesheets="true">
   
    <apex:form id="form" >
        <apex:pageMessages ></apex:pageMessages>
        
        <div style="width 100%">
            <apex:pageBlock title="Add Products" id="block" rendered="{!block}"> 
                <centre>
                    <div align="center"  >
                   <apex:pageBlockSection columns="1" id="section" > 
                        Enter the product to be added and select Go<br/>
                        
                        <apex:inputText value="{!query}" id="query" style="width: 1200px; height: 40px;"/> 
                    </apex:pageBlockSection> 
                  </div>
                </centre>
                <right>
                <apex:commandButton value="Go" action="{!runQuery}" style="align: right:100px;border-style:solid;
                     color:white; position:relative;background-color:rgba(13, 112, 165, 1);"/>
                <apex:commandButton value="Cancel" action="{!cancel}" style="float: centre:200px ;border-style:solid;
                     color:rgb(21, 137, 238); background-color:white;" />
                      </right>
            </apex:pageBlock>
                
            <apex:pageBlock id="block1" rendered="{!block1}" >
                <apex:pageBlockSection columns="1">
                    <apex:pageBlockTable value="{!wrapProductList}" var="accWrap">
                        <apex:column >
                            <apex:facet name="header">
                                <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                            </apex:facet>
                            <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                        </apex:column>
                        <apex:column headerValue="Name">
                            <apex:outputLink value="#">{!accWrap.acc.Name}</apex:outputLink>       
                        </apex:column>
                        <apex:column headerValue="Product Code">
                            <apex:outputText value="{!accWrap.acc.ProductCode__c}"  />       
                        </apex:column>
                        <apex:column headerValue="Product Description">
                            <apex:outputText value="{!accWrap.acc.Product2Id__r.Product_Description__c}"  />       
                        </apex:column>
                        <apex:column headerValue="Unit Price">
                            <apex:outputText value="{!accWrap.acc.UnitPrice__c}"  />  
                        </apex:column>
                        <apex:column headerValue="Standard Price">
                            <apex:outputText value="{!accWrap.acc.UseStandardPrice__c}"  />  
                        </apex:column>
                    </apex:pageBlockTable>  
                    <apex:commandButton value="Next"   action="{!processSelected}" style="float: right;border-style:solid;
                     color:white; background-color:rgba(13, 112, 165, 1);align-items: right;justify-content:right;"/>  
                </apex:pageBlockSection>
            </apex:pageBlock>
        </div>
        <div>
            <apex:pageBlock id="block2" rendered="{!block2}" >
                <apex:pageblockSection title="All Products" collapsible="false" columns="3">
                    <apex:pageBlockTable value="{!selectedProduct}" var="c" id="table2" title="Selected Products">
                        <apex:column value="{!c.Name}" headerValue="Product Name"/>
                        <apex:column headerValue="Sales Price">
                            <apex:inputText value="{!c.UnitPrice__c}" id="UnitPrice" /> 
                        </apex:column>
                        <apex:column headerValue="Discount">
                            <apex:inputText value="{!discount}" id="discount" /> 
                        </apex:column>
                        <apex:column headerValue="Quantity">
                            <apex:inputText value="{!quantity}" id="quantity" /> 
                        </apex:column>
                    </apex:pageBlockTable>  
                </apex:pageblockSection>
                <apex:commandButton action="{!GoBack}" value="Back" style="border-style:solid;
                     color:white; background-color:rgba(13, 112, 165, 1);"/>
                <apex:commandButton action="{!saveproduct}" value="Save" style="float: right;border-style:solid;
                     color:white; background-color:rgba(13, 112, 165, 1);"/>
                <apex:commandButton value="Cancel"  action="{!cancel}" style="float: right;border-style:solid;
                     color:rgb(21, 137, 238); background-color:white;"/>           
            </apex:pageBlock>
            </div>
           
        
    </apex:form>
</apex:page>
Can anyone help me in aligning the buttons to right

<apex:page standardController="Quotes__c" extensions="ProductSearchPopupController" showHeader="false" sidebar="false" lightningStylesheets="true">
   
    <apex:form id="form" >
        <apex:pageMessages ></apex:pageMessages>
        <apex:messages />
        <div style="width 100%">
            <apex:pageBlock title="Add Products" id="block" rendered="{!block}"> 
                <centre>
                    <div align="center"  >
                    <apex:pageBlockSection columns="1" id="section" > 
                        Enter the product to be added and select Go<br/>
                        
                        <apex:inputText value="{!query}" id="query"/> 
                    </apex:pageBlockSection> 
                  </div>
                </centre>
                <right>
                <apex:commandButton value="Go" action="{!runQuery}" style="border-style:solid;
                     color:white; class:centre;background-color:rgba(13, 112, 165, 1);style=float:right;"/>
                <apex:commandButton value="Cancel" action="{!cancel}" style="border-style:solid;
                     color:rgb(21, 137, 238); background-color:white;" />
                      </right>
            </apex:pageBlock>
                
            <apex:pageBlock id="block1" rendered="{!block1}" >
                <apex:pageBlockSection columns="1">
                    <apex:pageBlockTable value="{!wrapProductList}" var="accWrap">
                        <apex:column >
                            <apex:facet name="header">
                                <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                            </apex:facet>
                            <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                        </apex:column>
                        <apex:column headerValue="Name">
                            <apex:outputLink value="#">{!accWrap.acc.Name}</apex:outputLink>       
                        </apex:column>
                        <apex:column headerValue="Product Code">
                            <apex:outputText value="{!accWrap.acc.ProductCode__c}"  />       
                        </apex:column>
                        <apex:column headerValue="Product Description">
                            <apex:outputText value="{!accWrap.acc.Product2Id__r.Product_Description__c}"  />       
                        </apex:column>
                        <apex:column headerValue="Unit Price">
                            <apex:outputText value="{!accWrap.acc.UnitPrice__c}"  />  
                        </apex:column>
                        <apex:column headerValue="Standard Price">
                            <apex:outputText value="{!accWrap.acc.UseStandardPrice__c}"  />  
                        </apex:column>
                    </apex:pageBlockTable>  
                    <apex:commandButton value="Next"   action="{!processSelected}" style="border-style:solid;
                     color:white; background-color:rgba(13, 112, 165, 1);align-items: right;justify-content:right;"/>  
                </apex:pageBlockSection>
            </apex:pageBlock>
        </div>
        <div>
            <apex:pageBlock id="block2" rendered="{!block2}" >
                <apex:pageblockSection title="All Products" collapsible="false" columns="3">
                    <apex:pageBlockTable value="{!selectedProduct}" var="c" id="table2" title="Selected Products">
                        <apex:column value="{!c.Name}" headerValue="Product Name"/>
                        <apex:column headerValue="Sales Price">
                            <apex:inputText value="{!c.UnitPrice__c}" id="UnitPrice" /> 
                        </apex:column>
                        <apex:column headerValue="Discount">
                            <apex:inputText value="{!discount}" id="discount" /> 
                        </apex:column>
                        <apex:column headerValue="Quantity">
                            <apex:inputText value="{!quantity}" id="quantity" /> 
                        </apex:column>
                    </apex:pageBlockTable>  
                </apex:pageblockSection>
                <apex:commandButton action="{!GoBack}" value="Back" style="border-style:solid;
                     color:white; background-color:rgba(13, 112, 165, 1);"/>
                <apex:commandButton action="{!saveproduct}" value="Save" style="border-style:solid;
                     color:white; background-color:rgba(13, 112, 165, 1);"/>
                <apex:commandButton value="Cancel" oncomplete="doRedirect()" style="border-style:solid;
                     color:rgb(21, 137, 238); background-color:white;"/>           
            </apex:pageBlock>
            </div>
           
        
    </apex:form>
</apex:page>
I have written the below code to update bulk records to add all opportunity amount on quota object. Since it is a bulk record I have used asynchronous bulk update records.


public with sharing class listopponquota {
     public list<Opportunity> oppList{get;set;}
    public list<quota__c> qutoaList{get;set;}
    public set<ID> oppIds = new set<ID>(); 
 
public void listopponquota()
    {
        String selectedVal ='';
        oppList = new list<Opportunity>();
        qutoaList = new list<quota__c>();
        oppList();
    }
    
    
    
    public pageReference oppList() {
        Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
        system.debug('Id-->'+qId);    
        List<quota__c> quotaList1 = new List<quota__c>();
        List<Opportunity> oppList1 = new List<Opportunity>();
        
        quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c,Actual_Amount__c, OwnerId from quota__c where Id   =: qId Limit 1];
        oppList1 = [Select Id, Name, CloseDate, StageName,OwnerId,Amount From Opportunity where StageName = 'Closed Won'];
        
        system.debug('quotaList1-->'+quotaList1);
        if(quotaList1.size() > 0){
            for(quota__c q : quotaList1){
                
                for(Opportunity opp : oppList1){
                    system.debug('closedDate-->'+opp.CloseDate);
                    if(opp.CloseDate  >=  q.Start_Date__c  && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId){
                        oppList.add(opp);
                        oppIds.add(opp.id);
                    } 
                }                
            }
        }
        for(aggregateresult ag : [SELECT SUM(Amount) sum FROM Opportunity where ID =:oppIds]){
            system.debug('oppList-->'+double.valueof(ag.get('SUM')));
            for(quota__c q : quotaList1){
                if(q.Actual_Amount__c != double.valueof(ag.get('SUM'))){
                    q.Actual_Amount__c = double.valueof(ag.get('SUM'));
                    qutoaList.add(q);
                   
                }
            }
        }
        system.debug('oppList-->'+oppList.size());
        return null;
    }
    
    public class FutureClassLimitsTest {

    @future(callout=true)
    public static void docallouts(){
  
        system.debug('qutoaList-->'+qutoaList.size());
        if(qutoaList.size()>0){
            
            update qutoaList;
        }
        
    }
}
User-added image
I have written a test class to add all amount on quota which lies between start and end date of quota

I am getting below error

User-added image

Test class
@isTest
public class Test_listopponquota {
    static testMethod void listopponquota(){
        
        Quota__c a = new  Quota__c(Name = 'Test');
        a.Assign_to_User__c = 'Shruthi MN';
        a.Start_Date__c = date.today();
         a.Start_Date__c = date.today() + 12;
        insert a;
        
        
        Opportunity o = new Opportunity();
        o.name = 'Test';
        o.StageName = 'Closed Won';
        o.CloseDate = date.today();
        o.Type = 'New Customers';
        
        insert o;
    }
   
}
apex
public with sharing class listopponquota {
     
    
    public list<Opportunity> oppList{get;set;}
    public list<quota__c> qutoaList{get;set;}
    public set<ID> oppIds = new set<ID>(); 
    
    public listopponquota()
    {
        String selectedVal ='';
        oppList = new list<Opportunity>();
        qutoaList = new list<quota__c>();
        oppList();
    }
    
    public pageReference oppList() {
        Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
        system.debug('Id-->'+qId);    
        List<quota__c> quotaList1 = new List<quota__c>();
        List<Opportunity> oppList1 = new List<Opportunity>();
        
        quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c,Actual_Amount__c, OwnerId from quota__c where Id   =: qId Limit 1];
        oppList1 = [Select Id, Name, CloseDate, StageName,OwnerId,Amount From Opportunity where StageName = 'Closed Won'];
        
        system.debug('quotaList1-->'+quotaList1);
        if(quotaList1.size() > 0){
            for(quota__c q : quotaList1){
                
                for(Opportunity opp : oppList1){
                    system.debug('closedDate-->'+opp.CloseDate);
                    if(opp.CloseDate  >=  q.Start_Date__c  && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId){
                        oppList.add(opp);
                        oppIds.add(opp.id);
                    } 
                }                
            }
        }
        for(aggregateresult ag : [SELECT SUM(Amount) sum FROM Opportunity where ID =:oppIds]){
            system.debug('oppList-->'+double.valueof(ag.get('SUM')));
            for(quota__c q : quotaList1){
                if(q.Actual_Amount__c != double.valueof(ag.get('SUM'))){
                    q.Actual_Amount__c = double.valueof(ag.get('SUM'));
                    qutoaList.add(q);
                     System.enqueueJob(q);
                }
            }
        }
        system.debug('oppList-->'+oppList.size());
        return null;
    }
    
    public void doCallout(){
        system.debug('qutoaList-->'+qutoaList.size());
        if(qutoaList.size()>0){
            update qutoaList;
        }
        
    }
}

Vf

<apex:page controller="listopponquota" lightningStylesheets="true" action="{!doCallout}">
    <apex:form > 
        <apex:pageBlock rendered="true" >
            <apex:pageBlockTable value="{!oppList}" var="v">
                <apex:column value="{!v.OwnerId}"/>
                
                <apex:column headerValue="Opportunity Name">
                    <apex:outputlink value="/{!v.Id}">{!v.Name}</apex:outputlink>
                </apex:column>
                <apex:column value="{!v.CloseDate}"/>
                <apex:column value="{!v.StageName}"/>
                <apex:column value="{!v.Amount}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form> 
</apex:page
Can anyone provide Test class for following use Case.
Consider all positive negative and bulk test case

Use case ::
Collection of Closed Won Opportunities
1. I have created a custom quota object
2. Create a VF page to display all the Closed won opportunities in the org Only if
1)The opportunitys cloased date lies between start and end date of quota
2)The User which is dispalyed in the assed to user should be the same as the owner
3) The record type is BDM

I have written the below test class for the same. I do not know how to write the logic can anyone help me with the same

Apex class

public with sharing class listopponquota {
    
    public list<Opportunity> oppList{get;set;}
    
    public listopponquota()
    {
        String selectedVal ='';
        oppList = new list<Opportunity>();
        oppList();
    }
    
    public pageReference oppList() {
        Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
        system.debug('Id-->'+qId);    
        List<quota__c> quotaList1 = new List<quota__c>();
        List<Opportunity> oppList1 = new List<Opportunity>();
        quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c, OwnerId from quota__c where Id   =: qId Limit 1];
        oppList1 = [Select Id, Name, CloseDate, StageName,OwnerId,Amount From Opportunity where StageName = 'Closed Won'];
        
        system.debug('quotaList1-->'+quotaList1);
        if(quotaList1.size() > 0){
            for(quota__c q : quotaList1){
                
                for(Opportunity opp : oppList1){
                    system.debug('closedDate-->'+opp.CloseDate);
                    if(opp.CloseDate  >=  q.Start_Date__c  && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId){
                        oppList.add(opp);
                    } 
                }                
            }
        }
        system.debug('oppList-->'+oppList);
        return null;
    }
}

Vf page

<apex:page controller="listopponquota" lightningStylesheets="true" >
    <apex:form > 
        <apex:pageBlock rendered="true" >
            <apex:pageBlockTable value="{!oppList}" var="v">
                <apex:column value="{!v.OwnerId}"/>
                
                <apex:column headerValue="Opportunity Name">
                    <apex:outputlink value="/{!v.Id}">{!v.Name}</apex:outputlink>
                </apex:column>
                <apex:column value="{!v.CloseDate}"/>
                <apex:column value="{!v.StageName}"/>
                <apex:column value="{!v.Amount}"/>
                            </apex:pageBlockTable>
            
            
        </apex:pageBlock>
    </apex:form> 
</apex:page>

Test class

@isTest
private class testclassquotaVfpage{
    static testMethod void listopponquota(){ 
        
        Quota__c op = new Quota__c ();
        op.Name = 'test_shruthi';
      
        op.Start_Date__c = Date.newInstance(2020,02,06);
        op.End_Date__c = Date.newInstance(2020,02,19);
        insert op;
        
        
        
    }
}
    Opportunity opp = new Opportunity(Name='test opp', StageName='stage', Probability = 95, CloseDate=system.today());

Opportunity opp = new Opportunity();
        opp.Name = 'test_shruthi';
        
        opp.type = 'New Customer';
        opp.CloseDate = system.today();
        opp.StageName ='Closed Won';
        // add all required fields here
        insert opp;
        



   Database.executeBatch(new ContactWithClosedWonOpportunities());

    Test.stopTest();
}

}



 

I have designed a vf page for search and add products . I have wriiten error message if a user selects go as please enter the product name. Now I want to add one more validation as 'invalid entry' in they enter anything other the the existing prdocut name. Can you help me with the if else statement and correct the code. I an new to developement.

Below is the controller class
public class ProductSearchPopupController {
   
    public String query {get; set;}
    public List<PricebookEntry__c> products {get; set;}
    public List<wrapProduct> wrapProductList {get; set;}
    public List<PricebookEntry__c> selectedProduct{get;set;}
    public List<QuoteLineitem__c> quoteLineList{get;set;}
    public List<wrapProduct> selectedWrapperList{get;set;}
    public Boolean normalList{get;set;}
    public Boolean selectedList{get;set;}
    public Boolean block{get;set;}
    public Boolean block1{get;set;}
    public Boolean block2{get;set;}
    public String SalesPrice {get; set;}
    public integer Discount {get; set;}
    public String Quantity {get; set;}
    public String ServiceDate {get; set;}
    Id recordId;
   
    public ProductSearchPopupController(ApexPages.StandardController controller){
        recordId = controller.getId();
        system.debug('recordId '+recordId);
        wrapProductList = new List<wrapProduct>();
        selectedWrapperList = new List<wrapProduct>();
        normalList = true;
        selectedList = false;
        block = true;
        block1 = false;
        block2 = false;
    }
    public PageReference runQuery(){
        if(query == null || query == ''){
            system.debug('query '+query);
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'Please enter Product to search for'));
           
            return null;
        }
       
        system.debug('query '+query);
    

        List<List<PricebookEntry__c>> searchResults=[FIND :query IN ALL FIELDS RETURNING PricebookEntry__c (id, Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c)];
        if(searchResults[0]!=null){
            for(PricebookEntry__c a: searchResults[0]) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapProductList.add(new wrapProduct(a));
                block = true;
                block1 = true;
                block2 = false;
            }
        }
        return null;
    }
    public PageReference ProceedWithSelectedToNextPage(){
        selectedWrapperList = new List<wrapProduct>();
        normalList = false;
        selectedList = true;
        for(wrapProduct selectedWrapObj: wrapProductList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
                selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
        PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
        pageRef.setRedirect(false);
        return pageRef;
    }
    public void processSelected() {
        selectedProduct = new List<PricebookEntry__c>();
        for(wrapProduct wrapProductObj : wrapProductList) {
            if(wrapProductObj.selected == true) {
                selectedProduct.add(wrapProductObj.acc);
                block = false;
                block1 = false;
                block2 = true;
               
            }
        }
    }
   
    public void GoBack() {
        block = true;
        block1 = true;
        block2 = false;
    }
   
    public class wrapProduct{
        public PricebookEntry__c acc {get;set;}
        public Boolean selected {get;set;}
        public wrapProduct(PricebookEntry__c p) {
            this.acc = p;
            this.selected = false;
        }
       
    }
   
    public pagereference saveproduct(){
        List<QuoteLineitem__c> quoteLineList = new  List<QuoteLineitem__c>();
        if(!selectedProduct.isEmpty()){
            for(PricebookEntry__c sp:selectedProduct){
                system.debug('sp '+sp);
                QuoteLineitem__c qli = new QuoteLineitem__c();
                qli.QuotesId__c = recordId;
                qli.ListPrice__c = sp.UnitPrice__c;
                qli.UnitPrice__c = sp.UnitPrice__c;
                qli.Product2Id__c = sp.Product2Id__c;    
                if(Discount!=0 || Discount!=null){
                    qli.Discount__c = Discount;
                }
                quoteLineList.add(qli);
            }
           
            if(quoteLineList.size()>0){
                insert quoteLineList;
                PageReference pageRef = new PageReference('https://proseraa.lightning.force.com/lightning/r/Quotes__c/'+recordId+'/view');
                pageRef.setRedirect(true);
                return pageRef;
            }
        }
        return null;
    }
   
}