• chyun87
  • NEWBIE
  • 10 Points
  • Member since 2014
  • Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
Dear SF experts,
I have a drop down option in my visualforce page where the 'onchange' event calls a jQuery function called 'selectMapping()' that renders the appropriate outputpanel. There was a reason for using the onchange to trigger a jQuery function as opposed to using the native 'actionSupport' function along with the 'rerender' option in visualforce. It was because of performance issues due to the high viewstate size and took forever to re-render different sections of the page using the native approach.

However, an issue with the current implementation is that when clicking on 'save', even though the unused outputpanel is hidden from the page, the inputfields from the hidden outputpanel show a validation error, complaining an input is required. So I have tried disabling hidden inputfields to skip the validation on required fields, but had no luck.
I have tried the option of setting "immediate=true" on the save button, but this has caused some inputfields to be null.

Any help would be appreciated! 
 
<apex:pageBlockButtons location="bottom">
    <apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>

<apex:pageBlockSection columns="1">
    <apex:selectList id="chooseMappingOption" size="1" onchange="selectMapping()" label="Choose Option" multiselect="false">
        <apex:selectOption itemValue="MappingPanelAccountOnly" itemLabel="Map to Account Only" />
        <apex:selectOption itemValue="MappingPanelAccountBrand" itemLabel="Map to Account and Brand" />
    </apex:selectList>
</apex:pageBlockSection>

<apex:outputPanel id="MappingPanelAccountOnly">
    <apex:outputPanel>
        <apex:pageBlockSection columns="1">
            <apex:inputField label="Account Name" value="{!account.name}" id="accNameForAccOnly" />
        </apex:pageBlockSection>
        <apex:pageBlockSection columns="1">
            <apex:inputField label="Person Name" value="{!account.Person__c}" id="personNameForAccOnly" />
        </apex:pageBlockSection>
    </apex:outputPanel>
</apex:outputPanel>

<apex:outputPanel id="MappingPanelAccountBrand">
    <apex:inputField value="{!accBrandJunc.Account__c}" id="accNameForAccBrand" >
    ...
</apex:outputPanel>

<script type="text/javascript">
    j$('[id$=MappingPanelAccountBrand]').hide();

    function selectMapping() {
        if (j$('[id$=chooseMappingOption]').val() == "MappingPanelAccountOnly") {
            
            // Hide irrelevant fields
            j$('[id$=MappingPanelAccountBrand]').hide();

            // Disable hidden input fields
            j$('[id$=accNameForAccBrand]').prop('disabled', true);
            j$('[id$=brandNameForAccBrand]').prop('disabled', true);
            j$('[id$=personNameForAccBrand]').prop('disabled', true);
            
            // Show fields
            j$('[id$=MappingPanelAccountOnly]').show();
            j$('[id$=isAccountBrand]').val(false);
        } else {
            ...
        }
    }
</script>

 
Dear SF experts,
I have a visualforce page in read-only mode as the collection size in my controller exceeds the maximum size of 1,000. 
However, on the same page I also need to save inputfields but DML operations are not allowed on a read-only page.
On save, the following error page is shown:

Visualforce ErrorHelp for this Page
System.LimitException: Too many DML statements: 1
Error is in expression '{!save}' in component <apex:commandButton>

Are there any workarounds to kill 2 birds with 1 stone? ie allow a collection size of more than 1000 records AND have the page perform DML operations.
I'm aware I could use pagination to query 1000 records iteratively but I would like to avoid this option as I need a search feature on the page which is only useful if ALL records are loaded at once.

Would I be able to save records if I used a popup window + javascript remoting while the parent window is read-only?

Any inputs would be much appreciated!
Regards,
Dear SF experts,
I am currently trying to implement Remote Objects in Javascript to retrieve Accounts but having difficulty finding a workaround to query for more than the maximum limit of 100 records. Salesforce states that the maximum limit to return one batch of results is 100 but there is more than 2000 records that I need to query.  

Would I have to use offsets and batch query 100 records at a time?
Here is some sample code that I was working with:
j$(document).ready(function() {
            var acctTable = j$('[id$="accounttable"]').DataTable({
                "ajax": function(data, callback, settings) {
                    var acct = new SObjectModel.Account();
                    acct.retrieve({
                        orderby: [{
                            Name: 'ASC'
                        }],
                        limit: 1000
                    }, function(err, records) {
                        if (err) alert(err.message);
                        else {
                            callback({
                                'data': records
                            });
                        };
                    });
                },

Any advice would be appreciated!
Thanks.
Dear experts,
I've implemented Pat Patterson's Multiselect Picklist in my visualforce page using the example from:
https://developer.salesforce.com/blogs/developer-relations/2012/06/a-multiselect-picklist-visualforce-component.html

But I have found an issue which I am having difficulty resolving. Upon saving the visualforce page, if there is a validation error, then the values that were selected on the right options list disappears and the changes are lost. The actual record is not saved, but I still wanted the values to persist even if a refresh is caused by the validation error.
My understanding is that the save() action loops through the values in the rightOptions list to build a list of select options to insert, but because the validation error happens even before the save action is called, the data is not persisted.

For example, in the code below, any changes made to the allContacts and selectedContacts do not get persisted when the page is refreshed as a result of a validation error:
<c:MultiselectPicklist leftLabel="Available Contacts"
    leftOptions="{!allContacts}"
    rightLabel="Selected Contacts"
    rightOptions="{!selectedContacts}"
    size="14"
    width="150px"/>
Is there a workaround to still build the right options list during the validation stage?

Look forward to your answers. Thanks in advance!
 
Dear SF experts,
I have a visualforce page in read-only mode as the collection size in my controller exceeds the maximum size of 1,000. 
However, on the same page I also need to save inputfields but DML operations are not allowed on a read-only page.
On save, the following error page is shown:

Visualforce ErrorHelp for this Page
System.LimitException: Too many DML statements: 1
Error is in expression '{!save}' in component <apex:commandButton>

Are there any workarounds to kill 2 birds with 1 stone? ie allow a collection size of more than 1000 records AND have the page perform DML operations.
I'm aware I could use pagination to query 1000 records iteratively but I would like to avoid this option as I need a search feature on the page which is only useful if ALL records are loaded at once.

Would I be able to save records if I used a popup window + javascript remoting while the parent window is read-only?

Any inputs would be much appreciated!
Regards,
Dear SF experts,
I am currently trying to implement Remote Objects in Javascript to retrieve Accounts but having difficulty finding a workaround to query for more than the maximum limit of 100 records. Salesforce states that the maximum limit to return one batch of results is 100 but there is more than 2000 records that I need to query.  

Would I have to use offsets and batch query 100 records at a time?
Here is some sample code that I was working with:
j$(document).ready(function() {
            var acctTable = j$('[id$="accounttable"]').DataTable({
                "ajax": function(data, callback, settings) {
                    var acct = new SObjectModel.Account();
                    acct.retrieve({
                        orderby: [{
                            Name: 'ASC'
                        }],
                        limit: 1000
                    }, function(err, records) {
                        if (err) alert(err.message);
                        else {
                            callback({
                                'data': records
                            });
                        };
                    });
                },

Any advice would be appreciated!
Thanks.