3

I have a page like below

<apex:page controller="testcontroller" readonly="true">
........

</apex:page>

For Making query to search data from million records i put @readonly

I am sure it is not possible to perform DML statement form @readonly page

Can anybody suggest way to perform DML statement from the page

Thanks in advance

1
  • 3
    If you want to perform DML then I thing you need to remove readonly or making it false otherwise you can't use DML from page or controller.As Defined By the Salesforce:"In read-only mode, a page may not execute any DML operations, but the limit on the number of records retrieved is relaxed from 50,000 to 1 million rows. It also increases the number of items in a collection that can be handled by iteration components, from 1,000 to 10,000. If not specified, this value defaults to false."
    – Tepsi
    Commented Nov 22, 2013 at 11:37

2 Answers 2

2

You either make your page read only and you don't get to use DML, or you use DML and don't make your page Read-only.

The purpose of making a page or controller read only is specifically to be able to access and use large amounts of data...primarily for display purposes.

If you have a large amount of data to act upon, there are patterns you can use implement in your page to iterate over that data and only act on a subset of those records such as using StandardSetController which offers pagination for most data SObjects, or using the SOQL offsets feature.

Here's a blog post on using StandardSetController to get started with that.

-2

Yes... you can do with the help of @RemoteAction

VisualForce:

<apex:page controller="AccountRemoteActionController" readonly="true">
<script type="text/javascript">
function getAccountJS() 
{
    //get the values of input text and place into the variable.
    var accountNameJS = document.getElementById('accName').value;        
    AccountRemoteActionController.getAccount( accountNameJS, 
    function(result, event)
    {

      alert('event.status==>'+event.status);
      alert('event.type === '+event.type);
      alert('event.message ==>'+event.message);
        if (event.status) 
        {
            // demonstrates how to get ID for HTML and Visualforce tags
            document.getElementById("{!$Component.theBlock.thePageBlockSection.theFirstItem.accId}").innerHTML = result.Id;
            document.getElementById("{!$Component.theBlock.thePageBlockSection.theSecondItem.accNam}").innerHTML = result.Name;
        } 
        else if (event.type === 'exception') 
        {
            document.getElementById("errors-js").innerHTML = event.message;
        } else 
        {
            document.getElementById("errors-js").innerHTML = 'No Records Found..';
        }
    }, {escape:true});
}
</script>
Account Name :<input id="accName" type="text" />
<button onclick="getAccountJS()">Get Account</button>
<div id="errors-js"> </div>
<apex:pageBlock id="theBlock">
    <apex:pageBlockSection id="thePageBlockSection" columns="2">
        <apex:pageBlockSectionItem id="theFirstItem">
            <apex:outputText id="accId"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem id="theSecondItem" >
            <apex:outputText id="accNam" />
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
</apex:pageBlock>

ApexClass(@remoteAction):

global class AccountRemoteActionController{
public String accountName { get; set; }
public static Account account { get; set; }
//Default Constructor..
public AccountRemoteActionController() {

}

@RemoteAction
global static Account getAccount(String accountName) {
    account = [select id, name, phone, type, numberofemployees from Account where name = :accountName ];
    account.name = account.name+ 'ReadonlyUpdated';
    update account;
    return account;
}}

Output:

enter image description here

enter image description here

Let me know if you face any other issue.

Cheers!!! Pradeep

2
  • 2
    can you include your apex code as text, and not as an image? It really hurts the reusability of your answer. Commented Mar 22, 2019 at 13:31
  • 1
    @PradeepLandge Content needs to be edited into the body of your answer. Comments are meant to be temporary and for clarification.
    – David Reed
    Commented Mar 22, 2019 at 17:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .