• James Murphy
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
Hi,
The snippet below is from an Apex Class I have. In production, it works great. I use my list AccountsinBatch to limit the results of other queries in my class, which is great.

Only problem is that it doesn't work in my test class! The last line 
List<Account> AccountsinBatch = [SELECT ID FROM Account WHERE ID IN :AccountBatch limit :accountlimit];
 returns 0 rows. If I remove the "...ID IN :AccountBatch..." part the test class gets data. 

I don't think the problem is that AccountBatch is empty since I can see Apex interates through, adding to it. 

So why does the bind break in test class, but not prod?

Any help would be apprecaited,
James
03:11:55.340 (3340851502)|SYSTEM_METHOD_ENTRY|[183]|List<Id>.add(Object)
03:11:55.340 (3340857975)|ENTERING_MANAGED_PKG|
03:11:55.340 (3340867547)|SYSTEM_METHOD_EXIT|[183]|List<Id>.add(Object)
03:11:55.340 (3340874331)|SYSTEM_METHOD_ENTRY|[181]|system.ListIterator.hasNext()
03:11:55.340 (3340884287)|SYSTEM_METHOD_EXIT|[181]|system.ListIterator.hasNext()
03:11:55.340 (3340914907)|SYSTEM_METHOD_ENTRY|[183]|List<Id>.add(Object)
03:11:55.340 (3340921200)|ENTERING_MANAGED_PKG|
03:11:55.340 (3340930410)|SYSTEM_METHOD_EXIT|[183]|List<Id>.add(Object)
03:11:55.340 (3340937140)|SYSTEM_METHOD_ENTRY|[181]|system.ListIterator.hasNext()
03:11:55.340 (3340947018)|SYSTEM_METHOD_EXIT|[181]|system.ListIterator.hasNext()
03:11:55.340 (3340961044)|SYSTEM_METHOD_ENTRY|[185]|TaxReceiptsNPSP__ReceiptSettings__c.getInstance(String)
03:11:55.340 (3340966823)|ENTERING_MANAGED_PKG|
03:11:55.341 (3341067464)|SYSTEM_METHOD_EXIT|[185]|TaxReceiptsNPSP__ReceiptSettings__c.getInstance(String)
03:11:55.341 (3341099837)|SYSTEM_METHOD_ENTRY|[185]|Integer.valueOf(Object)
03:11:55.341 (3341107019)|ENTERING_MANAGED_PKG|
03:11:55.341 (3341134335)|SYSTEM_METHOD_EXIT|[185]|Integer.valueOf(Object)
03:11:55.341 (3341319181)|SOQL_EXECUTE_BEGIN|[186]|Aggregations:0|SELECT ID FROM Account WHERE ID IN :tmpVar1 LIMIT :tmpVar2
03:11:55.343 (3343319950)|SOQL_EXECUTE_END|[186]|Rows:0



 
List<ID> AccountBatch = new List<ID>();
List<Opportunity> AllReceiptableGifts = [select Account.ID FROM Opportunity WHERE (Receipt__c=NULL OR ReceiptQueue__c = 'Replace') AND (Receipt_to__c = 'Contact (Role)' OR Receipt_to__c = 'Account') AND Receiptable_Amount__c>0 AND ReceiptQueue__c = :ReceiptWhen AND CALENDAR_YEAR(CloseDate) = :DonationYear];
 
for (Opportunity d : AllReceiptableGifts)
{
        AccountBatch.add(d.Account.id);
}

accountlimit = integer.valueof(TaxReceiptsNPSP__ReceiptSettings__c.getInstance('Current').TaxReceiptsNPSP__Max_of_accounts_to_receipt_in_batch__c);

List<Account> AccountsinBatch = [SELECT ID FROM Account WHERE ID IN :AccountBatch limit :accountlimit];

 
Hi,
I'm a bit new with APEX/Visual Force and having trouble with my code.

I have a controller with 4 methods including tabulateReceipt (calculates amounts and inserts a record based on it), savePDF (which generates a VF page rendered as PDF based on the record), and ReceiptProcess which calls each of them.

When I run ReceiptProcess, the PDF documents from savePDF() are empty. If I delete the PDFs and run it again, I've noticed that it creates PDF documents for the records I created previously.

The problem is, I want the user to press a button and have a record inserted and a PDF generated - in one step, not two. Why isn't savePDF() able to read the records created by tabulateReceipts()??

public with sharing class PdfGeneratorController {

  //public ID parentId {get;set;}
  //public String pdfName {get;set;}
  public String email {get;set;}
  
  public Decimal amount = 0;
  private ID contactID = null;
  private String toAddress = null;
  public ID TRId  = null;  
       
    public PageReference savePDFs()
    {       
        Set<Id> attchmentParentIds = new Set<Id>();
        Attachment[] attachments = [SELECT ParentId FROM Attachment];
        for (Attachment a : attachments)
        {
            attchmentParentIds.add(a.ParentId);
        }           
        List<Attachment> attach = new List<Attachment>();
        List<Tax_Receipt__c> InsertedTRs = [SELECT ID FROM Tax_Receipt__c WHERE ID NOT IN :attchmentParentIds];
        For (Tax_Receipt__c myTR: InsertedTRs)
        { 
            PageReference pdf = Page.PdfGeneratorTemplate;
            system.debug ('myTR.id is: ' + myTR.Id);
            pdf.getParameters().put('id', myTR.Id);
            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');
            }
            attach.add(new Attachment(
                        Body = body,
                        Name = 'TaxReceipt.pdf',
                        IsPrivate = false,
                        ParentId = myTR.Id    
                        ));
        }               
        insert attach;
        return null;
    }

    public Tax_Receipt__c tabulateReceipts()
    {
        List<Tax_Receipt__c> newTRs = new List<Tax_Receipt__c>();
        List<OpportunityContactRole> donations = [select Opportunity.ID, Contact.ID, Opportunity.Receiptable_Amount__c, Opportunity.Receipt__c FROM OpportunityContactRole WHERE IsDeleted = FALSE AND IsPrimary = TRUE AND Opportunity.Receipt__c=NULL AND Opportunity.Receiptable_Amount__c>0];
        List<aggregateResult> contacts = [select Contact.ID CId, Contact.Email CEmail, SUM(Opportunity.Receiptable_Amount__c) amt FROM OpportunityContactRole WHERE ID IN : donations GROUP BY Contact.ID, Contact.Email, Contact.Name];
        for (AggregateResult ar : contacts)  
        {  
            email = String.ValueOf(ar.get('CEmail'));
            amount = (Decimal) ar.get('amt');
            contactID = (ID) ar.get('CId');
            Tax_Receipt__c thisTR = new Tax_Receipt__c(Contact__c = contactID, Amount__c = amount);
            newTRs.add(thisTR);
        }
        insert newTRs;
        return null;
        
    }

    public Tax_Receipt__c emailPDFs() 
    {
        Map<ID, String> EmailPDFLink = new Map<ID, String>();
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
        List<Tax_Receipt__c> TRsToSend = [Select ID, Email__c FROM Tax_Receipt__c WHERE Tax_Receipt__c.Sent__c = FALSE];
        for(Tax_Receipt__c TR : TRsToSend) 
        {
            EmailPDFLink.Put(TR.ID, TR.Email__c);    
            TR.Sent__c = TRUE;
        }
        List<Attachment> PDFsToSend = [SELECT body, Name, ParentID FROM Attachment WHERE ParentID IN :TRsToSend];
        for(Attachment att : PDFsToSend) 
        {
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                toAddress = EmailPDFLink.Get(att.ParentID);
                email.setToAddresses(New String [] {toAddress});
                email.setPlainTextBody('Thanks for your contribution');
                List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
                Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
                efa.SetBody(att.body);
                efa.SetFileName(att.Name);
                fileAttachments.Add(efa);
                email.setFileAttachments(fileAttachments);
                emails.add(email);
        }        
        Messaging.sendEmail(emails);
        Update (TRsToSend);
        return null;
  }
  
  public void ReceiptProcess()
  {
      tabulateReceipts();
      savePDFs();
      //emailPDFs()
  }

}
Hi,
I'm a bit new with APEX and having trouble with my code.

I have a controller with 4 methods including tabulateReceipt (calculates amounts and inserts a record based on it), savePDF (which generates a PDF document based on the record), and ReceiptProcess which calls each of them.

When I run ReceiptProcess, the PDF documents from savePDF() are empty. If I delete the PDFs and run it again, I've noticed that it creates PDF documents for the records I created previously.

The problem is, I want the user to press a button and have a record inserted and a PDF generated - in one step, not two. Why isn't savePDF() able to read the records created by tabulateReceipts()??

public with sharing class PdfGeneratorController {

  //public ID parentId {get;set;}
  //public String pdfName {get;set;}
  public String email {get;set;}
  
  public Decimal amount = 0;
  private ID contactID = null;
  private String toAddress = null;
  public ID TRId  = null;  
       
    public PageReference savePDFs()
    {       
        Set<Id> attchmentParentIds = new Set<Id>();
        Attachment[] attachments = [SELECT ParentId FROM Attachment];
        for (Attachment a : attachments)
        {
            attchmentParentIds.add(a.ParentId);
        }           
        List<Attachment> attach = new List<Attachment>();
        List<Tax_Receipt__c> InsertedTRs = [SELECT ID FROM Tax_Receipt__c WHERE ID NOT IN :attchmentParentIds];
        For (Tax_Receipt__c myTR: InsertedTRs)
        { 
            PageReference pdf = Page.PdfGeneratorTemplate;
            system.debug ('myTR.id is: ' + myTR.Id);
            pdf.getParameters().put('id', myTR.Id);
            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');
            }
            attach.add(new Attachment(
                        Body = body,
                        Name = 'TaxReceipt.pdf',
                        IsPrivate = false,
                        ParentId = myTR.Id    
                        ));
        }               
        insert attach;
        return null;
    }

    public Tax_Receipt__c tabulateReceipts()
    {
        List<Tax_Receipt__c> newTRs = new List<Tax_Receipt__c>();
        List<OpportunityContactRole> donations = [select Opportunity.ID, Contact.ID, Opportunity.Receiptable_Amount__c, Opportunity.Receipt__c FROM OpportunityContactRole WHERE IsDeleted = FALSE AND IsPrimary = TRUE AND Opportunity.Receipt__c=NULL AND Opportunity.Receiptable_Amount__c>0];
        List<aggregateResult> contacts = [select Contact.ID CId, Contact.Email CEmail, SUM(Opportunity.Receiptable_Amount__c) amt FROM OpportunityContactRole WHERE ID IN : donations GROUP BY Contact.ID, Contact.Email, Contact.Name];
        for (AggregateResult ar : contacts)  
        {  
            email = String.ValueOf(ar.get('CEmail'));
            amount = (Decimal) ar.get('amt');
            contactID = (ID) ar.get('CId');
            Tax_Receipt__c thisTR = new Tax_Receipt__c(Contact__c = contactID, Amount__c = amount);
            newTRs.add(thisTR);
        }
        insert newTRs;
        return null;
        
    }

    public Tax_Receipt__c emailPDFs() 
    {
        Map<ID, String> EmailPDFLink = new Map<ID, String>();
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
        List<Tax_Receipt__c> TRsToSend = [Select ID, Email__c FROM Tax_Receipt__c WHERE Tax_Receipt__c.Sent__c = FALSE];
        for(Tax_Receipt__c TR : TRsToSend) 
        {
            EmailPDFLink.Put(TR.ID, TR.Email__c);    
            TR.Sent__c = TRUE;
        }
        List<Attachment> PDFsToSend = [SELECT body, Name, ParentID FROM Attachment WHERE ParentID IN :TRsToSend];
        for(Attachment att : PDFsToSend) 
        {
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                toAddress = EmailPDFLink.Get(att.ParentID);
                email.setToAddresses(New String [] {toAddress});
                email.setPlainTextBody('Thanks for your contribution');
                List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
                Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
                efa.SetBody(att.body);
                efa.SetFileName(att.Name);
                fileAttachments.Add(efa);
                email.setFileAttachments(fileAttachments);
                emails.add(email);
        }        
        Messaging.sendEmail(emails);
        Update (TRsToSend);
        return null;
  }
  
  public void ReceiptProcess()
  {
      tabulateReceipts();
      savePDFs();
      //emailPDFs()
  }

}
 
Hi,
The snippet below is from an Apex Class I have. In production, it works great. I use my list AccountsinBatch to limit the results of other queries in my class, which is great.

Only problem is that it doesn't work in my test class! The last line 
List<Account> AccountsinBatch = [SELECT ID FROM Account WHERE ID IN :AccountBatch limit :accountlimit];
 returns 0 rows. If I remove the "...ID IN :AccountBatch..." part the test class gets data. 

I don't think the problem is that AccountBatch is empty since I can see Apex interates through, adding to it. 

So why does the bind break in test class, but not prod?

Any help would be apprecaited,
James
03:11:55.340 (3340851502)|SYSTEM_METHOD_ENTRY|[183]|List<Id>.add(Object)
03:11:55.340 (3340857975)|ENTERING_MANAGED_PKG|
03:11:55.340 (3340867547)|SYSTEM_METHOD_EXIT|[183]|List<Id>.add(Object)
03:11:55.340 (3340874331)|SYSTEM_METHOD_ENTRY|[181]|system.ListIterator.hasNext()
03:11:55.340 (3340884287)|SYSTEM_METHOD_EXIT|[181]|system.ListIterator.hasNext()
03:11:55.340 (3340914907)|SYSTEM_METHOD_ENTRY|[183]|List<Id>.add(Object)
03:11:55.340 (3340921200)|ENTERING_MANAGED_PKG|
03:11:55.340 (3340930410)|SYSTEM_METHOD_EXIT|[183]|List<Id>.add(Object)
03:11:55.340 (3340937140)|SYSTEM_METHOD_ENTRY|[181]|system.ListIterator.hasNext()
03:11:55.340 (3340947018)|SYSTEM_METHOD_EXIT|[181]|system.ListIterator.hasNext()
03:11:55.340 (3340961044)|SYSTEM_METHOD_ENTRY|[185]|TaxReceiptsNPSP__ReceiptSettings__c.getInstance(String)
03:11:55.340 (3340966823)|ENTERING_MANAGED_PKG|
03:11:55.341 (3341067464)|SYSTEM_METHOD_EXIT|[185]|TaxReceiptsNPSP__ReceiptSettings__c.getInstance(String)
03:11:55.341 (3341099837)|SYSTEM_METHOD_ENTRY|[185]|Integer.valueOf(Object)
03:11:55.341 (3341107019)|ENTERING_MANAGED_PKG|
03:11:55.341 (3341134335)|SYSTEM_METHOD_EXIT|[185]|Integer.valueOf(Object)
03:11:55.341 (3341319181)|SOQL_EXECUTE_BEGIN|[186]|Aggregations:0|SELECT ID FROM Account WHERE ID IN :tmpVar1 LIMIT :tmpVar2
03:11:55.343 (3343319950)|SOQL_EXECUTE_END|[186]|Rows:0



 
List<ID> AccountBatch = new List<ID>();
List<Opportunity> AllReceiptableGifts = [select Account.ID FROM Opportunity WHERE (Receipt__c=NULL OR ReceiptQueue__c = 'Replace') AND (Receipt_to__c = 'Contact (Role)' OR Receipt_to__c = 'Account') AND Receiptable_Amount__c>0 AND ReceiptQueue__c = :ReceiptWhen AND CALENDAR_YEAR(CloseDate) = :DonationYear];
 
for (Opportunity d : AllReceiptableGifts)
{
        AccountBatch.add(d.Account.id);
}

accountlimit = integer.valueof(TaxReceiptsNPSP__ReceiptSettings__c.getInstance('Current').TaxReceiptsNPSP__Max_of_accounts_to_receipt_in_batch__c);

List<Account> AccountsinBatch = [SELECT ID FROM Account WHERE ID IN :AccountBatch limit :accountlimit];

 
Hi,
I'm a bit new with APEX/Visual Force and having trouble with my code.

I have a controller with 4 methods including tabulateReceipt (calculates amounts and inserts a record based on it), savePDF (which generates a VF page rendered as PDF based on the record), and ReceiptProcess which calls each of them.

When I run ReceiptProcess, the PDF documents from savePDF() are empty. If I delete the PDFs and run it again, I've noticed that it creates PDF documents for the records I created previously.

The problem is, I want the user to press a button and have a record inserted and a PDF generated - in one step, not two. Why isn't savePDF() able to read the records created by tabulateReceipts()??

public with sharing class PdfGeneratorController {

  //public ID parentId {get;set;}
  //public String pdfName {get;set;}
  public String email {get;set;}
  
  public Decimal amount = 0;
  private ID contactID = null;
  private String toAddress = null;
  public ID TRId  = null;  
       
    public PageReference savePDFs()
    {       
        Set<Id> attchmentParentIds = new Set<Id>();
        Attachment[] attachments = [SELECT ParentId FROM Attachment];
        for (Attachment a : attachments)
        {
            attchmentParentIds.add(a.ParentId);
        }           
        List<Attachment> attach = new List<Attachment>();
        List<Tax_Receipt__c> InsertedTRs = [SELECT ID FROM Tax_Receipt__c WHERE ID NOT IN :attchmentParentIds];
        For (Tax_Receipt__c myTR: InsertedTRs)
        { 
            PageReference pdf = Page.PdfGeneratorTemplate;
            system.debug ('myTR.id is: ' + myTR.Id);
            pdf.getParameters().put('id', myTR.Id);
            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');
            }
            attach.add(new Attachment(
                        Body = body,
                        Name = 'TaxReceipt.pdf',
                        IsPrivate = false,
                        ParentId = myTR.Id    
                        ));
        }               
        insert attach;
        return null;
    }

    public Tax_Receipt__c tabulateReceipts()
    {
        List<Tax_Receipt__c> newTRs = new List<Tax_Receipt__c>();
        List<OpportunityContactRole> donations = [select Opportunity.ID, Contact.ID, Opportunity.Receiptable_Amount__c, Opportunity.Receipt__c FROM OpportunityContactRole WHERE IsDeleted = FALSE AND IsPrimary = TRUE AND Opportunity.Receipt__c=NULL AND Opportunity.Receiptable_Amount__c>0];
        List<aggregateResult> contacts = [select Contact.ID CId, Contact.Email CEmail, SUM(Opportunity.Receiptable_Amount__c) amt FROM OpportunityContactRole WHERE ID IN : donations GROUP BY Contact.ID, Contact.Email, Contact.Name];
        for (AggregateResult ar : contacts)  
        {  
            email = String.ValueOf(ar.get('CEmail'));
            amount = (Decimal) ar.get('amt');
            contactID = (ID) ar.get('CId');
            Tax_Receipt__c thisTR = new Tax_Receipt__c(Contact__c = contactID, Amount__c = amount);
            newTRs.add(thisTR);
        }
        insert newTRs;
        return null;
        
    }

    public Tax_Receipt__c emailPDFs() 
    {
        Map<ID, String> EmailPDFLink = new Map<ID, String>();
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
        List<Tax_Receipt__c> TRsToSend = [Select ID, Email__c FROM Tax_Receipt__c WHERE Tax_Receipt__c.Sent__c = FALSE];
        for(Tax_Receipt__c TR : TRsToSend) 
        {
            EmailPDFLink.Put(TR.ID, TR.Email__c);    
            TR.Sent__c = TRUE;
        }
        List<Attachment> PDFsToSend = [SELECT body, Name, ParentID FROM Attachment WHERE ParentID IN :TRsToSend];
        for(Attachment att : PDFsToSend) 
        {
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                toAddress = EmailPDFLink.Get(att.ParentID);
                email.setToAddresses(New String [] {toAddress});
                email.setPlainTextBody('Thanks for your contribution');
                List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
                Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
                efa.SetBody(att.body);
                efa.SetFileName(att.Name);
                fileAttachments.Add(efa);
                email.setFileAttachments(fileAttachments);
                emails.add(email);
        }        
        Messaging.sendEmail(emails);
        Update (TRsToSend);
        return null;
  }
  
  public void ReceiptProcess()
  {
      tabulateReceipts();
      savePDFs();
      //emailPDFs()
  }

}
Hi,
I'm a bit new with APEX and having trouble with my code.

I have a controller with 4 methods including tabulateReceipt (calculates amounts and inserts a record based on it), savePDF (which generates a PDF document based on the record), and ReceiptProcess which calls each of them.

When I run ReceiptProcess, the PDF documents from savePDF() are empty. If I delete the PDFs and run it again, I've noticed that it creates PDF documents for the records I created previously.

The problem is, I want the user to press a button and have a record inserted and a PDF generated - in one step, not two. Why isn't savePDF() able to read the records created by tabulateReceipts()??

public with sharing class PdfGeneratorController {

  //public ID parentId {get;set;}
  //public String pdfName {get;set;}
  public String email {get;set;}
  
  public Decimal amount = 0;
  private ID contactID = null;
  private String toAddress = null;
  public ID TRId  = null;  
       
    public PageReference savePDFs()
    {       
        Set<Id> attchmentParentIds = new Set<Id>();
        Attachment[] attachments = [SELECT ParentId FROM Attachment];
        for (Attachment a : attachments)
        {
            attchmentParentIds.add(a.ParentId);
        }           
        List<Attachment> attach = new List<Attachment>();
        List<Tax_Receipt__c> InsertedTRs = [SELECT ID FROM Tax_Receipt__c WHERE ID NOT IN :attchmentParentIds];
        For (Tax_Receipt__c myTR: InsertedTRs)
        { 
            PageReference pdf = Page.PdfGeneratorTemplate;
            system.debug ('myTR.id is: ' + myTR.Id);
            pdf.getParameters().put('id', myTR.Id);
            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');
            }
            attach.add(new Attachment(
                        Body = body,
                        Name = 'TaxReceipt.pdf',
                        IsPrivate = false,
                        ParentId = myTR.Id    
                        ));
        }               
        insert attach;
        return null;
    }

    public Tax_Receipt__c tabulateReceipts()
    {
        List<Tax_Receipt__c> newTRs = new List<Tax_Receipt__c>();
        List<OpportunityContactRole> donations = [select Opportunity.ID, Contact.ID, Opportunity.Receiptable_Amount__c, Opportunity.Receipt__c FROM OpportunityContactRole WHERE IsDeleted = FALSE AND IsPrimary = TRUE AND Opportunity.Receipt__c=NULL AND Opportunity.Receiptable_Amount__c>0];
        List<aggregateResult> contacts = [select Contact.ID CId, Contact.Email CEmail, SUM(Opportunity.Receiptable_Amount__c) amt FROM OpportunityContactRole WHERE ID IN : donations GROUP BY Contact.ID, Contact.Email, Contact.Name];
        for (AggregateResult ar : contacts)  
        {  
            email = String.ValueOf(ar.get('CEmail'));
            amount = (Decimal) ar.get('amt');
            contactID = (ID) ar.get('CId');
            Tax_Receipt__c thisTR = new Tax_Receipt__c(Contact__c = contactID, Amount__c = amount);
            newTRs.add(thisTR);
        }
        insert newTRs;
        return null;
        
    }

    public Tax_Receipt__c emailPDFs() 
    {
        Map<ID, String> EmailPDFLink = new Map<ID, String>();
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
        List<Tax_Receipt__c> TRsToSend = [Select ID, Email__c FROM Tax_Receipt__c WHERE Tax_Receipt__c.Sent__c = FALSE];
        for(Tax_Receipt__c TR : TRsToSend) 
        {
            EmailPDFLink.Put(TR.ID, TR.Email__c);    
            TR.Sent__c = TRUE;
        }
        List<Attachment> PDFsToSend = [SELECT body, Name, ParentID FROM Attachment WHERE ParentID IN :TRsToSend];
        for(Attachment att : PDFsToSend) 
        {
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                toAddress = EmailPDFLink.Get(att.ParentID);
                email.setToAddresses(New String [] {toAddress});
                email.setPlainTextBody('Thanks for your contribution');
                List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
                Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
                efa.SetBody(att.body);
                efa.SetFileName(att.Name);
                fileAttachments.Add(efa);
                email.setFileAttachments(fileAttachments);
                emails.add(email);
        }        
        Messaging.sendEmail(emails);
        Update (TRsToSend);
        return null;
  }
  
  public void ReceiptProcess()
  {
      tabulateReceipts();
      savePDFs();
      //emailPDFs()
  }

}