0

Scenario: VF page is having two column:checkbox and fee name. Second column is coming from object 'Fee' which is child of 'App' object. An 'App' record can have multiple fees associated to it.Below table is having 6 fees:first 3 fees are from one 'App' record and other 3 fees are from another 'App' record. When a user click on 1st fee, it should automatically select all the fees from same 'App' i.e. next 2 fees. I have a working code but it is taking 4-5 seconds and need to reduce this lag.

enter image description here

VF Page code portion:{!FeeVos} will display fee name list.

<apex:pageblockSection columns="1" title="Fees" collapsible="false">
                <apex:pageBlocktable value="{!feeVOs}" var="fee" style="width:100%">
                    <apex:column headerValue="Pay" >

                    <input type="checkbox" onclick="check(this,'fee')" id="{!fee.f.Id}" />
                    </apex:column>
   <apex:column headerValue="Type" >
            <apex:outputField value="{!fee.f.type__c}" />
        </apex:column>
              </apex:pageBlocktable>
                </apex:pageblockSection>

Javascript in same vf page:Related_ID__C will have parent 'App' ID. This code is working but because of `sforce.connection.query' it is taking 4 seconds as of now.

function check(input, objectType ){

var inputCheckboxes = document.getElementsByTagName("input");
var voList = feeVOList;
var inputCheckbox = inputCheckboxes[0];
sforce.connection.sessionId = '{!$Api.Session_ID}';
var queryResult = sforce.connection.query('select Related_ID__c from MUSW__Fee__c where id IN (\'' +voList[0].split(',')[0]+ '\')');
var records = queryResult.getArray("records");
var output;
output=records[0].Related_ID__c; //Related_ID__c will have parent 'App' ID. 


for (var i = 0; i < inputCheckboxes.length; i++)
{
    var inputCheckbox = inputCheckboxes[i];
    if(inputCheckbox.getAttribute('type')=='checkbox')
    {
        for (var j = 0; j < voList.length; j++)
        {
            if (voList[j].indexOf(inputCheckbox.id) != -1)
            {                                       
 var queryResult = sforce.connection.query('select Related_ID__c from MUSW__Fee__c where id IN (\'' +voList[j].split(',')[0]+ '\')');
                var records = queryResult.getArray("records");

                        var account = records[0];
                        if(output==account.Related_ID__c){
                        inputCheckbox.checked = true;
                        } 


            }
        }                                     
    }
  } 
 }
4
  • If you develop your page in AngularJs it will more reliable and also reduce the time gap. Commented Apr 2, 2018 at 11:24
  • @PiyushKumar Is it not possible with javascript/jquery to reduce time as I am not aware of AngularJS. or can you give an example on this with AngularJS
    – devforce
    Commented Apr 2, 2018 at 11:45
  • 1
    Looks like you may be performing a query (a server roundtrip that takes hundreds of milliseconds) multiple times in the check function. Suggest you refactor so the query is only done once. (Or you can include all the data as JSON in the original page so no further roundtrips are needed.) This is an algorithm problem: using jQuery or Angular will make no difference.
    – Keith C
    Commented Apr 2, 2018 at 11:54
  • 1
    This code could be bulkified, and further, unless this data changes frequently, consider preloading the data in to the page, which can eliminate the API calls altogether. Finally, don't use sforce.connection calls in a Visualforce page if you can help it; the Remote Objects and Remote Action features do not use API calls, which means you won't burn through your daily limit nearly as fast.
    – sfdcfox
    Commented Apr 2, 2018 at 12:23

0

You must log in to answer this question.

Browse other questions tagged .