• Caroline Wojciechowski
  • NEWBIE
  • 0 Points
  • Member since 2016


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 0
    Replies
The visualforce page is used on the browser and mobile app, however there is a lot of dead space on the left hand side of the landing screen.

How can I format the visualforce page to recognize the size of the device being used and load/fit properly?

Current code:
<apex:page >
<script>
var strWindowFeatures = "location=yes,height=device_height,width=device_width,scrollbars=yes,status=yes";

//
var URL = "LINK";

//Call Function
var win = window.open(URL, "_parent", strWindowFeatures);

</script>
</apex:page>

 
I have created a custom object with button for customized attachment related list on the Contact object. However, when I go to create the actual record and upload the file, the Contact name does not come through (should be in the "Back to" button seen below).

Error

Controller:
public class UploadAttachmentController {
    
    public String selectedType {get;set;}
    public Boolean selectedAwesomeness {get;set;}
    public String description {get;set;}
    private Contact contact {get;set;} 
    public String fileName {get;set;}
    public Blob fileBody {get;set;}
    
    public UploadAttachmentController(ApexPages.StandardController controller) { 
        this.contact = (Contact)controller.getRecord();
    }   
    
    // creates a new Contact_Attachment__c record
    private Database.SaveResult saveCustomAttachment() {
        Contact_Attachment__c obj = new Contact_Attachment__c();
        obj.contact__c = contact.Id; 
        obj.description__c = description;
        // fill out cust obj fields
        return Database.insert(obj);
    }
    
    // create an actual Attachment record with the Contact_Attachment__c as parent
    private Database.SaveResult saveStandardAttachment(Id parentId) {
        Database.SaveResult result;
        
        Attachment attachment = new Attachment();
        attachment.body = this.fileBody;
        attachment.name = this.fileName;
        attachment.parentId = parentId;
        // inser the attahcment
        result = Database.insert(attachment);
        // reset the file for the view state
        fileBody = Blob.valueOf(' ');
        return result;
    }
    
    /**
    * Upload process is:
    *  1. Insert new Contact_Attachment__c record
    *  2. Insert new Attachment with the new Contact_Attachment__c record as parent
    *  3. Update the Contact_Attachment__c record with the ID of the new Attachment
    **/
    public PageReference processUpload() {
        try {
            Database.SaveResult customAttachmentResult = saveCustomAttachment();
        
            if (customAttachmentResult == null || !customAttachmentResult.isSuccess()) {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                  'Could not save attachment.'));
                return null;
            }
        
            Database.SaveResult attachmentResult = saveStandardAttachment(customAttachmentResult.getId());
        
            if (attachmentResult == null || !attachmentResult.isSuccess()) {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                  'Could not save attachment.'));            
                return null;
            } else {
                // update the custom attachment record with some attachment info
                Contact_Attachment__c customAttachment = [select id from Contact_Attachment__c where id = :customAttachmentResult.getId()];
                customAttachment.name = this.fileName;
                customAttachment.Attachment__c = attachmentResult.getId();
                update customAttachment;
            }
        
        } catch (Exception e) {
            ApexPages.AddMessages(e);
            return null;
        }
        
        return new PageReference('/'+contact.Id);
    }
    
    public PageReference back() {
        return new PageReference('/'+contact.Id);
    }     

}

Visualforce Page:
<apex:page standardController="Contact" tabStyle="Contact" extensions="UploadAttachmentController">

<apex:sectionHeader title="{!Contact.Name}" subtitle="Attach File"/>

<apex:form id="form_Upload">
<apex:pageBlock >

<apex:pageBlockButtons >
<apex:commandButton action="{!back}" value="Back to {!Contact.Name}"/>
 <apex:commandButton action="{!back}" value="Cancel"/>
 </apex:pageBlockButtons>
<apex:pageMessages />

 <apex:pageBlockSection columns="1">

<apex:pageBlockSectionItem >
<apex:outputLabel value="File" for="file_File"/>
<apex:inputFile id="file_File" value="{!fileBody}" filename="{!fileName}"/>
</apex:pageBlockSectionItem>

 <apex:pageBlockSectionItem >
 <apex:outputLabel value="Description" for="description"/>
 <apex:inputTextarea id="description" value="{!description}" rows="4" cols="50"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="" for="uploadBtn"/>
 <apex:commandButton id="uploadBtn" value="Attach File" action="{!processUpload}" />
 </apex:pageBlockSectionItem>

</apex:pageBlockSection>

 </apex:pageBlock>

 </apex:form>

</apex:page>