You need to sign in to do that
Don't have an account?
Test a VF controller
I'm not sure how to write a test class for a VF page and custom controller.
HERE IS THE CONTROLLER
public class UploadContentController { public ContentVersion contentToUpload {get;set;} public ContentVersion contentToUpload1 {get;set;} Id memberId; public Blob fileContent {get;set;} public UploadContentController(ApexPages.StandardController controller) { memberId = controller.getId(); contentToUpload = new ContentVersion(); contentToUpload1 = new ContentVersion(); } public PageReference uploadContents() { List<ContentWorkSpace> CWList = [SELECT Id, Name From ContentWorkspace WHERE Name = 'Contract Documents']; contentToUpload.VersionData = fileContent; insert contentToUpload; contentToUpload = [SELECT ContentDocumentId,ContractDocumentType__c FROM ContentVersion WHERE Id = :contentToUpload.Id]; ContentWorkspaceDoc cwd = new ContentWorkspaceDoc(); cwd.ContentDocumentId = contentToUpload.ContentDocumentId; cwd.ContentWorkspaceId = CWList.get(0).Id; insert cwd; List<Contract> con=[select id,accountid from contract where id=:memberId limit 1]; contentToUpload.ContractDocumentType__c=contentToUpload1.ContractDocumentType__c; contentToUpload.RelatedAccount__c=con[0].accountid; contentToUpload.RelatedContract__c=con[0].id; update contentToUpload; PageReference pg = new PageReference('/' + memberId); pg.setRedirect(true); return pg; } }
HERE IS THE VF PAGE
<apex:page standardController="Contract" extensions="UploadContentController"> <apex:sectionHeader title="Upload to Contract Library" subtitle="Upload Approved Contracts only."/> <apex:form > <apex:pageBlock > <apex:pageBlockSection title="Upload a File"> <apex:panelGrid columns="2"> Select File : <apex:inputFile fileName="{!contentToUpload.PathOnClient}" value="{!fileContent}"/> </apex:panelGrid> <apex:panelGrid columns="2"> Contract Document Type: <apex:inputField id="pick" value="{!contentToUpload1.ContractDocumentType__c}"/> </apex:panelGrid> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Upload" action="{!uploadContents}"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
I can write tests for triggers and such, but I am not too savvy on VF.
Any help would be appreciated.
Thanks,
Hey Robert,
The trick is knowing how to construct your controller extension.
If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!
-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator