+ Start a Discussion
Seung Ju KimSeung Ju Kim 

How do I mass edit all record in Custom object?

Hi, I am having problems in undertaking one project, that's problem is mass edit record in custom object.
not selected edit, How can I mass edit all record for Related Custom object?
Examples:
User-added image
User-added image
User-added image

Thanks
Best Answer chosen by Seung Ju Kim
Alap MistryAlap Mistry
Hello Seung Ju Kim,
In Developer Console, click Debug-> Open Execute Anonymous Window (CTRL+E). Then write code for editing in custom object. I given below some code structure for that.
 
List<CUSTOM_OBJECT_API_NAME> a = [SELECT Id FROM CUSTOM_OBJECT_API_NAME];
for(CUSTOM_OBJECT_API_NAME b : a) {
     b.FIELD_NAME = NEW_VALUE;
}
update b;
If error is occur, then post here. If it is useful, then mark it as best answer (for close this thread).
 
Regards,
Alap Mistry

All Answers

srinivasarao Muppanenisrinivasarao Muppaneni
you can edit by writing an update trigger
Alap MistryAlap Mistry
Hello Seung Ju Kim,
In Developer Console, click Debug-> Open Execute Anonymous Window (CTRL+E). Then write code for editing in custom object. I given below some code structure for that.
 
List<CUSTOM_OBJECT_API_NAME> a = [SELECT Id FROM CUSTOM_OBJECT_API_NAME];
for(CUSTOM_OBJECT_API_NAME b : a) {
     b.FIELD_NAME = NEW_VALUE;
}
update b;
If error is occur, then post here. If it is useful, then mark it as best answer (for close this thread).
 
Regards,
Alap Mistry
This was selected as the best answer
jigarshahjigarshah
Seung,

There are multiple approaches that you could use to Mass Update data. Please use the best that works for you.

1. In case the total number of records to be updated are less than 50,000 in number you can use the Import Wizard, the default utility from Salesforce to update the respective records.
2. In case the total number of records exceed 50,000, then Data Loader is the best option to mass update records.
3. You could use Apex code being executed through the Execute Anonymous window from Dev Console as a one time activity or using an Apex trigger that mass updates the existing records by executing a dummy update on the records in consideration.

I would recommend using Data Loader considering that it gives you the ability to backup the records to be updated which proves helpful in case of a rollback. Additionally, it also provides clear success and error files to understand the update progress as well as troubleshoot update failures.

Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps reolve your issue.
diya khodabolediya khodabole

Hi,
1.In Developer Console, click Debug-> Open Execute Anonymous Window (CTRL+E). Then write code for editing in custom object. I given below some code structure for that.
List<Opportunity> opps = [select Id, NewNumberField__c from Opportunity where NewNumberField__c = null limit 1000];
for (Opportunity opp : opps) {
opp.NewNumberField__c = 0;
}
update opps;
2. Else if total number of records exceed 50,000, then Data Loader is the best option to mass update records.
https://help.salesforce.com/articleView?id=000005123&type=1

Thanks,
Shruti Khodabole
Salesforce Developer
http://www.zen4orce.com

amol salveamol salve
Hello  Seung,
if you want to edit record on detail page then you have to do some setting 
Setup -> customize -> User Interface and then check the checkbox for Enable enline editing.
But if you want to mass editing means you have to edit all record at atime you need to create visualforce page and and edit record using  <apex:inputField> component so ypu can edit all record.
please check below code

<apex:page standardController="Account">
      <apex:form>
      <apex:outputField value="{!account.Test!__c}">
               <apex:inlineEditSupport event="ondblClick" />
         </apex:outputField>
     </apex:form>
</apex:page>

Create table and add field which you want to mass edit.


Thanks,
Amol B Salve
Salesforce Developer
http://www.zen4orce.com
Seung Ju KimSeung Ju Kim
Thanks All :)
I try Edit all at Standard function but It's Problem Seem to didn't Standard function.
so, I was Developed EditAll Button and table.
I'm Immature developer, but I'll share Code.

Apex Class....----------

public with sharing class EditAllController {

    public List<Pos_Data__c> posDataList {get; set;}

    public List<Pos_Data__c> getPosData() {

        Id bid = ApexPages.currentPage().getParameters().get('id');
        Set<Id> prebId = new Set<Id>();

        if(posDataList == null){
            posDataList = new List<Pos_Data__c>();
            for(Pos_Data__c a: [SELECT Id ~ custom object query =: bId ORDER BY Name asc]){
                posDataList.add(a);
            }
        }
        return posDataList;
    }
        public PageReference save(){   
            Id bid = ApexPages.currentPage().getParameters().get('id');

            try{
                update posDataList;
                }catch(exception e){
                }
                PageReference page = new Pagereference('/apex/MassEditPOSData?Id='+ bid );
            page.setRedirect(true);
            return page;
        }
        public Pagereference cancel(){
            Id bid = ApexPages.currentPage().getParameters().get('id');
        
            PageReference newpage = new Pagereference('/' + bid);
            newpage.setRedirect(true);
            return newpage;
        }
}

Visualforce Page....--------

<apex:page controller="EditAllController" sidebar="false">

<!-- for this page to work with a specific custom object, change standController="entityname" to custom object api name  
    For example, if custom object name is Warehouse__c, change first part of the first line to standardController="warehouse__c" -->

    
<apex:includeScript value="{!$Resource.UtilJS}" />
    <apex:form >
        <apex:pageBlock >
            <apex:pageMessages />
            <apex:pageBlock >
            Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first. 
            </apex:pageBlock>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Return" action="{!cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!PosData}" var="a" id="table">
            <apex:column headerValue="Product">
            <apex:inputField value="{!a.Product__c}"/>
            </apex:column>
            <apex:column headerValue="RRP">
            <apex:outputField value="{!a.RRP__c}"/>
            </apex:column>
            <apex:column headerValue="Unit Price">
            <apex:inputField value="{!a.Unit_Price__c}"/>
            </apex:column>
            <apex:column headerValue="margin">
            <apex:outputField value="{!a.margin__c}"/>
            </apex:column>
            <apex:column headerValue="Discount">
            <apex:inputField value="{!a.Discount__c}"/>
            </apex:column>
            <apex:column headerValue="Unit Price II">
            <apex:inputField value="{!a.Unit_Price_II__c}"/>
            </apex:column>
            <apex:column headerValue="Quantity">
            <apex:inputField value="{!a.Qty__c}"/>
            </apex:column>
            <apex:column headerValue="TTL Sales">
            <apex:inputField value="{!a.TTL_Sales__c}"/>
            </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>


User-added image

I'll Choose the closest Answer as Best Answer. 
Thanks All again!
Best Regards,
Seung Ju Kim
jigarshahjigarshah
Seung, I am not really able to understand what exactly are you trying to accomplish. Please share more details so that we can help you resolve your issue.
amol salveamol salve

Hello Seung,

       Just change your visualforce page code with bello code


<apex:page controller="EditAllController" sidebar="false">
    <apex:includeScript value="{!$Resource.UtilJS}" />
    <apex:form>
        <apex:pageBlock>
            <apex:pageMessages />
            <apex:pageBlock>
                Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first.
            </apex:pageBlock>
            <apex:pageBlockButtons>
                <apex:commandButton value="Save" action="{!save}" />
                <apex:commandButton value="Return" action="{!cancel}" />
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!PosData}" var="a" id="table">
                <apex:column headerValue="Product">
                    <apex:outputField value="{!a.Product__c}">
                        <apex:inlineEditSupport event="ondblClick" />
                    </apex:outputField >
                </apex:column>
                <apex:column headerValue="RRP">
                    <apex:outputField value="{!a.RRP__c}">
                        <apex:inlineEditSupport event="ondblClick" />
                    </apex:outputField >
                </apex:column>
                <apex:column headerValue="Unit Price">
                    <apex:outputField value="{!a.Unit_Price__c}" >
                        <apex:inlineEditSupport event="ondblClick" />
                    </apex:outputField >
                </apex:column>
                <apex:column headerValue="margin">
                    <apex:outputField value="{!a.margin__c}" >
                        <apex:inlineEditSupport event="ondblClick" />
                    </apex:outputField >
                </apex:column>
                <apex:column headerValue="Discount">
                    <apex:outputField value="{!a.Discount__c}" >
                        <apex:inlineEditSupport event="ondblClick" />
                    </apex:outputField >
                </apex:column>
                <apex:column headerValue="Unit Price II">
                    <apex:outputField value="{!a.Unit_Price_II__c}" >
                        <apex:inlineEditSupport event="ondblClick" />
                    </apex:outputField >
                </apex:column>
                <apex:column headerValue="Quantity">
                    <apex:outputField value="{!a.Qty__c}" >
                        <apex:inlineEditSupport event="ondblClick" />
                    </apex:outputField >
                </apex:column>
                <apex:column headerValue="TTL Sales">
                    <apex:outputField value="{!a.TTL_Sales__c}" >
                        <apex:inlineEditSupport event="ondblClick" />
                    </apex:outputField >
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>


on double click of that field you are able to edit that field, In this way you can mass edit all records in vf page..


Thanks,
Amol Salve
Salesforce Developer
http://www.zen4orce.com

Michael TomarMichael Tomar
Hi! You can use this ready-made query to mass edit custom object (https://skyvia.com/gallery/salesforce-mass-update-custom-object):

UPDATE "Custom_object"
SET
    "Custom_field" = 'New_Value'