• Alan Cardel 13
  • NEWBIE
  • 5 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi all, need some help...

I have a Salesforce Site that has a VF page that people can attach files to.  The page seems to be working well, but if there is any issue, the user gets the generic "Unauthorized" page with no error messages at all.  I am looking for a way to get an error log emailed to me so that I can troubleshoot the issue.  I have attached the Apex class that allows the user to attach the attachments to the VF page.  Any help you can provide will be greatly appreciated.
 
public class AddMultipleAttachments {
    public Incident_Reports__c objIncidentReport { get; set; }
    public Attachment attachment1 { get; set; }
    public Attachment attachment2 { get; set; }
    public Attachment attachment3 { get; set; }
    public Attachment attachment4 { get; set; }
    public Attachment attachment5 { get; set; }
    public Attachment attachment6 { get; set; }
    public Attachment attachment7 { get; set; }
    public Attachment attachment8 { get; set; }
    public Attachment attachment9 { get; set; }
    public Attachment attachment10 { get; set; }
    private ApexPages.StandardController controller;

    public AddMultipleAttachments (ApexPages.StandardController stdController) {
        this.controller = stdController;
        // Record and Attachments to be inserted
        this.objIncidentReport = (Incident_Reports__c)(this.controller.getRecord());
        this.attachment1 = new Attachment();
        this.attachment2 = new Attachment();
        this.attachment3 = new Attachment();
        this.attachment4 = new Attachment();
        this.attachment5 = new Attachment();
        this.attachment6 = new Attachment();
        this.attachment7 = new Attachment();
        this.attachment8 = new Attachment();
        this.attachment9 = new Attachment();
        this.attachment10 = new Attachment();
    }

    public PageReference createRecordAndAttachments() {
        Savepoint sp = Database.setSavepoint();

        try {
            // Insert the record
            this.objIncidentReport = (Incident_Reports__c)(this.controller.getRecord());
            insert this.objIncidentReport;

            // Insert Attachments;
            List<Attachment> toInsert = new List<Attachment>();

            if (this.attachment1.Name != null) {
                this.attachment1.ParentId = this.objIncidentReport.Id;
                toInsert.add(this.attachment1);
            }

            if (this.attachment2.Name != null) {
                this.attachment2.ParentId = this.objIncidentReport.Id;
                toInsert.add(this.attachment2);
            }

            if (this.attachment3.Name != null) {
                this.attachment3.ParentId = this.objIncidentReport.Id;
                toInsert.add(this.attachment3);
            }
            
            if (this.attachment4.Name != null) {
                this.attachment4.ParentId = this.objIncidentReport.Id;
                toInsert.add(this.attachment4);
            }
            
            if (this.attachment5.Name != null) {
                this.attachment5.ParentId = this.objIncidentReport.Id;
                toInsert.add(this.attachment5);
            }
            
            if (this.attachment6.Name != null) {
                this.attachment6.ParentId = this.objIncidentReport.Id;
                toInsert.add(this.attachment6);
            }
            
            if (this.attachment7.Name != null) {
                this.attachment7.ParentId = this.objIncidentReport.Id;
                toInsert.add(this.attachment7);
            }
            
            if (this.attachment8.Name != null) {
                this.attachment8.ParentId = this.objIncidentReport.Id;
                toInsert.add(this.attachment8);
            }
            
            if (this.attachment9.Name != null) {
                this.attachment9.ParentId = this.objIncidentReport.Id;
                toInsert.add(this.attachment9);
            }
            
            if (this.attachment10.Name != null) {
                this.attachment10.ParentId = this.objIncidentReport.Id;
                toInsert.add(this.attachment10);
            }

            if (!toInsert.isEmpty()) {
                insert toInsert;
            }
        } catch(Exception ex) {
            Database.rollback(sp);
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage());
            ApexPages.addMessage(msg);
        }

 // Go to Incident Report Thank you page
        PageReference p = Page.IR_Thanks;
        p.setRedirect(true);
        return p;
        
    }
    
 // If cancel is clicked go back to entry page
        public PageReference cancelRequest() {  
                pageReference c = new PageReference('http://teamalliance.ninja');
                c.setRedirect(true);
                return c;
        
        }
}

 
Can any one help me in increasing the code coverage i am a newbee to classes.