質問

I have created a DataBase.Batchable class in which I am inserting a custom object named Event__c

public class BatchCreateGCalendars implements Database.Batchable<SObject>, Database.Stateful, Database.AllowsCallouts {
 private List<Event__c> event_id;
}

I am creating, for example, 1000 records of type events and then using the statement

insert event_id;

Is this good, or is inserting each element one by one more appropriate? In my custom object I created only one custom field of type text(255), what is the maximum size of a list?

役に立ちましたか?

解決

There's not a defined limit for size of a list. I think the limit you'd eventually hit is heap size, which is currently 12 MB for a batch job. However, you need to be mindful of the number of records you can process via DML, which is currently 10,000.

他のヒント

Two questions combined there.

1) Yes, always do DML statements with a list of objects if you can. This will be executed faster, and will help you to avoid governor limits. (you should really check them out if you haven't)

2) edit: Used to be 1K few years ago, now it's just a heap size as Jeremy writes. You still have 1K for collection passed to visualforce though (10K if it's a page with readonly="true") and max 50K rows returned in all queries

Salesforce left the 1000 limit on visualforce components because rerender performance of large dataTables is pretty bad and can make the browser freeze up, something to watch out for.

With the work-around above the limit you need to look out for is heap size as the lists start to become large. If data is too big, I suggest using filtering (on SOQL) for reducing the data that needs to be returned to the Browser. (Select2 will do the trick)

There is couple of ways to do a work-around. Here is couple of them...

-Using rows and first params to set the offset and limit on the showing data:

<apex:repeat value="{!myCollection}" var="item" rows="1000" first="0">
{!item.text}
</apex:repeat>
<apex:repeat value="{!myCollection}" var="item" rows="1000" first="1000">
{!item.text}
</apex:repeat>
<apex:repeat value="{!myCollection}" var="item" rows="1000" first="2000">
{!item.text}
</apex:repeat>

-Using wrapper:

Visualforce page:

 <apex:page controller="thousandLimit">    
        <apex:pageBlock >
            <apex:repeat value="{!thousandBlocks}" var="block">
                <apex:pageBlockTable value="{!block.Accounts}" var="a">
                    <apex:column value="{!a.Name}"/>                
                </apex:pageBlockTable>
            </apex:repeat>
        </apex:pageBlock>  
    </apex:page>

Controller:

public class thousandLimit
    {
        private limitWrapper[] thousandBlocks = new limitWrapper[]{};

        private final integer listLimit;

        public thousandLimit()
        {
            listLimit = 999;
        }

        public limitWrapper[] getthousandBlocks()
        {
            thousandBlocks = new limitWrapper[]{};

            integer counter = 0;
            integer loopCount = 0;
            Account[] tmpAccount = new Account[]{};

            for(Account a:[SELECT Id, Name FROM Account])
            {
                if(counter < listLimit)
                {
                    tmpAccount.add(a);
                    counter++;
                }
                else
                {
                    loopCount++;
                    thousandBlocks.add(new limitWrapper(tmpAccount,loopCount));
                    tmpAccount = new Account[]{};
                    tmpAccount.add(a);
                    counter = 0;
                }            
            }

            if(thousandBlocks.size() == 0)
            {
                loopCount++;
                thousandBlocks.add(new limitWrapper(tmpAccount,loopCount));
            }

            return thousandBlocks;
        }

        public class limitWrapper
        {
            public Account[] accounts {get;set;}
            public integer blockNumber {get;set;}
            public limitWrapper(Account[] accs, integer i)
            {
                accounts = accs;
                blockNumber = i;
            }

        }
    }

-You can user readonly tag to increase from 1k to 10k:

<apex:page controller="thousandLimit" readonly="true">
   <apex:pageBlock >
      <apex:repeat value="{!thousandBlocks}" var="block">
            <apex:pageBlockTable value="{!block.cases}" var="c">
            <apex:column value="{!c.CaseNumber}"/>
            <apex:column value="{!c.owner.name}"/>
            <apex:column value="{!c.App_Process__c}"/>
            <apex:column value="{!c.Load__c}"/>
            <apex:column value="{!c.subject}"/>
            <apex:column value="{!c.Estimated_Completion_Date__c}"/>   
            <apex:column value="{!c.Complete__c}"/>
            <apex:column value="{!c.Priority}"/>
            <apex:column value="{!c.Case_Age_Days__c}"/>                    
            </apex:pageBlockTable>
        </apex:repeat>
     </apex:pageBlock>  
</apex:page>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top