function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Scott Janis 19Scott Janis 19 

VF page not showing up in lightining

I have a list button from the account record that called up this VF page. The works perfectrly in classic but the page doesn not load in lighteing. Why?
<apex:page standardController="Account"    extensions="UploadAttachmentController">

 <apex:sectionHeader title="{!Account.Name}" subtitle="Attach File"/>
 
 <apex:form id="form_Upload">
 <apex:pageBlock >

 <apex:pageBlockButtons >
   <apex:commandButton action="{!back}" value="Back to {!Account.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="Type" for="type"/>
      <apex:selectList value="{!selectedType}" size="1" id="type"> 
        <apex:selectOption itemValue="MSA" itemLabel="MSA"/>
        <apex:selectOption itemValue="NDA" itemLabel="NDA"/>

      </apex:selectList>
    </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>
Dushyant SonwarDushyant Sonwar
Could you post the screenshot what issue you are facing? I tried with above code and created the list button ,  it is working fine.
Scott Janis 19Scott Janis 19
In lightning?
Scott Janis 19Scott Janis 19
This is the error in lightning. It just comes up blank.
Dushyant SonwarDushyant Sonwar
Scott , It seems to be issue in your controller i think.

Could you post the code of apex class ?

User-added image
Scott Janis 19Scott Janis 19
public class UploadAttachmentController {
    
    public String selectedType {get;set;}
    public Boolean selectedAwesomeness {get;set;}
    public String description {get;set;}
    private Account Account {get;set;} 
    public String fileName {get;set;}
    public Blob fileBody {get;set;}
    
    public UploadAttachmentController(ApexPages.StandardController controller) { 
        this.account = (Account)controller.getRecord();
    }   
    
    // creates a new Account_Attachment__c record
    private Database.SaveResult saveCustomAttachment() {
        Account_Attachment__c obj = new Account_Attachment__c();
        obj.Account__c = Account.Id; 
        obj.Description__c = Description;
        obj.Type_of_Document_of_File__c = selectedType;
        
        // fill out cust obj fields
        return Database.insert(obj);
    }
    
    // create an actual Attachment record with the Account_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 Account_Attachment__c record
    *  2. Insert new Attachment with the new Account_Attachment__c record as parent
    *  3. Update the Account_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 {
                //  the custom attachment record with some attachment info
                Account_Attachment__c customAttachment = [select id from Account_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('/'+Account.Id);
    }
    
    public PageReference back() {
        return new PageReference('/'+Account.Id);
    }     

}
Scott Janis 19Scott Janis 19
public class UploadAttachmentController {
    
    public String selectedType {get;set;}
    public Boolean selectedAwesomeness {get;set;}
    public String description {get;set;}
    private Account Account {get;set;} 
    public String fileName {get;set;}
    public Blob fileBody {get;set;}
    
    public UploadAttachmentController(ApexPages.StandardController controller) { 
        this.account = (Account)controller.getRecord();
    }   
    
    // creates a new Account_Attachment__c record
    private Database.SaveResult saveCustomAttachment() {
        Account_Attachment__c obj = new Account_Attachment__c();
        obj.Account__c = Account.Id; 
        obj.Description__c = Description;
        obj.Type_of_Document_of_File__c = selectedType;
        
        // fill out cust obj fields
        return Database.insert(obj);
    }
    
    // create an actual Attachment record with the Account_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 Account_Attachment__c record
    *  2. Insert new Attachment with the new Account_Attachment__c record as parent
    *  3. Update the Account_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 {
                //  the custom attachment record with some attachment info
                Account_Attachment__c customAttachment = [select id from Account_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('/'+Account.Id);
    }
    
    public PageReference back() {
        return new PageReference('/'+Account.Id);
    }     

}
Dushyant SonwarDushyant Sonwar
Did you created the list button with Content Source Option as URL?

Could you post the url that you are using?

It will be help debugging the issue.

User-added image
Scott Janis 19Scott Janis 19
[image: image.png] Scott Janis Senior Systems Business Engineer Butterfly Network Inc. 251 W 30th Street, 11th Floor New York, NY 10001 917 902 6627 https://www.butterflynetwork.com/ Join Us! Link to the job openings at 4C https://www.4catalyzer.com/#opportunities
Scott Janis 19Scott Janis 19
Button for VF page
Scott Janis 19Scott Janis 19
yes content source URL
Dushyant SonwarDushyant Sonwar

i used the same way to redirect the button usign URLFor like you did  , it is working in my org.

Could you post screenshot of where you are using this list button?
Dushyant SonwarDushyant Sonwar
Is your atttachment  a custom object?
Scott Janis 19Scott Janis 19
Its on the account as a reAdd attachment button which launched the VF page.lated list button off of the 'attachments' child list 
Scott Janis 19Scott Janis 19
yes....'attachment' is a customer object but the fule upload is still stored in the standard file attachment object. 
Scott Janis 19Scott Janis 19
The object is actually called 'Account_Attachment__c' and is also referenced on the APEX code you asked me to send you earlier. 
Dushyant SonwarDushyant Sonwar
From my assumptions , you are using account__c as parent lookup/masterdetail field

So please change to below
{!URLFOR("/apex/AccountFile?id="+ Account_Attachment__c.Account__c )}
This will work fine.

Hope this helps!
 
Scott Janis 19Scott Janis 19
No ...it did not work. This issue seems to be specific to ligjtening. In cassic the redirect works perfectly.