+ Start a Discussion
rizwan ahmed 16rizwan ahmed 16 

how to update a record value from developer console

I have Field label as  Lead source which is Formula field  on Quote object .But  now the requirement is insted of formulae they require  Pick list field.So i created a new pick list field and labeld as Lead source .now i want to update all the pick list value by formula field by developer console ananymous window .how to update a record value from developer console. can any one help
Best Answer chosen by rizwan ahmed 16
Lalit Mistry 21Lalit Mistry 21
List<Quote> quotes = [SELECT Id, Lead_source__c, Lead_source2__c FROM Quote LIMIT 50000];
for(Quote quote : quotes){
	quote.Lead_source2__c = quote.Lead_source__c;
​}
update quotes;

There was a typo in previous response. Use the code snippet as in this response

All Answers

Lalit Mistry 21Lalit Mistry 21
Hi Rizwan,
Assuming the field api name for formula field is Lead_source__c and api name for new picklist field is Lead_source2__c, you can execute below code in developer console.
List<Quote> quotes = [SELECT Id, Lead_source__c, Lead_source2__c FROM Quote  WHERE LIMIT 50000];
for(Quote quote : quotes){
	quote.Lead_source2__c = quote.Lead_source__c;
​}
update quotes;

Note that this will process only 50000 records and if there are more than 50K records then use Lead_source2__c != NULL in where clause of the above query and run multiple times till all quotes are updated.
 
Lalit Mistry 21Lalit Mistry 21
List<Quote> quotes = [SELECT Id, Lead_source__c, Lead_source2__c FROM Quote LIMIT 50000];
for(Quote quote : quotes){
	quote.Lead_source2__c = quote.Lead_source__c;
​}
update quotes;

There was a typo in previous response. Use the code snippet as in this response
This was selected as the best answer
rizwan ahmed 16rizwan ahmed 16
Hi Lalit Thank you its working