DT Worksheet

{!med.Name}
Here is the extension, if relevant: public with sharing class GetMedicals { public List lstMedicals{get;set;} public GetMedicals() { } public GetMedicals(ApexPages.StandardController controller) { lstMedicals = [Select Id, Name, Provider_Name__c, Disburse__c, Disbursement_Note__c From Medical_Bill__c LIMIT 10 ]; } public pagereference saveme() { try { update lstMedicals; } catch(Exception e) { System.debug('Exception occurred '+String.valueOf(e)); } return NULL; } } ​​​​​​​", "answerCount": 1, "upvoteCount": 0, "datePublished": "2020-01-07T14:24:02.000Z", "author": { "@type": "Person", "name": "Jacob Elliott", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000EDSKfQAP", "affiliation": { "@type": "Organization", "name": "HawkLaw" } }, "acceptedAnswer": { "@type": "Answer", "text": "I ended up using a validation rule on the object and using apex to display that same error when the dml update failed. Page:

DT Worksheet

{!med.Name}
Extension: public with sharing class GetMedicals { public List lstMedicals{get;set;} public GetMedicals() { } public GetMedicals(ApexPages.StandardController controller) { lstMedicals = [Select Id, Name, Provider_Name__c, Disburse__c, Disbursement_Note__c From Medical_Bill__c LIMIT 10 ]; } public pagereference saveme() { try { update lstMedicals; } catch(DmlException ex) { ApexPages.addMessages(ex); } return NULL; } }  ", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4BMHSA3", "datePublished": "2020-01-08T14:36:17.000Z", "author": { "@type": "Person", "name": "Jacob Elliott", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000EDSKfQAP", "affiliation": { "@type": "Organization", "name": "HawkLaw" } } }, "suggestedAnswer": [] } } Skip to main content
Jacob Elliott (HawkLaw) ha fatto una domanda in #Visualforce
Hi all! Any help will be greatly appreciated! 

I have a VF page that is a list of records(Medical Bills) and the user can use inline edit to say whether or not we should pay(Disburse__c) the bill and give a reason why(Note/ Disbursement_Note__c). 

If the user decides to select no to pay(Disburse__c) then the Note field becomes required and if they try to save without leaving a note I would like to populate a Toast Message using  sforce.one.showToast().

The javascript function will need to iterate through a list of the medical bills, see if there is a Pay/Disburse value of no and a Note with the Value of Null and if so, display the toast message. 

Here is the VF Page:

 

<apex:page standardController="litify_pm__Matter__c" extensions="GetMedicals" lightningStylesheets="true">

<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

<head>

<script>

function showToast() {

var myList = new Array();

myList = ‘{!lstMedicals}’;

boolean showError = false;

for(Medical_Bill__c med : myList){

if(med.Disburse__c == 'No' || med.Disbursement_Note__c == null){

showError = true;

}

}

if(showError){

sforce.one.showToast({

"title": "Error!",

"message": "Error.",

"type": "success"

});

}

else {

sforce.one.showToast({

"title": "Success!",

"message": "Success.",

"type": "success"

});

}

}

</script>

</head>

<apex:pageMessages id="showmsg"></apex:pageMessages>

<apex:form >

<apex:pageBlock mode="inlineEdit">

<div id="header" class="headerborder">

<p id="title">DT Worksheet</p>

</div>

<apex:pageBlockButtons location="bottom">

<apex:commandButton id="saveButton" value="Save" rerender="showmsg" onclick="showToast();"/>

<apex:commandButton id="cancelButton" value="Cancel" rerender="showmsg"/>

</apex:pageBlockButtons>

<div class="tableborder">

<apex:pageBlockTable value="{!lstMedicals}" var="med">

<apex:column headerValue="Medical Bill Number" headerClass="headerStyle">

<apex:actionRegion >

<apex:outputLink value="/{!med.Id}" styleClass="link">

{!med.Name}

</apex:outputLink>

</apex:actionRegion>

</apex:column>

<apex:column headerValue="Provider" headerClass="headerStyle">

<apex:actionRegion >

<apex:outputField value="{!med.Provider_Name__c}">

</apex:outputField>

</apex:actionRegion>

</apex:column>

<apex:column headerValue="Pay?" headerClass="headerStyle">

<apex:actionRegion >

<apex:outputField value="{!med.Disburse__c}">

<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" id="pay"/>

</apex:outputField>

</apex:actionRegion>

</apex:column>

<apex:column headerValue="Notes" headerClass="headerStyle">

<apex:actionRegion >

<apex:outputField value="{!med.Disbursement_Note__c}">

<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" id="note"/>

</apex:outputField>

</apex:actionRegion>

</apex:column>

</apex:pageBlockTable>

</div>

</apex:pageBlock>

</apex:form>

</apex:page>

Here is the extension, if relevant:

public with sharing class GetMedicals {

public List<Medical_Bill__c> lstMedicals{get;set;}

public GetMedicals() {

}

public GetMedicals(ApexPages.StandardController controller)

{

lstMedicals = [Select Id, Name, Provider_Name__c, Disburse__c, Disbursement_Note__c From Medical_Bill__c LIMIT 10 ];

}

public pagereference saveme()

{

try

{

update lstMedicals;

}

catch(Exception e)

{

System.debug('Exception occurred '+String.valueOf(e));

}

return NULL;

}

}

​​​​​​​
1 risposta
  1. 8 gen 2020, 14:36
    I ended up using a validation rule on the object and using apex to display that same error when the dml update failed.

    Page:

    <apex:page>

    <apex:form id="form">

    <apex:pageBlock mode="inlineEdit" id="pageblock1">

    <div id="header" class="headerborder">

    <p id="title">DT Worksheet</p>

    </div>

    <apex:pageBlockButtons location="bottom">

    <apex:commandButton id="saveButton" value="Save" rerender="" action="{!saveme}"/>

    <apex:commandButton id="cancelButton" value="Cancel" rerender=""/>

    </apex:pageBlockButtons>

    <div class="tableborder" id="border">

    <apex:pageBlockTable value="{!lstMedicals}" var="med" id="table">

    <apex:column headerValue="Medical Bill Number" headerClass="headerStyle">

    <apex:actionRegion >

    <apex:outputLink value="/{!med.Id}" styleClass="link">

    {!med.Name}

    </apex:outputLink>

    </apex:actionRegion>

    </apex:column>

    <apex:column headerValue="Provider" headerClass="headerStyle">

    <apex:actionRegion >

    <apex:outputField value="{!med.Provider_Name__c}">

    </apex:outputField>

    </apex:actionRegion>

    </apex:column>

    <apex:column headerValue="Pay?" headerClass="headerStyle" id="column1">

    <apex:actionRegion id="actionRegion1">

    <apex:outputField value="{!med.Disburse__c}" id="pay">

    <apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton"/>

    </apex:outputField>

    </apex:actionRegion>

    </apex:column>

    <apex:column headerValue="Notes" headerClass="headerStyle">

    <apex:actionRegion >

    <apex:outputField value="{!med.Disbursement_Note__c}">

    <apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" id="note"/>

    </apex:outputField>

    </apex:actionRegion>

    </apex:column>

    </apex:pageBlockTable>

    </div>

    </apex:pageBlock>

    </apex:form>

    </html>

    </apex:page>

    Extension:

    public with sharing class GetMedicals {

    public List<Medical_Bill__c> lstMedicals{get;set;}

    public GetMedicals() {

    }

    public GetMedicals(ApexPages.StandardController controller)

    {

    lstMedicals = [Select Id, Name, Provider_Name__c, Disburse__c, Disbursement_Note__c From Medical_Bill__c LIMIT 10 ];

    }

    public pagereference saveme()

    {

    try

    {

    update lstMedicals;

    }

    catch(DmlException ex)

    {

    ApexPages.addMessages(ex);

    }

    return NULL;

    }

    }

     
0/9000