You need to sign in to do that
Don't have an account?

Change field value en-mass using DML
Hi All,
Here is the change I am looking to make:
If fieldA (SortType_C) from CustomObject_C = BLANK then change value of SortType_C to "Other"
I am a new administrator and learning fast, I managed to access the developer console but I am new to DML.
Can anyone help me with the code?
Thanks,
Dave The Rave
Here is the change I am looking to make:
If fieldA (SortType_C) from CustomObject_C = BLANK then change value of SortType_C to "Other"
I am a new administrator and learning fast, I managed to access the developer console but I am new to DML.
Can anyone help me with the code?
Thanks,
Dave The Rave
List<RealEstateObject__c> recList = [SELECT Id, SortRealEstate__c FROM RealEstateObject__c WHERE SortRealEstate__c = NULL ];
for (RealEstateObject__c rec : recList) {
rec.SortRealEstate__c = 'Other';
}
update recList;
All Answers
The reason I am not using workflow or process builder is because they need a trigger like an update to a record or creation of a record to start a process or field change. So I understand (once I have put the real field and object names in the code) I can just past the code into the developer console, click "execute" and it should run the code? (maybe a stupid question, but I am in a learning mode now)
I believe that the requirement is to update SortType_C to "Other", everytime this field is left blank. If you go by the developer console that will be a one-time solution which means it will work only when you run the code and this will not be an automated process.
If you use a workflow rule for this, you do not have to write a trigger or any code for this and it will work each time a record is created or updated.
Thanks,
Amit
So whenever a record of CustomObject__c is being saved, if the Sort_Type__c field is not set on the record, the above code will set the Sort_Type__c field to "Other".
The trigger code would handle all the records that would be created or updated from the point, trigger is deployed. However for existing records, you can use the following code to run from Execute Anonymous window in Developer Console.
Please tell me if the image is not clear, here is the code I entered:
List<RealEstateObject__c> recList = [SELECT Id, Sort_Type__c FROM RealEstateObject__c WHERE SortRealEstate__c = null];
for (RealEstateObject__c rec : recList) {
rec.SortRealEstate__c = 'Other';
}
update recList;
List<RealEstateObject__c> recList = [SELECT Id, SortRealEstate__c FROM RealEstateObject__c WHERE SortRealEstate__c = NULL ];
for (RealEstateObject__c rec : recList) {
rec.SortRealEstate__c = 'Other';
}
update recList;
Choose 'Open Execute Anonymous Window' option under 'Debug'. Paste the code in opened window and click on run.