Wednesday 25 November 2009

Lookup filter - a cautionary tale

Apologies for the lack of posts of late - I've been busy coding for a project, and I'm off on holiday for the end of the year, so the pressure is on!

I'm at the "fun" stage of the project where I'm writing my test methods and encountered an unusual problem. We have a custom object, I created some instances of this object and saved them to the database. This object also has an (optional) lookup field to another instance of the same object, so I then tried to update some of the inserted objects with references to other inserted objects.

When running the test code, I was getting an error message along the lines of:

"FIELD_INTEGRITY_EXCEPTION: Value does not exist or does not match filter criteria. Click icon to select a value."

Turns out the error was related to a feature in beta, "Filter on Lookup". To be fair, it wasn't the feature's fault: it was being used incorrectly which was causing the problem, and it wasn't an obvious culprit.

The Idea requests a way to restrict what records are shown when a look up button is pressed. For example, let's say you use the Account object for two types of account, customer and partner. On the Opportunity object, you may want fields related to the customer you are trying to sell to, and the partner you are partnering with on the deal. You want to stop users putting partners in the customer field and vice versa. Sharing rules are no good as you want users to be able to see both type of account. With filter on lookup, users click the lookup button on the customer field, and only see customer accounts, and partner accounts when clicking the partner lookup.

It also stops you manually entering names of accounts that do not meet the filter criteria. It's actually slightly cleverer than this, because whatever way you try to save a record, it will check the related object matches the filter; if it doesn't an error is reported...

Which is where the problem I encountered comes into play: the field I was trying to set in my test method had such a filter set on it, and the filter had been set up incorrectly - it was looking at the wrong field, which hadn't been set by my test code. The result: error! Hope someone finds this useful...

3 comments:

  1. Java is a high-level programming language based on C and C++. This language has been growing, and it is used for various purposes. It can be used for developing Web applications such as Apache Tomcat, JBoss, and Weblogic. Uses of Java are diverse, and hence right explained in a blog. If you are a freelancer, register today on Eiliana-A global freelancing portal.For more info visit:- https://eiliana.com/blogitem/an-overview-of-java-spring-framework-features-capabilities

    ReplyDelete
  2. Indians are sports fans, and cricket is our national sport. Indian sports have recently developed significantly, moving away from traditional offline modes of involvement and toward more immersive tech innovations such as world777 fantasy sports.

    ReplyDelete
  3. This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up. You might also like adidas product tester

    ReplyDelete