function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Katelyn SorensenKatelyn Sorensen 

Best way to turn Employee Number "0" lead fields to "blank"

I am looking for a way to switch the fields in SF that have a zero in the "No. Of Employees" Field to make them blank so that I can update them with a data.com clean. Someone suggested that there might be a way to write an Apex trigger for "if employees=0" then "make blank" - does anyone know if there is a better way or know how to write an Apex trigger that would be willing to help me?

Thank you!
Terence_ChiuTerence_Chiu
Katelyn, have your considered using Apex Data loader? If this is a one-off update you can export all records from the lead object where it matches your crteria to a data file including the Id and No of employess fields at a minimum. Using that data file you can clear the No of Employees field and use Data loader to run a mass update.

Below link will have an overview of data loader and its capabilities.

https://developer.salesforce.com/page/Data_Loader
AmrenderAmrender
Hi Katelyn

Below is the small piece of code. You can run this in your Developer Console
List<Account> accountList = [Select Id, NumberOfEmployees From Account where NumberOfEmployees = 0 Limit 10000];
for(Account a:accountList) {
    a.NumberOfEmployees = null;
}
update accountList;

If your query return more than 10000 records. Run the above code again. Let me know if it helps you.


Regards
Amrender
Katelyn SorensenKatelyn Sorensen
Hi Amrender, Thank you for this – I very much appreciate it! As I was about to run the code I noticed that it says “account” I am looking to run to clean up the Leads – would it be the same code except changing the id? I want to make sure I am not going to mess anything up ☺ I apologize for taking so long to get back to you, I had a competing priority come up. Best, Katelyn Sorensen Account Executive [Signaturepicture] Fierce, Inc. | 101 Yesler Way | Suite 200 | Seattle WA 98104 206.787.1134 PHONE | 206.787.1120 FAX Twitter | Facebook | LinkedIn | Blog | fierceinc.com
AmrenderAmrender
Yes Katelyn. For Lead you just need to change the Object name from Account to Lead. Below is the sample code.
List<Lead> leadList = [Select Id, NumberOfEmployees From Lead where NumberOfEmployees = 0 Limit 10000];
for(Lead l:leadList) {
    l.NumberOfEmployees = null;
}
update leadList;
This is a one time process to update all '0' with 'blank'. If you want it to work in real time (update NumberOfEmployees to 'blank' from '0' as soon as lead comes into system) then we have to write trigger.

Let me know if it helps you.

Regards
Amrender
 
Katelyn SorensenKatelyn Sorensen
Hi Amrender, Thank you for this – I am excited to run it. Am I supposed to execute it as a SQL query or in the devconsole$ area or somewhere else? I got into the developer console and am not sure where to input the code, thank you! ☺ Best, Katelyn Sorensen Account Executive [Signaturepicture] Fierce, Inc. | 101 Yesler Way | Suite 200 | Seattle WA 98104 206.787.1134 PHONE | 206.787.1120 FAX Twitter | Facebook | LinkedIn | Blog | fierceinc.com
Katelyn SorensenKatelyn Sorensen
I tried to simplify the code down to run in SQL just to test it and keep getting a "Unknown Error Parsing Query" This is all I have:

SELECT Name 
FROM Lead
WHERE NumberOfEmployees = 0
;

I have tried every iteration I can think of including using Account, deleting the spacing, using quotes, using different "where" qualifications, I cannot seem to run a query that returns results.

Ultimately, I am trying to run Amrender's code to complete the data clean and thought I would do a search first, I am new to using the developer console, but I have done some SQL before, I am not sure what I am doing wrong. Any help would be incredible!!
AmrenderAmrender
Hi Katelyn

I captured some screen shots and I hope these will help you to run the code.

Query Run
Execute Code

User-added image

Let me know if it helps you

Regards
Amrender