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
RyanBakerRyanBaker 

Refresh page during form submittal

I'm still a novice VF developer (but trying) and am working on a volunteer gig helping a non-profit in my community. Everything I've done is working fine, except for one thing. I have a VF page served up a SF Site. The VF page lists families in need (for the upcoming Christmas holiday). Interested people can browse the list and click a link to "sponsor" a specific family. Once a family is sponsored, a checkbox is checked and the family is removed from the VF page. However if two users are looking at the same family on the website at the same time and both try sponsoring that family, we end up with two sponsors for one family. What I want to do is before/during the "click to sponsor" process, I want to "refresh the page or somehow check to make sure that the family is still "not sponsored". If sponsor1 clicks the link, 30 seconds before sponsor 2, sponsor 2 should get a message on the page saying that family is no longer available.

 

Here's the code for the page where sponsors search for families. Sponsors click the link toward the bottom (Page.SOGSponsor):

 

<apex:page Controller="DataTableExampleController" docType="html-5.0" sidebar="false" showHeader="false" standardStylesheets="false" cache="false" >
<apex:stylesheet value="{!$Resource.SOGStyle}"/>

<head>

<apex:includescript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"/>

<style type="text/css" title="currentStyle">
@import "{!URLFOR($Resource.DataTables, 'media/css/demo_page.css')}";
@import "{!URLFOR($Resource.DataTables, 'media/css/demo_table.css')}";
@import "{!URLFOR($Resource.DataTables, 'media/css/ColReorder.css')}";
@import "{!URLFOR($Resource.DataTables, 'media/css/ColVis.css')}";
@import "{!URLFOR($Resource.DataTables, 'media/css/TableTools.css')}";
@import "{!URLFOR($Resource.DataTables, 'media/css/ColumnFilterWidgets.css')}";
@import "{!URLFOR($Resource.DataTables, 'media/css/demo_table_jui.css')}";
@import "{!URLFOR($Resource.DataTables, 'media/examples_support/themes/smoothness/jquery-ui-1.8.4.custom.css')}";
</style>

<script src="{!URLFOR($Resource.DataTables, 'media/js/jquery.dataTables.min.js')}"></script>
<script src="{!URLFOR($Resource.DataTables, 'media/js/jquery.dataTables.js')}"></script>
<script src="{!URLFOR($Resource.DataTables, 'media/js/ColVis.js')}"></script>
<script src="{!URLFOR($Resource.DataTables, 'media/js/ZeroClipboard.js')}"></script>
<script src="{!URLFOR($Resource.DataTables, 'media/js/TableTools.js')}"></script>
<script src="{!URLFOR($Resource.DataTables, 'media/js/ColumnFilterWidgets.js')}"></script>

<script type="text/javascript" charset="UTF-8">

$(document).ready( function () {
var oTable = $('#familytable').dataTable( {
"bProcessing": true,
"bSort": true,
"bAutoWidth": false,
"bJQueryUI": true,
"bPaginate": true,
"sPaginationType": "full_numbers",
"sDom": '<"top">iWlfrt<"bottom" p>',

"aoColumnDefs": [ { "bVisible": false, "aTargets": [ ] }],
"oColumnFilterWidgets": { "aiExclude": [ 0, 2, 3, 4 ] }
});
});

</script>

 

</head>

<body>
<a href="top" />

<h2>Family Search</h2>

<table class="display" id="familytable">

<thead>
<tr>
<th>Family ID</th>
<th># of Children</th>
<th>School</th>
<th>Wishes</th>
<th>&nbsp;</th></tr>
</thead>

<tfoot>
<tr>
<th>Family ID</th>
<th># of Children</th>
<th>School</th>
<th>Wishes</th>
<th>&nbsp;</th>
</tr>
</tfoot>

<tbody>
<apex:repeat value="{!Family}" var="c">
<tr>
<td align="center">{!c.Name}</td>
<td align="center">{!c.Number_of_Children__c}</td>
<td>{!c.Schools__c}</td>
<td>{!c.Wishes__c}</td>

<td><apex:outputLink value="{!$Page.SOGSponsor}?id={!c.Name}&name={!c.ID}">Click here to sponsor</apex:outputLink> </td> </tr>
</apex:repeat>
</tbody>
</table>
</body>

</apex:page>

Ashish_SFDCAshish_SFDC
HI Ryan, 

The code is too long, but the logic is -

You should have a Sponsor Field on a Family. 

Before you start processing, check if sponsor ISBLANK only then porceed else throw exception Already Sponsored. 

Regards,
Ashish