7

I added a new custom field to an object with many existing records. It was a checkbox field and during creation I specified the default value to be "true". However, it looks like all the records have the new field unchecked. Is this expected behaviour? More importantly, is there a way to mass update the value of the new field, like:

UPDATE Input_Source__c 
SET Hide_Province_Field__c = true

I have tried the developer console, but either my syntax is wrong or you can't run update queries through the console.

9

The default behaviour relates to 'new' records only, not existing - so yes expected behaviour.

The statement that you have provided is SQL rather than SOQL. You can't issue SQL statements within Salesforce, you have to take the following steps:

  1. Retrieve the data using a SOQL query
  2. Update the data using a DML statement

There are some governor limits that you should be aware of with both (e.g. only being able to retrieve maximum of 50,000 rows and only able to update a maximum of 10,000 etc.). If you exceed any of these limits, you may need to employ batch apex. However, if you are just talking about a few records you could do this:

List<Your_Object__c> myobjects = [ Select Input_Source__c From Your_Object__c ];
for( Your_Object__c myobject : myobjects )
{
    myobject.Input_Source__c = true;
}

update myobjects;

Edit: you could also use dataloader, i.e. extract the records, update the value to true and then update with data loader if you don't want to use Apex

1

You can use this native premium app called Smart-Mass-Update (it has 14-days trial) it supports all Salesforce versions and has a mass delete, mass edit, mass update, export to file and advanced filtering options.

https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B4KmAEAV

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.