2

I've got a picklist Activity1__c with 2 values that don't actually exist in the metadata: "Reverse Reference - Completed" and "Reverse Reference - Incomplete". In other words those picklist values aren't defined.

However, they exist as someone has effectively set those values when writing to that field.

When I try to query this though like below, nothing is being fetched through.

List<Activity_Log__c> reverseReferencesList = new List<Activity_Log__c>();

for (Activity_Log__c a : [SELECT Id, Candidate__c, Person__c, Activity1__c FROM Activity_Log__c WHERE OwnerId = :user AND Activity1__c LIKE '%Reverse Reference%' AND CreatedDate >= :startDate AND CreatedDate < :endDate]) {
  if (String.valueOf(a.Activity1__c) == 'Reverse Reference - Completed') {
    reverseReferencesList.add(a);
  }
}

If I remove the if statement and just add those records to reverseReferencesList, records will appear in the Visualforce page. However if I try to specifically find "Reverse Reference - Completed", it returns nothing.

I've tried:

  • Specifically querying for "Reverse Reference - Completed"
  • Getting the String.valueOf() and filtering (as in the example), still returns nothing
  • Adding the values to the PickList's metadata, but that has no effect

Is there any way around this for finding records by PickList value that aren't defined in the PickList metadata itself, but are written to the record?

2
  • You have pick list data type field but you have not defined any value to it. How its possible picklist field without value.
    – MIX DML
    Jan 22, 2016 at 10:28
  • @PrabhatKumar Correct, but the picklist does have values. But somehow someone has written Reverse Reference - Completed and Reverse Reference - Incomplete to the records that don't exist in the PickList's values.
    – Dan Jones
    Jan 22, 2016 at 10:32

1 Answer 1

0

Seems like Salesforce doesn't like dashes.

I firstly queried the following:

[SELECT Id, Candidate__c, Person__c, Activity1__c 
 FROM Activity_Log__c 
 WHERE OwnerId = :user 
       AND Activity1__c LIKE '%Completed%' 
       AND CreatedDate >= :startDate 
       AND CreatedDate < :endDate]

This bought up a correct list with "Completed" in, but with other unwanted records in. So then I added AND Activity1__c LIKE %Reverse Reference% to the query like below:

[SELECT Id, Candidate__c, Person__c, Activity1__c 
 FROM Activity_Log__c 
 WHERE OwnerId = :user 
       AND Activity1__c LIKE '%Completed%' 
       and Activity1__c LIKE '%Reverse Reference%' 
       AND CreatedDate >= :startDate 
       AND CreatedDate < :endDate]

Which then filtered everything properly. Adding the - in seemed to be causing complications. No idea why, but if someone has an explanation for this I'd appreciate it. Otherwise I'd say this is pretty much answered.

2
  • is this 'Reverse Reference - Completed' creating problem ? Actually i did not understand what actually causing it. You don't have dash in query in the question. :)
    – MIX DML
    Jan 22, 2016 at 10:52
  • @PrabhatKumar Yeah it was. The original query would pull all the records through! So then I was using the if to try and filter the records with the - in. But that didn't work either! Not sure entirely why!
    – Dan Jones
    Jan 22, 2016 at 11:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .