• Nazneen Arab
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi Everyone,

I have a visualforce page which has notes and Attachments related list on it. 
There is a button on the page which when clicked should download a pdf and attach it in the Notes and Attachments related list.

When I click on View link on the related list (image1), I get the error(Image2).

Code called on the command button is:
 public PageReference downloadPDF(){
        System.debug(' Inside downloadPDF1 ');
      PageReference pdf =  Page.EventsBudgetPDFVFP_New;
      pdf.getParameters().put('id',(String)eventBudget.id);
      pdf.setRedirect(true); 
        
      Blob b = null;
     if (Test.IsRunningTest())
        {
            b=Blob.valueOf('UNIT.TEST');
        }
        else
        { 
            b = pdf.getContent();
        }
        Attachment att = new Attachment();
        att.body = b;
        att.Name = eventBudget.Name +' - '+ '.pdf';
        att.ParentId = eventBudget.Id;
        insert att; 
     return new PageReference('/apex/ViewEventsBudget?id='+eventBudget.id);   
     }

Is there any thing that I am missing?
The same is working for other pages but not for this.

Thanks,
NazneenNotes and AttachmnetsError
Hi Everyone,

There is an apex code that throws an exception 'System.ListException: List index out of bounds: 0
Class.NewEventsBudget.<init>: line 14, column 1' .

This exception occurs only in the sandbox and is working completely fine in production. I have pasted the code below. Line marked in bold is line 14 of the code. Can some body please help me with this? 


This is the code:
   public class NewEventsBudget {
    public Events_Budget__c eventBudget {get; set;}
    public Order order {get; set;}
    public List<selectOption> suppliers {get; set;}
    
    public string newSectionType {get; set;}
    public boolean isSalesforce {get; set;}
    
    public List<WrapperMainSection> wmainSectionList {get;set;}
    public NewEventsBudget(ApexPages.StandardController stdController){
        this.eventBudget = (Events_Budget__c)stdController.getRecord(); 
        Id proEventId = apexpages.currentpage().getparameters().get('peid');
        
        order = [select Id,Job_Number__c,Project_Name__c,Name from Order where id = :proEventId][0];
        eventBudget.Project_Event_Number__c = order.Id;
        eventBudget.Conversion_Rate__c = 1.0;
        string jobNumber = order.Job_Number__c;
        wmainSectionList = new List <WrapperMainSection>();
        suppliers = new List<selectOption>();
        suppliers.add(new SelectOption('','-'));
        for(Account a : [select name,RecordType.Name, id from Account where RecordType.Name = 'IE Supplier' order by Name]){
            suppliers.add(new selectOption(a.Name, a.Name)); 
        }

Thanks,
Nazneen
 
Hi Everyone,

There is an apex code that throws an exception 'System.ListException: List index out of bounds: 0
Class.NewEventsBudget.<init>: line 14, column 1' .

This exception occurs only in the sandbox and is working completely fine in production. I have pasted the code below. Line marked in bold is line 14 of the code. Can some body please help me with this? 


This is the code:
   public class NewEventsBudget {
    public Events_Budget__c eventBudget {get; set;}
    public Order order {get; set;}
    public List<selectOption> suppliers {get; set;}
    
    public string newSectionType {get; set;}
    public boolean isSalesforce {get; set;}
    
    public List<WrapperMainSection> wmainSectionList {get;set;}
    public NewEventsBudget(ApexPages.StandardController stdController){
        this.eventBudget = (Events_Budget__c)stdController.getRecord(); 
        Id proEventId = apexpages.currentpage().getparameters().get('peid');
        
        order = [select Id,Job_Number__c,Project_Name__c,Name from Order where id = :proEventId][0];
        eventBudget.Project_Event_Number__c = order.Id;
        eventBudget.Conversion_Rate__c = 1.0;
        string jobNumber = order.Job_Number__c;
        wmainSectionList = new List <WrapperMainSection>();
        suppliers = new List<selectOption>();
        suppliers.add(new SelectOption('','-'));
        for(Account a : [select name,RecordType.Name, id from Account where RecordType.Name = 'IE Supplier' order by Name]){
            suppliers.add(new selectOption(a.Name, a.Name)); 
        }

Thanks,
Nazneen