IDE part 2 - using Search and Replace
Jun 14, 2009So, in Part 1, we covered creating a project, and being able to delete reports. Some people were already happy about that - see the end of Mass delete reports:
It warms the cockles of my heart!
So, once you've cleaned up the old reports we wanted to delete, what else can we do? How about changing things in reports?
Search and Replace - changing filter values
One thing that comes up a lot in wanting to change reports is looking for "old" filter values. These might be from picklists or member status, or territories. So, what can we do?
Well, let's say we have reports on opportunities, and we want to change the opportunity stage names. Normally that would mean going to the reports, and changing what we were looking at. Now, we can use the powerful search and replace in eclipse to do our work.
An Example - stage name
So, I have filter definition on stage name. I'm filtering in my reports to only show stage 1 to 3, but I see that the third one - “Needs Analysis” isn’t used much:
In the query I have:
Now, I want to get rid of “Needs Analysis”. I can do that in the picklist editor, by deleting the picklist value, and moving those opportunities to “Qualification”:
But my reports still filter on the old value.
Or, I might have chosen “None” in the replacement value, then they would all still stay “Needs Analysis” – maybe I am migrating to new settings, maybe I’m converting 2 statuses to 1 new one.
In the IDE:
I can now see this in the IDE:
<filter>
<criteriaItems>
<column>STAGE_NAME</column>
<operator>equals</operator>
<value>Prospecting,Qualification,Needs Analysis</value>
</criteriaItems>
</filter>
andfdf
So, let’s says I want to:
find places where the text appears in the the <value> block of a report file
Then I can ask it to search (but don’t hit the “search” button), I’m about to explain the contents
Here, I’ve clicked the “Regular Expression” checkbox. Rather than making things more normal (like Regular Coffee, or Regular Joe), this allows me to do something special.
The first part of the “containing text” is (<value>.*) – the parentheses mean that this is a “capturing group” – that we are going to be able to use later. This means, find something that starts with <value>, then has any number of any characters. Then the next part says “Needs Analysis”.
I also want to search only in report files – where the pattern is *.report – any file ending in .report
Now, hit the “replace” button, and this appears:
And here’s where it gets weird. We want to replace it with $1? You can’t even buy a coffee for a dollar (yes, I live in expensive San Francisco).
No. The “$1” means to replace that text with whatever the search found in the parentheses – so it will replace it with “<value>” followed by whatever else was before the “Needs Analysis”, followed by the replacement value I’ve chosen.
DON’T HIT THE “REPLACE” BUTTON UNLESS YOU ARE REALLY SURE!
You want to try this in a dev org, or with a single file, or where you have the files versioned, because as soon as you press “replace”, it will replace in all files, and put that file back on the server.
Now, for a split second, the code looks like this:
<filter>
<criteriaItems>
<column>STAGE_NAME</column>
<operator>equals</operator>
<value>Prospecting,Qualification,Qualification</value>
</criteriaItems>
</filter>
and you’ll wonder what in the Sam Hill is going on, before the save/verify/download logic build-in to the IDE takes over, and makes the code look like this:
<filter>
<criteriaItems>
<column>STAGE_NAME</column>
<operator>equals</operator>
<value>Prospecting,Qualification</value>
</criteriaItems>
</filter>
and then you are done!
Here, the IDE has uploaded your code to the server, which looked at the filter, and decided two of the picklist values were the same, and it’s sent it back to the client with the duplicate removed.
Remember:
- practice in a developer org (they are free!)
- back up your .report files
- Run “Search” to make sure you find what you want
- Run “replace in file” to try one file at a time
- Be lucky!

Hi Tom,
Another inspiring article! Discovering more Salesforce super powers always reminds me of those first few episodes of Heroes...
This method also serves as a useful trick for the age-old question of "Where am I using this field?". By performing the same search against *.layout, you can uncover all the layouts on which you are using a field.
Of course like any good hero, I've got a fatal weakness: too many reports! Since I had just 12 more than Eclipse will allow, I was able to easily trim to under the 1500 file limit.
Posted by: Luke "AlwaysThinkin" C | July 08, 2009 at 11:00 AM
Thanks for this walkthrough... I have avoided truly educating myself on regular expressions my whole coding career... I reckon this is a good reason to knuckle down.
Unlike Luke, I was not able to trim down below 1500 and had to do mass updating in two phases... imagine if I had to go into each report!
Thanks for posting... and Luke, thanks for alerting me to the post!
Posted by: michaelforce | August 07, 2009 at 02:56 PM