• rohitash yadav 8
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 9
    Replies
Hi,

I need to show a list of those leads in my visualforce page on which any task or call is created. I have wrote the following query but it is not working.

Select Id, Name from Lead where Id IN (SELECT Who.Id FROM Task where Who.Type='Lead') limit 10

Can anyone help me?

Thanks,
Rohitash
Hi,

I want to create one record in my custom object  through rest api in php. What is the best way to do so. and how to achieve my goal. Please help anyone.
Hi,

I have wrapper class and test class. My code coverage is 38%. Can anyone help me to increase code coverage.

Apex class is 
public with sharing class OpportunityLineItemsNew {
    public List<Package__c> selectedPackages = new List<Package__c>();
    public Package__c prdcat{get;set;}
    public List<Package__c> checkedPackages{get;set;}
    List<packagewrapper1> packagesListNew = new List<packagewrapper1>();
    public List<packagewrapper1> packages {get;set;}
    public List<Package__c> filteredList = new List<Package__c>();
    String opprid = System.currentPageReference().getParameters().get('id');
    public set<Id> AccountSelectedSet;
    public OpportunityLineItemsNew(ApexPages.StandardSetController controller) {
        prdcat = new Package__c();
        AccountSelectedSet = new set<Id>();
        checkedPackages = new List<Package__c>();
        packagesListNew = new List<packagewrapper1>();
        packages = new List<packagewrapper1>();
        
        for(Line_Item__c chpack: [select Id, Name, Package__c,Product_Category__c,Activity__c,Cost__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c from Line_Item__c where Opportunity__c = :opprid]){
            Package__c exisOpprLineItems = new Package__c();
            exisOpprLineItems.Name = chpack.Name;
            exisOpprLineItems.Product_Category__c = chpack.Product_Category__c;
            exisOpprLineItems.Activity__c = chpack.Activity__c;
            exisOpprLineItems.Cost__c = chpack.Cost__c;
            exisOpprLineItems.Final_Price__c = chpack.Final_Price__c;
            exisOpprLineItems.No_of_Days__c = chpack.No_of_Days__c;
            exisOpprLineItems.No_Of_People__c = chpack.No_Of_People__c;
            exisOpprLineItems.No_of_Male__c = chpack.No_of_Male__c;
            exisOpprLineItems.No_of_Female__c = chpack.No_of_Female__c;
            exisOpprLineItems.Total_Price__c= chpack.Total_Price__c;
            exisOpprLineItems.Comments__c = chpack.Comments__c;
            checkedPackages.add(exisOpprLineItems);
            AccountSelectedSet.add(chpack.Package__c);
        }
    }

    public List<packagewrapper1> getPackages(){
        if( prdcat.Product_Category__c != null ){
            filteredList = [SELECT Id,Name,Product_Category__c,Cost__c,Stay__c,Activity__c,Description__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c FROM Package__c 
               where Product_Category__c=:prdcat.Product_Category__c ];
        } else {
            filteredList = [SELECT Id,Name,Product_Category__c,Cost__c,Stay__c,Activity__c,Description__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c FROM Package__c ];
        }
        for(Package__c a : filteredList ){
            if(AccountSelectedSet.contains(a.Id)) {
            } else {
                packages.add(new packagewrapper1(a));
            }
            packages.add(new packagewrapper1(a));
        }
        
        return packages;
    }
    
    public  PageReference  filterPackagess(){
        packages.clear();
        return null;
    }

    public Package__c getPrdcat() {
        prdcat = new Package__c();
        return null;
    }

    public void getSelectedPackages() {
        for(packagewrapper1 pkgwrapper : packages){
            if(pkgwrapper.selected == true){
                if(AccountSelectedSet.contains(pkgwrapper.pkgs.Id)) {
                } else {
                    AccountSelectedSet.add(pkgwrapper.pkgs.Id);
                    checkedPackages.add(pkgwrapper.pkgs);
                }
            }
        }
    }

    public PageReference cancel() {
        PageReference opportunityPage = new PageReference('/'+opprid);
        opportunityPage.setRedirect(true);
        return opportunityPage;
    }

    public PageReference save() {
        String opprid=System.currentPageReference().getParameters().get('id');
        for(Line_Item__c chpack: [select Id, Name, Package__c,Product_Category__c,Activity__c,Cost__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c from Line_Item__c where Opportunity__c = :opprid]){
            delete chpack;
        }
                
        for(Package__c chpack : checkedPackages){
            Line_Item__c oppline = new Line_Item__c();
            oppline.Name = chpack.Name;
            oppline.Product_Category__c= chpack.Product_Category__c;
            oppline.Activity__c = chpack.Activity__c;
            oppline.Cost__c = chpack.Cost__c;
            oppline.Final_Price__c = chpack.Final_Price__c;
            oppline.No_Of_People__c = chpack.No_Of_People__c;
            oppline.No_of_Male__c = chpack.No_of_Male__c;
            oppline.No_of_Female__c = chpack.No_of_Female__c;
            oppline.No_of_Days__c = chpack.No_of_Days__c;
            oppline.Total_Price__c= chpack.Total_Price__c;
            oppline.Comments__c = chpack.Comments__c;
            oppline.Opportunity__c = opprid;
            oppline.Package__c = chpack.Id;
            insert oppline;
        }

        PageReference opportunityPage = new PageReference('/'+opprid);
        opportunityPage .setRedirect(true);
        return opportunityPage ;
    }

    public class packagewrapper1 {
        public Package__c pkgs{get; set;}
        public Boolean selected {get; set;}
        public packagewrapper1(Package__c p) 
        { 
            pkgs = p;
            selected = false;
        }
    }
}

Test class is:
 
@isTest
private class Test_OpportunityLineItemsNew {
    static Opportunity oppor;
    static List<Line_Item__c> opporLineItem;
    static Payment_Schedule__c paySchedule;
    static List<Package__c> selectedPackages;
    static List<OpportunityLineItemsNew.packagewrapper1> packagesListNew;
    static List<OpportunityLineItemsNew.packagewrapper1> packages;
    static String opprid;

    static {
        packagesListNew = new List<OpportunityLineItemsNew.packagewrapper1>();
        packages = new List<OpportunityLineItemsNew.packagewrapper1>();
        
        oppor = new Opportunity();
        oppor.Name = 'Test Opportunity';
        oppor.Location__c = 'Nandi Hills';
        oppor.StageName = 'Lead';
        oppor.CloseDate = Date.newInstance(2016, 07, 22);
        insert oppor;
        
        opporLineItem = new List<Line_Item__c>(); 
        for(Package__c chpack: [select Id, Name, Product_Category__c,Activity__c,Cost__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c from Package__c where Product_Category__c = 'Full Day Package']){
            Line_Item__c oppline = new Line_Item__c();
            oppline.Name = chpack.Name;
            oppline.Product_Category__c= chpack.Product_Category__c;
            oppline.Activity__c = chpack.Activity__c;
            oppline.Cost__c = chpack.Cost__c;
            oppline.Final_Price__c = chpack.Final_Price__c;
            oppline.No_Of_People__c = 2;
            oppline.No_of_Male__c = 2;
            oppline.No_of_Female__c = 0;
            oppline.No_of_Days__c = 2;
            oppline.Total_Price__c= 2000;
            oppline.Comments__c = chpack.Comments__c;
            oppline.Opportunity__c = oppor.Id;
            oppline.Package__c = chpack.Id;
            opporLineItem.add(oppline);
        }

        insert opporLineItem;

        for(Line_Item__c chpack: [select Id, Name, Package__c,Product_Category__c,Activity__c,Cost__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c from Line_Item__c where Opportunity__c = :oppor.Id]){
            
            ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
            stdSetController.setSelected(opporLineItem);
            OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);
            con.AccountSelectedSet.add(chpack.Package__c);
        }
    }

    static testMethod List<OpportunityLineItemsNew.packagewrapper1> Test_getPackages() {
        PageReference pref = Page.AddOpportunityLineItem2;
        pref.getParameters().put('id',oppor.Id);
        Test.setCurrentPage(pref);
        Test.startTest();

        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
        stdSetController.setSelected(opporLineItem);
        OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);
        
        Package__c pkgs = new Package__c();
        OpportunityLineItemsNew.packagewrapper1 op = new OpportunityLineItemsNew.packagewrapper1(pkgs);

        con.prdcat.Product_Category__c = null;
        con.packages = con.getPackages();
        
        Test.stopTest();
        return packages ;
    }
    
    static testMethod Void Test_getSelectedPackages() {
        PageReference pref = Page.AddOpportunityLineItem2;
        pref.getParameters().put('id',oppor.Id);
        Test.setCurrentPage(pref);
        Test.startTest();

        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
        stdSetController.setSelected(opporLineItem);
        OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);

        con.getSelectedPackages();

        Test.stopTest();

    }
    
    static testMethod PageReference Test_filterPackagess(){
        PageReference pref = Page.AddOpportunityLineItem2;
        Test.setCurrentPage(pref);
        Test.startTest();
        
        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
        stdSetController.setSelected(opporLineItem);
        OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);

        pref = con.filterPackagess();

        Test.stopTest();
        return pref;
    }
    
    static testMethod PageReference Test_Save(){
        PageReference pref = Page.AddOpportunityLineItem2;
        Test.setCurrentPage(pref);
        Test.startTest();

        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
        stdSetController.setSelected(opporLineItem);
        OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);

        //getCheckecPackages
        pref = con.save();

        Test.stopTest();
        return pref;
    }
    
    static testMethod PageReference Test_Cancel(){
        PageReference pref = Page.AddOpportunityLineItem2;
        Test.setCurrentPage(pref);
        Test.startTest();

        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
        stdSetController.setSelected(opporLineItem);
        OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);
        pref = con.cancel();
        Test.stopTest();
        return pref;
    }

    static testMethod void TestgetSelectedPackages(){
        PageReference pref = Page.AddOpportunityLineItem2;
        Test.setCurrentPage(pref);
        Test.startTest();

        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
        stdSetController.setSelected(opporLineItem);
        OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);

        con.getSelectedPackages();

        Test.stopTest();
    }
}

 
HI,

I have a developer account with some functionality. I have to use all functionality into another account. Do I need to create a packages or app. Can anyone help me..

Thanks,
Rohitash yadav
Hi,

I am passing a parameter email from visual force pagfe to apex class. Based on the parameter I want to send pdf to the email address, but it is displaying error

Visualforce Page:
<apex:page standardController="Payment_Receipt__c" extensions="ReceiptEmailController">
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock title="Send Email">
            <div>
                <p style="text-align:center; font-size:16px;">Send an Email to <b><apex:outputField id="emailNew" value="{!Payment_Receipt__c.Contact_Email__c}" /></b> attaching Customer Details as PDF</p>
            </div>
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Cc:" />
                    <apex:inputText value="{!email_cc}" />
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton value="Send Email" action="{!sendEmailReceipt}" rendered="true" reRender="">

                </apex:commandButton>
          </apex:pageBlockButtons>
        </apex:pageBlock>
        <apex:iframe src="/apex/SendEmailReceiptPdf?id={!$CurrentPage.parameters.id}"/>
    </apex:form>
</apex:page>

Apex class is:
 
public with sharing class ReceiptEmailController {
    public ID receiptId {get;set;}
    public String email {get;set;}
    public String emailNew {get;set;}
    public String email_cc {get;set;}

    public ReceiptEmailController (ApexPages.StandardController controller) {
        receiptId = System.currentPageReference().getParameters().get('id');
    }

    public PageReference sendEmailReceipt() {

        String emailNew = System.currentPagereference().getParameters().get('emailNew');
        if(email_cc !='' && !Pattern.matches('[a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z]{2,4}', email_cc)) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Check your email')); 
        } else {
            PageReference pdf = Page.SendEmailReceiptPdf;
            // add parent id to the parameters for standardcontroller
            pdf.getParameters().put('id',receiptId);
    
            // the contents of the attachment from the pdf
            Blob body;
            try {
                // returns the output of the page as a PDF
                body = pdf.getContent();
    
            // need to pass unit test -- current bug  
            } catch (VisualforceException e) {
                body = Blob.valueOf('Some Text');
            }
    //email = System.currentPageReference().getParameters().get('email');
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            attach.setContentType('application/pdf');
            attach.setFileName('receipt.pdf');
            attach.setInline(false);
            attach.Body = body;
    
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setUseSignature(false);
            mail.setToAddresses(new String[] { emailNew });
            mail.setSubject('PDF Receipt Demo');
            mail.setHtmlBody('Here is the email you requested! Check the attachment!');
            mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); 
    
            // Send the email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Email with PDF sent to '+emailNew ));
        }
        return null;
    }
}

When I click on send email then it is displaying the following error:

SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email address is invalid: null: [toAddresses, null]

Can anyone help me:

Thanks,
Rohitash 
Hi,

I have some records with checkboxes in visualforces page. I am using wrapper class. I need to add the selected record(checkbox) to another table. When I click on checkbox then all records are getting added to the table again and again rather than only the one whick I check.

Visualforce Page:
 
<apex:page controller="OpportunityLineItems" >
    <apex:form >
        <apex:pageBlock title="Selected Packages">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
                <apex:pageblockTable value="{!checkedPackages}" var="pck" id="Selected_PBS"  >
                    <apex:column headerValue="">
                        Remove
                    </apex:column>
                    <apex:column headerValue="Product Name" value="{!pck.Name}" width="50" />
                    <apex:column headerValue="Product Category" value="{!pck.Product_Category__c}" width="50" />
                    <apex:column headerValue="Activity" width="50">
                        <apex:inputField value="{!pck.Activity__c}"/>
                    </apex:column>
                    <apex:column headerValue="Price" value="{!pck.Cost__c}" width="50"/>
                    <apex:column headerValue="Final Price" width="50">
                        <apex:inputField value="{!pck.Final_Price__c}"/>
                    </apex:column>
                    <apex:column headerValue="No of Days" width="50">
                        <apex:inputField value="{!pck.No_of_Days__c}"/>
                    </apex:column>
                    <apex:column headerValue="No Of People" width="50">
                        <apex:inputField value="{!pck.No_Of_People__c}"/>
                    </apex:column>
                    <apex:column headerValue="No Of Male" width="50">
                        <apex:inputField value="{!pck.No_of_Male__c}"/>
                    </apex:column>
                    <apex:column headerValue="No Of Female" width="50">
                        <apex:inputField value="{!pck.No_of_Female__c}"/>
                    </apex:column>
                    <apex:column headerValue="Total Price" width="50">
                        <apex:inputField value="{!pck.Total_Price__c}"/>
                    </apex:column>
                    <apex:column headerValue="Comments" width="50">
                        <apex:inputField value="{!pck.Comments__c}"/>
                    </apex:column>
                </apex:pageblockTable>
        </apex:pageBlock>
        <apex:pageBlock title="Search for Packages">
            <apex:outputLabel >Packages Category</apex:outputLabel>
            <apex:inputField value="{!prdcat.Product_Category__c}" >
                <apex:actionSupport event="onchange" rerender="packagesList" action="{!filterPackagess}"/>
            </apex:inputField>
                <apex:pageblockTable value="{!packages}" var="a" id="packagesList" >
                    <apex:column headerValue="Select" width="60">
                        <apex:inputCheckbox value="{!a.selected}" id="checkedone" >
                            <apex:actionSupport event="onclick" action="{!getSelectedPackages}" rerender="Selected_PBS"/>
                        </apex:inputCheckbox>
                    </apex:column>
                    <apex:column value="{!a.pkgs.Name}"/>
                    <apex:column value="{!a.pkgs.Product_Category__c}"/>
                    <apex:column value="{!a.pkgs.Cost__c}"/>
                    <apex:column value="{!a.pkgs.Stay__c}"/>
                    <apex:column value="{!a.pkgs.Activity__c}"/>
                    <apex:column value="{!a.pkgs.Description__c}"/>
                </apex:pageblocktable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Wrapper class:
public class OpportunityLineItems {

    List<Package__c> selectedPackages = new List<Package__c>();
    public Package__c prdcat{get;set;}
	List<packagewrapper1> packagesListNew = new List<packagewrapper1>();
    public OpportunityLineItems(){
        prdcat = new Package__c();
    }

    public  List<packagewrapper1> getPackages(){
        packagesListNew.clear();
        filteredList = new List<Package__c>();
        if( prdcat.Product_Category__c != null ){
            filteredList = [SELECT Id,Name,Product_Category__c,Cost__c,Stay__c,Activity__c,Description__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c FROM Package__c 
               where Product_Category__c=:prdcat.Product_Category__c ];
        } else {
            filteredList = [SELECT Id,Name,Product_Category__c,Cost__c,Stay__c,Activity__c,Description__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c FROM Package__c ];
        }
        for(Package__c a : filteredList ){
            packagesListNew.add(new packagewrapper1(a));
        }
        return packagesListNew;
    }
    
    List<Package__c> filteredList = new List<Package__c>();
    List<packagewrapper1> packages = new List<packagewrapper1>();
    public  PageReference  filterPackagess(){
        packages.clear();
        return null;
    }

    public Package__c getPrdcat() {
        prdcat = new Package__c();
        return null;
    }

    public List<Package__c> GetCheckedPackages() {
        if(selectedPackages.size()>0)
        return selectedPackages;
        else
        return null;
    }

    public PageReference getSelectedPackages() {
        selectedPackages.clear();
        for(packagewrapper1 pkgwrapper : packagesListNew)
        if(pkgwrapper.selected == true)
        selectedPackages.add(pkgwrapper.pkgs);
		return null;
    }

    public PageReference cancel() {
        return null;
    }

    public PageReference save() {
        return null;
    }

    public class packagewrapper1 {
        public Package__c pkgs{get; set;}
        public Boolean selected {get; set;}
        public packagewrapper1(Package__c p)
        {
            pkgs = p;
            selected = false;
        }
    }
}


Can anyone help me.

Thanks,
Rohitash
 
Hi,

I have wrapper class and test class. My code coverage is 38%. Can anyone help me to increase code coverage.

Apex class is 
public with sharing class OpportunityLineItemsNew {
    public List<Package__c> selectedPackages = new List<Package__c>();
    public Package__c prdcat{get;set;}
    public List<Package__c> checkedPackages{get;set;}
    List<packagewrapper1> packagesListNew = new List<packagewrapper1>();
    public List<packagewrapper1> packages {get;set;}
    public List<Package__c> filteredList = new List<Package__c>();
    String opprid = System.currentPageReference().getParameters().get('id');
    public set<Id> AccountSelectedSet;
    public OpportunityLineItemsNew(ApexPages.StandardSetController controller) {
        prdcat = new Package__c();
        AccountSelectedSet = new set<Id>();
        checkedPackages = new List<Package__c>();
        packagesListNew = new List<packagewrapper1>();
        packages = new List<packagewrapper1>();
        
        for(Line_Item__c chpack: [select Id, Name, Package__c,Product_Category__c,Activity__c,Cost__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c from Line_Item__c where Opportunity__c = :opprid]){
            Package__c exisOpprLineItems = new Package__c();
            exisOpprLineItems.Name = chpack.Name;
            exisOpprLineItems.Product_Category__c = chpack.Product_Category__c;
            exisOpprLineItems.Activity__c = chpack.Activity__c;
            exisOpprLineItems.Cost__c = chpack.Cost__c;
            exisOpprLineItems.Final_Price__c = chpack.Final_Price__c;
            exisOpprLineItems.No_of_Days__c = chpack.No_of_Days__c;
            exisOpprLineItems.No_Of_People__c = chpack.No_Of_People__c;
            exisOpprLineItems.No_of_Male__c = chpack.No_of_Male__c;
            exisOpprLineItems.No_of_Female__c = chpack.No_of_Female__c;
            exisOpprLineItems.Total_Price__c= chpack.Total_Price__c;
            exisOpprLineItems.Comments__c = chpack.Comments__c;
            checkedPackages.add(exisOpprLineItems);
            AccountSelectedSet.add(chpack.Package__c);
        }
    }

    public List<packagewrapper1> getPackages(){
        if( prdcat.Product_Category__c != null ){
            filteredList = [SELECT Id,Name,Product_Category__c,Cost__c,Stay__c,Activity__c,Description__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c FROM Package__c 
               where Product_Category__c=:prdcat.Product_Category__c ];
        } else {
            filteredList = [SELECT Id,Name,Product_Category__c,Cost__c,Stay__c,Activity__c,Description__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c FROM Package__c ];
        }
        for(Package__c a : filteredList ){
            if(AccountSelectedSet.contains(a.Id)) {
            } else {
                packages.add(new packagewrapper1(a));
            }
            packages.add(new packagewrapper1(a));
        }
        
        return packages;
    }
    
    public  PageReference  filterPackagess(){
        packages.clear();
        return null;
    }

    public Package__c getPrdcat() {
        prdcat = new Package__c();
        return null;
    }

    public void getSelectedPackages() {
        for(packagewrapper1 pkgwrapper : packages){
            if(pkgwrapper.selected == true){
                if(AccountSelectedSet.contains(pkgwrapper.pkgs.Id)) {
                } else {
                    AccountSelectedSet.add(pkgwrapper.pkgs.Id);
                    checkedPackages.add(pkgwrapper.pkgs);
                }
            }
        }
    }

    public PageReference cancel() {
        PageReference opportunityPage = new PageReference('/'+opprid);
        opportunityPage.setRedirect(true);
        return opportunityPage;
    }

    public PageReference save() {
        String opprid=System.currentPageReference().getParameters().get('id');
        for(Line_Item__c chpack: [select Id, Name, Package__c,Product_Category__c,Activity__c,Cost__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c from Line_Item__c where Opportunity__c = :opprid]){
            delete chpack;
        }
                
        for(Package__c chpack : checkedPackages){
            Line_Item__c oppline = new Line_Item__c();
            oppline.Name = chpack.Name;
            oppline.Product_Category__c= chpack.Product_Category__c;
            oppline.Activity__c = chpack.Activity__c;
            oppline.Cost__c = chpack.Cost__c;
            oppline.Final_Price__c = chpack.Final_Price__c;
            oppline.No_Of_People__c = chpack.No_Of_People__c;
            oppline.No_of_Male__c = chpack.No_of_Male__c;
            oppline.No_of_Female__c = chpack.No_of_Female__c;
            oppline.No_of_Days__c = chpack.No_of_Days__c;
            oppline.Total_Price__c= chpack.Total_Price__c;
            oppline.Comments__c = chpack.Comments__c;
            oppline.Opportunity__c = opprid;
            oppline.Package__c = chpack.Id;
            insert oppline;
        }

        PageReference opportunityPage = new PageReference('/'+opprid);
        opportunityPage .setRedirect(true);
        return opportunityPage ;
    }

    public class packagewrapper1 {
        public Package__c pkgs{get; set;}
        public Boolean selected {get; set;}
        public packagewrapper1(Package__c p) 
        { 
            pkgs = p;
            selected = false;
        }
    }
}

Test class is:
 
@isTest
private class Test_OpportunityLineItemsNew {
    static Opportunity oppor;
    static List<Line_Item__c> opporLineItem;
    static Payment_Schedule__c paySchedule;
    static List<Package__c> selectedPackages;
    static List<OpportunityLineItemsNew.packagewrapper1> packagesListNew;
    static List<OpportunityLineItemsNew.packagewrapper1> packages;
    static String opprid;

    static {
        packagesListNew = new List<OpportunityLineItemsNew.packagewrapper1>();
        packages = new List<OpportunityLineItemsNew.packagewrapper1>();
        
        oppor = new Opportunity();
        oppor.Name = 'Test Opportunity';
        oppor.Location__c = 'Nandi Hills';
        oppor.StageName = 'Lead';
        oppor.CloseDate = Date.newInstance(2016, 07, 22);
        insert oppor;
        
        opporLineItem = new List<Line_Item__c>(); 
        for(Package__c chpack: [select Id, Name, Product_Category__c,Activity__c,Cost__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c from Package__c where Product_Category__c = 'Full Day Package']){
            Line_Item__c oppline = new Line_Item__c();
            oppline.Name = chpack.Name;
            oppline.Product_Category__c= chpack.Product_Category__c;
            oppline.Activity__c = chpack.Activity__c;
            oppline.Cost__c = chpack.Cost__c;
            oppline.Final_Price__c = chpack.Final_Price__c;
            oppline.No_Of_People__c = 2;
            oppline.No_of_Male__c = 2;
            oppline.No_of_Female__c = 0;
            oppline.No_of_Days__c = 2;
            oppline.Total_Price__c= 2000;
            oppline.Comments__c = chpack.Comments__c;
            oppline.Opportunity__c = oppor.Id;
            oppline.Package__c = chpack.Id;
            opporLineItem.add(oppline);
        }

        insert opporLineItem;

        for(Line_Item__c chpack: [select Id, Name, Package__c,Product_Category__c,Activity__c,Cost__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c from Line_Item__c where Opportunity__c = :oppor.Id]){
            
            ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
            stdSetController.setSelected(opporLineItem);
            OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);
            con.AccountSelectedSet.add(chpack.Package__c);
        }
    }

    static testMethod List<OpportunityLineItemsNew.packagewrapper1> Test_getPackages() {
        PageReference pref = Page.AddOpportunityLineItem2;
        pref.getParameters().put('id',oppor.Id);
        Test.setCurrentPage(pref);
        Test.startTest();

        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
        stdSetController.setSelected(opporLineItem);
        OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);
        
        Package__c pkgs = new Package__c();
        OpportunityLineItemsNew.packagewrapper1 op = new OpportunityLineItemsNew.packagewrapper1(pkgs);

        con.prdcat.Product_Category__c = null;
        con.packages = con.getPackages();
        
        Test.stopTest();
        return packages ;
    }
    
    static testMethod Void Test_getSelectedPackages() {
        PageReference pref = Page.AddOpportunityLineItem2;
        pref.getParameters().put('id',oppor.Id);
        Test.setCurrentPage(pref);
        Test.startTest();

        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
        stdSetController.setSelected(opporLineItem);
        OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);

        con.getSelectedPackages();

        Test.stopTest();

    }
    
    static testMethod PageReference Test_filterPackagess(){
        PageReference pref = Page.AddOpportunityLineItem2;
        Test.setCurrentPage(pref);
        Test.startTest();
        
        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
        stdSetController.setSelected(opporLineItem);
        OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);

        pref = con.filterPackagess();

        Test.stopTest();
        return pref;
    }
    
    static testMethod PageReference Test_Save(){
        PageReference pref = Page.AddOpportunityLineItem2;
        Test.setCurrentPage(pref);
        Test.startTest();

        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
        stdSetController.setSelected(opporLineItem);
        OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);

        //getCheckecPackages
        pref = con.save();

        Test.stopTest();
        return pref;
    }
    
    static testMethod PageReference Test_Cancel(){
        PageReference pref = Page.AddOpportunityLineItem2;
        Test.setCurrentPage(pref);
        Test.startTest();

        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
        stdSetController.setSelected(opporLineItem);
        OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);
        pref = con.cancel();
        Test.stopTest();
        return pref;
    }

    static testMethod void TestgetSelectedPackages(){
        PageReference pref = Page.AddOpportunityLineItem2;
        Test.setCurrentPage(pref);
        Test.startTest();

        ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(opporLineItem);
        stdSetController.setSelected(opporLineItem);
        OpportunityLineItemsNew con = new OpportunityLineItemsNew (stdSetController);

        con.getSelectedPackages();

        Test.stopTest();
    }
}

 
Hi,

I am passing a parameter email from visual force pagfe to apex class. Based on the parameter I want to send pdf to the email address, but it is displaying error

Visualforce Page:
<apex:page standardController="Payment_Receipt__c" extensions="ReceiptEmailController">
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock title="Send Email">
            <div>
                <p style="text-align:center; font-size:16px;">Send an Email to <b><apex:outputField id="emailNew" value="{!Payment_Receipt__c.Contact_Email__c}" /></b> attaching Customer Details as PDF</p>
            </div>
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Cc:" />
                    <apex:inputText value="{!email_cc}" />
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton value="Send Email" action="{!sendEmailReceipt}" rendered="true" reRender="">

                </apex:commandButton>
          </apex:pageBlockButtons>
        </apex:pageBlock>
        <apex:iframe src="/apex/SendEmailReceiptPdf?id={!$CurrentPage.parameters.id}"/>
    </apex:form>
</apex:page>

Apex class is:
 
public with sharing class ReceiptEmailController {
    public ID receiptId {get;set;}
    public String email {get;set;}
    public String emailNew {get;set;}
    public String email_cc {get;set;}

    public ReceiptEmailController (ApexPages.StandardController controller) {
        receiptId = System.currentPageReference().getParameters().get('id');
    }

    public PageReference sendEmailReceipt() {

        String emailNew = System.currentPagereference().getParameters().get('emailNew');
        if(email_cc !='' && !Pattern.matches('[a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z]{2,4}', email_cc)) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Check your email')); 
        } else {
            PageReference pdf = Page.SendEmailReceiptPdf;
            // add parent id to the parameters for standardcontroller
            pdf.getParameters().put('id',receiptId);
    
            // the contents of the attachment from the pdf
            Blob body;
            try {
                // returns the output of the page as a PDF
                body = pdf.getContent();
    
            // need to pass unit test -- current bug  
            } catch (VisualforceException e) {
                body = Blob.valueOf('Some Text');
            }
    //email = System.currentPageReference().getParameters().get('email');
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            attach.setContentType('application/pdf');
            attach.setFileName('receipt.pdf');
            attach.setInline(false);
            attach.Body = body;
    
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setUseSignature(false);
            mail.setToAddresses(new String[] { emailNew });
            mail.setSubject('PDF Receipt Demo');
            mail.setHtmlBody('Here is the email you requested! Check the attachment!');
            mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); 
    
            // Send the email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Email with PDF sent to '+emailNew ));
        }
        return null;
    }
}

When I click on send email then it is displaying the following error:

SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email address is invalid: null: [toAddresses, null]

Can anyone help me:

Thanks,
Rohitash 
Hi,

I have some records with checkboxes in visualforces page. I am using wrapper class. I need to add the selected record(checkbox) to another table. When I click on checkbox then all records are getting added to the table again and again rather than only the one whick I check.

Visualforce Page:
 
<apex:page controller="OpportunityLineItems" >
    <apex:form >
        <apex:pageBlock title="Selected Packages">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
                <apex:pageblockTable value="{!checkedPackages}" var="pck" id="Selected_PBS"  >
                    <apex:column headerValue="">
                        Remove
                    </apex:column>
                    <apex:column headerValue="Product Name" value="{!pck.Name}" width="50" />
                    <apex:column headerValue="Product Category" value="{!pck.Product_Category__c}" width="50" />
                    <apex:column headerValue="Activity" width="50">
                        <apex:inputField value="{!pck.Activity__c}"/>
                    </apex:column>
                    <apex:column headerValue="Price" value="{!pck.Cost__c}" width="50"/>
                    <apex:column headerValue="Final Price" width="50">
                        <apex:inputField value="{!pck.Final_Price__c}"/>
                    </apex:column>
                    <apex:column headerValue="No of Days" width="50">
                        <apex:inputField value="{!pck.No_of_Days__c}"/>
                    </apex:column>
                    <apex:column headerValue="No Of People" width="50">
                        <apex:inputField value="{!pck.No_Of_People__c}"/>
                    </apex:column>
                    <apex:column headerValue="No Of Male" width="50">
                        <apex:inputField value="{!pck.No_of_Male__c}"/>
                    </apex:column>
                    <apex:column headerValue="No Of Female" width="50">
                        <apex:inputField value="{!pck.No_of_Female__c}"/>
                    </apex:column>
                    <apex:column headerValue="Total Price" width="50">
                        <apex:inputField value="{!pck.Total_Price__c}"/>
                    </apex:column>
                    <apex:column headerValue="Comments" width="50">
                        <apex:inputField value="{!pck.Comments__c}"/>
                    </apex:column>
                </apex:pageblockTable>
        </apex:pageBlock>
        <apex:pageBlock title="Search for Packages">
            <apex:outputLabel >Packages Category</apex:outputLabel>
            <apex:inputField value="{!prdcat.Product_Category__c}" >
                <apex:actionSupport event="onchange" rerender="packagesList" action="{!filterPackagess}"/>
            </apex:inputField>
                <apex:pageblockTable value="{!packages}" var="a" id="packagesList" >
                    <apex:column headerValue="Select" width="60">
                        <apex:inputCheckbox value="{!a.selected}" id="checkedone" >
                            <apex:actionSupport event="onclick" action="{!getSelectedPackages}" rerender="Selected_PBS"/>
                        </apex:inputCheckbox>
                    </apex:column>
                    <apex:column value="{!a.pkgs.Name}"/>
                    <apex:column value="{!a.pkgs.Product_Category__c}"/>
                    <apex:column value="{!a.pkgs.Cost__c}"/>
                    <apex:column value="{!a.pkgs.Stay__c}"/>
                    <apex:column value="{!a.pkgs.Activity__c}"/>
                    <apex:column value="{!a.pkgs.Description__c}"/>
                </apex:pageblocktable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Wrapper class:
public class OpportunityLineItems {

    List<Package__c> selectedPackages = new List<Package__c>();
    public Package__c prdcat{get;set;}
	List<packagewrapper1> packagesListNew = new List<packagewrapper1>();
    public OpportunityLineItems(){
        prdcat = new Package__c();
    }

    public  List<packagewrapper1> getPackages(){
        packagesListNew.clear();
        filteredList = new List<Package__c>();
        if( prdcat.Product_Category__c != null ){
            filteredList = [SELECT Id,Name,Product_Category__c,Cost__c,Stay__c,Activity__c,Description__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c FROM Package__c 
               where Product_Category__c=:prdcat.Product_Category__c ];
        } else {
            filteredList = [SELECT Id,Name,Product_Category__c,Cost__c,Stay__c,Activity__c,Description__c,Final_Price__c,No_of_Days__c,No_Of_People__c,No_of_Male__c,No_of_Female__c,Total_Price__c,Comments__c FROM Package__c ];
        }
        for(Package__c a : filteredList ){
            packagesListNew.add(new packagewrapper1(a));
        }
        return packagesListNew;
    }
    
    List<Package__c> filteredList = new List<Package__c>();
    List<packagewrapper1> packages = new List<packagewrapper1>();
    public  PageReference  filterPackagess(){
        packages.clear();
        return null;
    }

    public Package__c getPrdcat() {
        prdcat = new Package__c();
        return null;
    }

    public List<Package__c> GetCheckedPackages() {
        if(selectedPackages.size()>0)
        return selectedPackages;
        else
        return null;
    }

    public PageReference getSelectedPackages() {
        selectedPackages.clear();
        for(packagewrapper1 pkgwrapper : packagesListNew)
        if(pkgwrapper.selected == true)
        selectedPackages.add(pkgwrapper.pkgs);
		return null;
    }

    public PageReference cancel() {
        return null;
    }

    public PageReference save() {
        return null;
    }

    public class packagewrapper1 {
        public Package__c pkgs{get; set;}
        public Boolean selected {get; set;}
        public packagewrapper1(Package__c p)
        {
            pkgs = p;
            selected = false;
        }
    }
}


Can anyone help me.

Thanks,
Rohitash