• Jonathan Anspaugh 6
  • NEWBIE
  • 0 Points
  • Member since 2017


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
I am working on a file upload that will change 2 fields on the record when a document is uploaded. Right now I need to change the status and the date received fields when the file is uploaded through a visualforce page.

Currently my apex class is as follows:
public with sharing class cc_AppChecklist_List{ 

    public List<Application_Checklist__c> Records {get; set;} 
    String AppID = ApexPages.currentPage().getParameters().get('appid');
    
    public cc_AppChecklist_List(){ 
        Records = [SELECT Id, Name, CC_Document_Name__c, CC_Document_Status__c, CC_Date_Received__c,CC_Date_Requested__c, CC_Due_Date__c FROM Application_Checklist__c WHERE Application_CC__c = :AppID];    
    }
    
    //system.debug('-----ChecklistID')
    // Upload Code
    public Id itemId {get; set;}
    public Application_Checklist__c item {get; set;}
    public SObject obj {get; set;} 
    public Attachment file {
        get {
            system.debug('-----Item ID 1 ----- ' + itemId);
            if(file == null) {
                file = new Attachment();
            }
            return file;
        } 
        set;
    }
    private Boolean isOld {get; set;}

    public PageReference uploadFile() {
        PageReference pr = null;
        try {
            system.debug('-----ChecklistID ----- '+ itemId);
            file.ParentId = itemId;
            insert file;
            
            if(isOld) {
                item.CC_Date_Received__c = Date.today();
                item.CC_Document_Status__c = 'Received';
                update item;
            } else {
               obj.put('CC_Date_Received__c', Date.today());
               obj.put('CC_Document_Status__c','Received');
               update obj;
            } 
          
            pr = Page.cc_App_Status;
        } catch (Exception ex) {
            cc_App_BaseController.addError(Label.Upload_Attachment_Error);
            System.debug(ex.getMessage());
        } finally {
            file = null;
        }
        return pr;
    }
}

and the Visualforce page is as follows:
 
<apex:page showHeader="false" sidebar="false" controller="cc_AppChecklist_List" standardStylesheets="false" html-lang="en-US"> 

<style>
    .content a {
        color: #FFF !important;
        margin-top: 4%;
        font-size: 12px;
     }
</style>   
   
   
    <c:cc_App_Header />
    <c:cc_App_TopNav activeSection="Personal" />

    <div class="gridlock gridlock-16 appPage">
        <div class="page page_container clearfix"> 
            <div class="row page_row">
                <div class="content page_content max-push-1 max-14 desktop-push-1 desktop-14 tablet-full mobile-full margined">
                    
                    <div class="row page_row content_block background">
                        <div class="desktop-12 tablet-6 mobile-6 min-full left" >
                            <h1 style="margin: 0;">My Application Checklist Items</h1>
                        </div>
                        
                        <apex:pageBlock Id="Block" title=""> 
                            <apex:pageBlockTable value="{!Records}" var="Record" style="width:100%"> 
                                <apex:column style="width:35%"> 
                                    <apex:facet name="header">Checklist ID</apex:facet> 
                                    <apex:outputText value="{!Record.Id}"/> 
                                </apex:column> 
                                <apex:column style="width:35%"> 
                                    <apex:facet name="header">Checklist Name</apex:facet> 
                                    <apex:outputText value="{!Record.CC_Document_Name__c}"/> 
                                </apex:column> 
                                <apex:column style="width:10%"> 
                                    <apex:facet name="header">Status</apex:facet> 
                                    <apex:outputText value="{!Record.CC_Document_Status__c}"/> 
                                </apex:column> 
                                <!-- apex:column > 
                                    <apex:facet name="header">Date Requested</apex:facet> 
                                    <apex:outputText value="{0, date, MMMM d','  yyyy}">
                                        <apex:param value="{!Record.CC_Date_Requested__c}" /> 
                                    </apex:outputText>
                                </apex:column> 
                                <apex:column > 
                                    <apex:facet name="header">Date Due</apex:facet> 
                                    <apex:outputText value="{0, date, MMMM d','  yyyy}">
                                        <apex:param value="{!Record.CC_Due_Date__c}" /> 
                                    </apex:outputText>
                                </apex:column --> 
                                <apex:column style="width:15%"> 
                                    <apex:facet name="header">Date Received</apex:facet> 
                                    <apex:outputText value="{0, date, MMMM d','  yyyy}">
                                        <apex:param value="{!Record.CC_Date_Received__c}" /> 
                                    </apex:outputText>
                                </apex:column>
                                <apex:column style="width:40%"> 
                                    <apex:facet name="header">Action</apex:facet> 
                                    <apex:form >
                                         <apex:inputFile title="file_upload" value="{!file.body}" fileName="{!file.name}" id="file_upload" onchange="return checkFileSize(this);" rendered="{!Record.CC_Document_Status__c =='Required'}" />
                                         <apex:commandLink styleClass="btn app-btn-success" value="Upload" action="{!uploadFile}" rendered="{!Record.CC_Document_Status__c =='Required'}" >
                                             <apex:param name="FiletoUpload" value="{!Record.Id}" assignTo="{!itemId}"/>
                                         </apex:commandLink>
                                    </apex:form> 
                               </apex:column> 
                               
                            </apex:pageBlockTable> 
                        </apex:pageBlock> 
                    </div>
                    

                </div>
            </div>
        </div>
    </div>
   
    <!-- <c:App_Footer /> -->
</apex:page>

The goal is that when a file is uploaded:
- Attach the file to the record (individual checklist item)
- Update status to "Received"
- Set a Date Received of date of upload


Any advice since the upload currently works, the issue is getting the set of fields to update. 
I have a visualforce page with the following code:
<apex:page showHeader="false" sidebar="false" controller="cc_AppChecklist_List" standardStylesheets="false" html-lang="en-US">  
    <c:cc_App_Header />
    <c:cc_App_TopNav activeSection="Personal" />
    <div class="gridlock gridlock-16 appPage">
        <div class="page page_container clearfix"> 
            <div class="row page_row">
                <div class="content page_content max-push-1 max-14 desktop-push-1 desktop-14 tablet-full mobile-full margined">
                    
                    <div class="row page_row content_block background">
                        <div class="desktop-12 tablet-6 mobile-6 min-full left" >
                            <h1 style="margin: 0;">My Application Checklist Items</h1>
                        </div>
                        
                        <apex:pageBlock title=""> 
                            <apex:pageBlockTable value="{!Records}" var="Record" style="width:100%"> 
                                <apex:column style="width:35%"> 
                                    <apex:facet name="header">Checklist ID</apex:facet> 
                                    <apex:outputText value="{!Record.Id}"/> 
                                </apex:column> 
                                <apex:column style="width:35%"> 
                                    <apex:facet name="header">Checklist Name</apex:facet> 
                                    <apex:outputText value="{!Record.CC_Document_Name__c}"/> 
                                </apex:column> 
                                <apex:column style="width:10%"> 
                                    <apex:facet name="header">Status</apex:facet> 
                                    <apex:outputText value="{!Record.CC_Document_Status__c}"/> 
                                </apex:column> 
                                <!-- apex:column > 
                                    <apex:facet name="header">Date Requested</apex:facet> 
                                    <apex:outputText value="{0, date, MMMM d','  yyyy}">
                                        <apex:param value="{!Record.CC_Date_Requested__c}" /> 
                                    </apex:outputText>
                                </apex:column> 
                                <apex:column > 
                                    <apex:facet name="header">Date Due</apex:facet> 
                                    <apex:outputText value="{0, date, MMMM d','  yyyy}">
                                        <apex:param value="{!Record.CC_Due_Date__c}" /> 
                                    </apex:outputText>
                                </apex:column --> 
                                <apex:column style="width:15%"> 
                                    <apex:facet name="header">Date Received</apex:facet> 
                                    <apex:outputText value="{0, date, MMMM d','  yyyy}">
                                        <apex:param value="{!Record.CC_Date_Received__c}" /> 
                                    </apex:outputText>
                                </apex:column>
                                <apex:column style="width:40%"> 
                                    <apex:facet name="header">Action</apex:facet> 
                                    <apex:form >
                                         <apex:inputFile title="file_upload" value="{!file.body}" fileName="{!file.name}" id="file_upload" onchange="return checkFileSize(this);"/>
                                         <apex:commandButton styleClass="btn app-btn-success" value="Upload" action="{!uploadFile}" />
                                    </apex:form> 
                               </apex:column> 
                               
                            </apex:pageBlockTable> 
                        </apex:pageBlock> 
                   </div>
                
                    

                </div>
            </div>
        </div>
    </div>
   
    <!-- <c:App_Footer /> -->
</apex:page>

Control class:
public with sharing class cc_AppChecklist_List{ 

    public List<Application_Checklist__c> Records {get; set;} 
    String AppID = ApexPages.currentPage().getParameters().get('appid');
    
    public cc_AppChecklist_List(){ 
    Records = 
    [SELECT Id, Name, CC_Document_Name__c, CC_Document_Status__c, CC_Date_Received__c,CC_Date_Requested__c, CC_Due_Date__c FROM Application_Checklist__c WHERE Application_CC__c = :AppID];    
    }
    
    // system.debug('-----ChecklistID')
    // Upload Code
    private Id itemId {get; set;}
    public Application_Checklist__c item {get; set;}
    public SObject obj {get; set;} 
    public Attachment file {
        get {
            if(file == null) {
                file = new Attachment(ParentId = itemId);
            }
            return file;
        } 
        set;
    }
    private Boolean isOld {get; set;}

    public PageReference uploadFile() {
        PageReference pr = null;
        try {
            system.debug('-----ChecklistID'+itemId);
            insert file;
            if(isOld) {
                item.CC_Date_Received__c = Date.today();
                update item;
            } else {
                obj.put('CC_Date_Received__c', Date.today());
                obj.put('CC_Document_Status__c','Received');
                update obj;
            }
            pr = Page.cc_App_Status;
        } catch (Exception ex) {
            cc_App_BaseController.addError(Label.Upload_Attachment_Error);
            System.debug(ex.getMessage());
        } finally {
            file = null;
        }
        return pr;
    }
}

What I am trying to do is make the {!Record.Id} value for each row in the visualforce page pass across to the "itemId" value so the upload button will upload to the correct record. The upload function works when I hard code a value but I am having trouble passing the data to the variable when the upload button is selected. The goal of this is to query an application id and display all checklist items on the visualforce page with an upload button for each item. 
I need to solve a process automation issue. Right now I have a checkbox field called 'Can Contact' on the Contact and a custom object related to the contact via lookup field. What I need to do is:

A) Check the box on the contact is ANY of the related records has a 'Can Contact' that is 'true' 
--- This is already done and working properly through Process Builder

B) Uncheck the box on the contact if ALL of the related records have 'false' values for their field. 
--- This is where it is not working.

While the Process Automation works for A, I know I likely need to convert A & B into a trigger but am not sure where to begin or how to formulate the trigger since there are potentially multiple associated records to search.

My fields are:

Contact.Can_Contact__c
UHCU_Accounts__c.Can_Contact__c

Again the logic is:
A) If ANY related UHCU Account is checked, then check the Contact field.
B) If ALL related UHCU Accounts are not checked, then uncheck / have a non-checked field on the Contact

Any help would be greatly appreciated.
I have a visualforce page with the following code:
<apex:page showHeader="false" sidebar="false" controller="cc_AppChecklist_List" standardStylesheets="false" html-lang="en-US">  
    <c:cc_App_Header />
    <c:cc_App_TopNav activeSection="Personal" />
    <div class="gridlock gridlock-16 appPage">
        <div class="page page_container clearfix"> 
            <div class="row page_row">
                <div class="content page_content max-push-1 max-14 desktop-push-1 desktop-14 tablet-full mobile-full margined">
                    
                    <div class="row page_row content_block background">
                        <div class="desktop-12 tablet-6 mobile-6 min-full left" >
                            <h1 style="margin: 0;">My Application Checklist Items</h1>
                        </div>
                        
                        <apex:pageBlock title=""> 
                            <apex:pageBlockTable value="{!Records}" var="Record" style="width:100%"> 
                                <apex:column style="width:35%"> 
                                    <apex:facet name="header">Checklist ID</apex:facet> 
                                    <apex:outputText value="{!Record.Id}"/> 
                                </apex:column> 
                                <apex:column style="width:35%"> 
                                    <apex:facet name="header">Checklist Name</apex:facet> 
                                    <apex:outputText value="{!Record.CC_Document_Name__c}"/> 
                                </apex:column> 
                                <apex:column style="width:10%"> 
                                    <apex:facet name="header">Status</apex:facet> 
                                    <apex:outputText value="{!Record.CC_Document_Status__c}"/> 
                                </apex:column> 
                                <!-- apex:column > 
                                    <apex:facet name="header">Date Requested</apex:facet> 
                                    <apex:outputText value="{0, date, MMMM d','  yyyy}">
                                        <apex:param value="{!Record.CC_Date_Requested__c}" /> 
                                    </apex:outputText>
                                </apex:column> 
                                <apex:column > 
                                    <apex:facet name="header">Date Due</apex:facet> 
                                    <apex:outputText value="{0, date, MMMM d','  yyyy}">
                                        <apex:param value="{!Record.CC_Due_Date__c}" /> 
                                    </apex:outputText>
                                </apex:column --> 
                                <apex:column style="width:15%"> 
                                    <apex:facet name="header">Date Received</apex:facet> 
                                    <apex:outputText value="{0, date, MMMM d','  yyyy}">
                                        <apex:param value="{!Record.CC_Date_Received__c}" /> 
                                    </apex:outputText>
                                </apex:column>
                                <apex:column style="width:40%"> 
                                    <apex:facet name="header">Action</apex:facet> 
                                    <apex:form >
                                         <apex:inputFile title="file_upload" value="{!file.body}" fileName="{!file.name}" id="file_upload" onchange="return checkFileSize(this);"/>
                                         <apex:commandButton styleClass="btn app-btn-success" value="Upload" action="{!uploadFile}" />
                                    </apex:form> 
                               </apex:column> 
                               
                            </apex:pageBlockTable> 
                        </apex:pageBlock> 
                   </div>
                
                    

                </div>
            </div>
        </div>
    </div>
   
    <!-- <c:App_Footer /> -->
</apex:page>

Control class:
public with sharing class cc_AppChecklist_List{ 

    public List<Application_Checklist__c> Records {get; set;} 
    String AppID = ApexPages.currentPage().getParameters().get('appid');
    
    public cc_AppChecklist_List(){ 
    Records = 
    [SELECT Id, Name, CC_Document_Name__c, CC_Document_Status__c, CC_Date_Received__c,CC_Date_Requested__c, CC_Due_Date__c FROM Application_Checklist__c WHERE Application_CC__c = :AppID];    
    }
    
    // system.debug('-----ChecklistID')
    // Upload Code
    private Id itemId {get; set;}
    public Application_Checklist__c item {get; set;}
    public SObject obj {get; set;} 
    public Attachment file {
        get {
            if(file == null) {
                file = new Attachment(ParentId = itemId);
            }
            return file;
        } 
        set;
    }
    private Boolean isOld {get; set;}

    public PageReference uploadFile() {
        PageReference pr = null;
        try {
            system.debug('-----ChecklistID'+itemId);
            insert file;
            if(isOld) {
                item.CC_Date_Received__c = Date.today();
                update item;
            } else {
                obj.put('CC_Date_Received__c', Date.today());
                obj.put('CC_Document_Status__c','Received');
                update obj;
            }
            pr = Page.cc_App_Status;
        } catch (Exception ex) {
            cc_App_BaseController.addError(Label.Upload_Attachment_Error);
            System.debug(ex.getMessage());
        } finally {
            file = null;
        }
        return pr;
    }
}

What I am trying to do is make the {!Record.Id} value for each row in the visualforce page pass across to the "itemId" value so the upload button will upload to the correct record. The upload function works when I hard code a value but I am having trouble passing the data to the variable when the upload button is selected. The goal of this is to query an application id and display all checklist items on the visualforce page with an upload button for each item.