Teach Me Salesforce

A community approach to learning salesforce.com

Archive for the ‘Configuration’ Category

Mastering the Force.com IDE: Searching metadata

with 17 comments

The Force.com IDE is a developer application that is great utility for Salesforce.com administrators even if they never have to write or troubleshoot Apex or Visualforce. The most useful capability for any admin is the Search feature which allows you to find all the places a field is used: workflow, reports, templates, formulas, etc.

Let’s consider this scenario: you’ve been hired to update a company’s Salesforce org and you discover a duplicate field on Accounts. You run reports and find out both fields are populated with data. Before you can decide which one to keep and which to delete, you need to know all the locations in which each field is used: reports, views, workflow, templates, etc. You can find all those configurations in minutes with your Salesforce org’s metadata in a project in the Force.com IDE.

I’ll assume you’ve already installed Eclipse and the Force.com IDE. If you haven’t, developer.force.com has a great page to help you; see you back here soon!

The first step is to create a Force.com project that contains all your metadata. Do this during the set up by selecting all the Metadata components.

New Force.com Project Wizard: Choose Initial Project Contents

New Force.com Project Wizard: Choose Metadata Components

If you have a very large amount of metadata and Eclipse throws a Java Out of Memory error, you can either apply this solution or choose fewer metadata components. You should at least include the following to ensure you are searching the common components that reference fields.

Component file extension
Apex Classes
Visualforce Components
Email Templates
Page Layout
Custom Objects
Standard Objects
Object Translations
Visualforce Pages
Reports(includes reports built from Custom Report Types)
Apex Triggers

Once you have created your project, you’re ready to start your search!

  1. Click on your Project to highlight it
  2. Click on the Search menu in the menu bar and select Search… to open the Search dialog box
  3. Enter the API Name of the field you’re seeking in Containing Text
  4. Copy the following file extension names into the field called File Name Patterns:
    *.cls, *.component, *.email, *.layout, *.object, *.page, *.profile, *.report, *.scontrols, *.trigger, *.workflow
  5. Set the Scope option to “Selected Resource” to ensure that only one Project is being searched.
  6. Click Search
  7. The Search Results pane will open when your search is completed with a list of all locations where the field occurs.

The following video demonstrates these steps in the Force.com IDE for Windows (Mac version is similar)

The search results will show you a tree with all the results in each metadata component. Click on any result will open the metadata file and show you exactly where your field occurs. You’ll be viewing XML, but don’t worry if you’ve never looked at XML before, there’s nothing tricky here. In fact, the tags you see are very friendly. They’ll be “nested” which means indented like a outline so that you can tell which tags are subordinate to which other tags. With a little investigative analysis, you’ll be able to discern the exactly how a field is being used in the metadata.

For example, in this screenshot you can see the Search results pane showing the components in which the field was found. The Reports components are open and the report called “Server Alerts” has two matches. By clicking on the matches, the Server_Alerts.report XML file is opened and the matches are highlighted. In the XML you can see all the configurations for this particular report. The <columns> tags show which columns are displayed in the report’s output, so we can see that our “App Server” field is one of the output columns.  We also see the field nested in the <filter> tags and can translate the XML tags to tell us that the field is being used in a filter with the operator “notEqual” and no value which means we are looking for records where App Server is not populated with any data. You can compare it to the actual report in the UI which is depicted in the second image below.

Screenshot shows the Search Results panel for a metadata search and the XML for the field as it occurs in a custom report.
Here’s how this report looks in the declarative UI for comparison. Note how the fields selected in the report show up as <column> tags and the filter is divided up into <filter>, <criteriaItems>, <column> and <operator> tags.
Using the Force.com IDE for metadata searches is one of my favorite techniques for thorough database maintenance. Searching with the IDE is just a start. From the results, you can even update many components with a simple Find and Replace to replace the retired field with a new field…but we’ll save that for the next lesson in Mastering the Force.com IDE!

Update 2013-11-06: Since Summer ’13 you can also use the Developer Console to search for fields across all Apex Classes and Triggers. Admittedly not as thorough a search of metadata as you can do in the IDE but it’s a good start – let’s hope we get the rest of the metadata world in there in a future release!


Written by Always Thinkin

September 25, 2011 at 2:48 pm

Apex Trigger and an Asprin can give you a dynamic approval process

with 3 comments

This post is crossed posted on my blog.

Ever come across the need of a large approval process where you do not know who the approver of the next stage will be? We all do don’t we?

In a recent project requirement, I had to work on a big approval process. My basic requirement was:

1. One approval process for child object
2. Once child is approved, it should trigger the master object approval process

Both the approval process had around 5 steps and the approvers where determined by the role hierarchy and the region of the submitter.

Yikes isn’t it?

For this recipe, you need
1. Basic knowledge of APEX and trigger
2. Basic knowledge of Approval process
3. Aspirin (just in case you miss a step and go reverse engineering on it, its scary!!!)

Part I: The Child Object Dynamic Approval process.

Steps for Child Object Dynamic Process
1. Create two fields on the child object. These fields should not be shown on Page Layout.
i) Approval_step__c: Text field to determine which step the approval is.
ii) Next_approval__c: A user field to store the approver. (In case there are multiple approvers or parallel approver, create multiple fields)

2. Create the approval process.
i) Initial submission action will be field update: Approval_step__c=’Submitted for approval’
ii) In approver step, select related user and add the Next_approval__c
iii) In the approval Step Action, field update for Approval_step__c with the next step of Approval, e.g., ‘Regional Manager’ or maybe ‘Higher Manager’. Keep a  note of these keywords. (If the approval process is directly tied to the role hierarchy it is advisable to Update the field with next Role in approval, that way you can avoid confusion)
iv) Repeat the ii) and iii) till you finish all the approval steps.

3. Write a before update trigger on child object
i) Check if Trigger.old.Approval_step__c != Trigger.new.Approval_step__c (this is a pseudo code, you will have to iterate through trigger.new and old and compare all values, if you do not know how to do this, add a comment below)
ii) Now based on the value in Approval_step__c fetch the respective user from Role Hierarchy or anywhere else. Better option would be to use custom settings for this. Add this user in Next_approval__c
iii) Repeat step ii) till you finish all the approval steps. The final approval step would be to either empty the  Next_approval__c field or set it back to manager of the user.

4. Optional step If you need to trigger another approval process after this.
i) In the approval process, set the final approval action to ‘Approved’
ii) In the trigger if the field value is ‘Approved’ then submit the Master in Approval process using Apex Code. (There are many links which give you direct code, I might share the code later, but it has to be done in code if you want continuous approval process)

That’s it. It is easily understood that you need to repeat the whole process for master if it needs dynamic approval.
After you done everything, take a deep breath and test your code. If it doesn’t the way it should, take an aspirin and debug. Since this uses hand-shake between trigger and approval steps make sure you don’t miss out on any step.

Note: As this approval process updates back-end, the visual process manager won’t be able to visualize it.

Try it and hope you don’t need a aspirin.

P.s. This is my first post on this blog, do share your thoughts.

Written by Siddhesh Kabe

May 25, 2011 at 1:46 pm

Multilingual Salesforce

leave a comment »

This article first appeared on Luneos SFDC blog.

Would you like use SalesForce CRM in your local language? Have you tried to look for your language but haven’t succeeded? Do you speak Swedish, Portuguese, Dutch, Danish, Hungarian, Finnish, Polish, Russian, Czech, Turkish, Indonesian, Romanian or Greek? Then you still have a chance, but you have to ask your administrator for a favour. 😉

SalesForce - Creating new service case

SFDC doesn’t display (and allow) all available languages by default and if you speak one of the languages above, your administrator has to create a new service case for SalesForce team at first.

How to do it? After login into the CRM, just click on the “Help” link a then continue to “My Cases” tab, where you can check your existing services requests or create new ones. Then click on the button “Log Case” and fill the case details following the screenshot below.

SalesForce - Creating new service case

After you save the case, you receive a confirmation e-mail with the case number and during next 24 hours is your custom language activated. Once it happens, another confirmation message lands in mailbox.

How to change default language for your organization or selected users is explained in post Changing Languages in SalesForce.

Written by Lukas Vedral

May 23, 2011 at 12:50 am

KPI Traffic Lights in SalesForce

with 2 comments

Did you know that you can use traffic lights to visualize the status of your customers, leads and opportunities in SalesForce? It’s even easier than you think, because you don’t need any programming skills, but only single formula field.

SalesForce CRM - visualization

Let’s say that you want to evaluate the opportunity status based on the last activity date and display a green light if there was an activity during the last week, yellow light if the last one is from 7 to 14 days old and red for all others.

Sounds simple, huh? So let’s start… 🙂

Open the administration screen, choose the option Opportunity – Fields and create a new custom field with type Formula. On next screen fill in its name and select the return type Text.

SalesForce CRM - formula field

Now comes the most creative part, because you have to write down the conditions for the traffic lights. Following code works fine:

IF( LastActivityDate > Today() – 7 , IMAGE(“/img/samples/light_green.gif”, “Green”),
IF( LastActivityDate > Today() – 14 , IMAGE(“/img/samples/light_yellow.gif”, “Yellow”), IMAGE(“/img/samples/light_red.gif”, “Red”)) )

Then just setup the field level security, its visibility on page layouts and save. The traffic light color is then automatically recalculated for all opportunities and displayed within their detail.

SalesForce CRM - traffic light

If you need additional information check the SalesForce.com manual.

SalesForce CRM - traffic light

This post has also appeared on our SFDC blog.

Written by Lukas Vedral

May 12, 2011 at 1:03 am

Posted in Configuration, Intermediate

Tagged with

Instant Reports

with 3 comments

It happens all the time – customer calls you because of some trivial matter (e.g. what’s the sum of his unpaid orders or how many escalated cases have violated the SLA) and you have to run through several CRM modules to give him a correct answer.

Salesforce - instant reporting

At first you open the account details, where you check his payment or SLA conditions, then you copy his name and move to reporting. There you have to find the correct report, paste account name and adjust filtering criteria.

Finally after three minutes of hard effort, you can tell the customer precise number. Because this scenario happens on daily basis, you’ve already got used to the constant interruptions and do not expect any improvements…

With Salesforce.com Instant Reporting you can completely avoid this process and run selected reports directly from account detail.

You simply navigate to the customer account, click the report link and the instant reporting overtakes filtering parameters (e.g. payment status, SLA conditions,…) from the account and displays report results.

On top of that you can use instant reporting for all SFDC objects, because it uses standard formula fields and it’s really easy to setup.

At first it is necessary to create the underlying report – in our case, because we want to display all escalated cases with SLA violation, we add filtering criteria SLA violation = Yes and Status = Escalated. Because we want to display the information only for one selected account, we also add another filter Account ID, keep it blank and save. Don’t be afraid that the report hasn’t returned any result – it’s because of the empty Account ID filter, which is necessary for proper function of instant reporting.

Salesforce - reporting

After that navigate to the account fields (Setup – Customize – Account – Fields) and create new one with type Formula. Fill in its name (e.g. Escalated cases with SLA violation), set its type to Text, insert following code and save:

HYPERLINK(“/00OA0000003jShP?pv0=” & Id , “see details”, “blank”)

The HYPERLINK specifies that a link to the report will be created, /00OA0000003jShP is the unique ID of the report, which you can copy from the URL after you run it. There you have to take care, because your report ID will be different from ours.

Salesforce - instant reporting

The ?pv0= means that you want to change the first filter parameter in report and Id represents the Account Id field, which you can get by clicking on the Insert field button.

Salesforce - formula field setup

Two remaining parameters are really simple – see details is the text that will be displayed as a link and blank opens the report in a new window.

Salesforce - formula field setup

Account page layout is then enhanced by a new fieldand after you click the link, the instant report with all adjusted filters is opened.

Salesforce - instant reporting

After you test instant report links in sandbox and move them to production, you have to adjust the report ID in the formula field. The reason is that the report in sandbox has another ID (/00OA0000003jShP) than the one in production.

If you want to use more ad hoc filtering criterions, just add another & sign and don’t forget that the criteria numbering starts from zero (pv0 – first filter criteria, pv2 – third filter criteria) – e.g.

HYPERLINK(“/00OA0000003jShP?pv0=” & Id & “&pv2=” & Name , “see details”, “blank”)

Also posted on Luneos Salesforce.com blog.

Written by Lukas Vedral

May 7, 2011 at 7:16 am

Posted in Beginner, Configuration

Tagged with ,

Updating reports with Eclipse and the Force.com IDE

with 9 comments

I came across a question on the Salesforce.com Answers forum today and thought the answer might be useful to others.

Here is the original question: http://bit.ly/k3nKHD

The question concerned updating reports after a new Stage was created on the Opportunity Object.  Once the new stage was created and Opportunity records had been updated to use that new stage, any reports leveraging the old stage in their filters would be broken.  The poster of the question was hoping there was a faster way to identify the reports that filtered on that stage than opening each report individually.  I suggested using Eclipse and the Force.com IDE along with Notepad++ to get things done.  This will work with much more than just Stage, so insert your own search terms as desired.

The following assumes that you are already comfortable with Eclipse and the Force.com IDE:

The first thing you will want to do is download all of your report metadata to Eclipse.   If you have reports that are in Production and not your Sandbox then you will need to connect to your Production environment or refresh your Sandbox first.  If you do need to connect to Production just BE CAREFUL.

  • Create a new project
  • Include ‘reports’ or more specifically the report folders you are concerned with
  • Let Eclipse refresh the project with the reports metadata
Now that you have all of the metadata for your reports, it is time to search through the metadata for the StageName to find all of the reports using that Stage.
  • In Eclipse, navigate to the reports folder you just download. Right click and select properties
  • Highlight and Note (or copy) the Location. This is the path where the metadata files are located
  • Open a windows explorer window and navigate to the path you just copied
You should now see all of the folders containing your report metadata.
  • Open Notepad++ click Search > Find in Files  (or just Ctrl+Shift+F)
  • Enter your search term (in our case, the Stage) , make sure the ‘In all sub-folders’ box is checked and click the ‘Find All’
  • A message will pop up saying “Searching… Press Enter to Cancel”. Don’t touch anything, just let it do it’s search, this may take a little while depending on how many files you have.  Clicking OK will cancel the search.
You should now have a list of files where the Stage has been found.  You can use this to narrow down the reports that need to be updated and hopefully cut down the time you spend updating your reports.
Note: It is possible to update your reports directly from the IDE as well.  If you choose to do that, make sure you back up the report data to another location in case something goes wrong.

Written by knthornt

May 4, 2011 at 11:03 am

Posted in Advanced, Configuration

Tagged with

Overriding Standard Links & Buttons

leave a comment »

Salesforce.com allows you to override standard button and links (add, edit, delete, etc.) throughout the platform with your own customized functionality. This is a video which details some of the functionality I outlined here along with the new feature to by-pass the recordtype selection page.

Written by Jeff Douglas

May 2, 2011 at 9:00 am

Posted in Beginner, Configuration