2

I am writing a code that filters records who has the value of 2 fields**(Firstname__c,Lastname__c)** concatenation. I assigned that concatenation value in a string and I use contains method . But it returns nothing. Will you help me implement this code ?. for example this line of code will return String [SELECT Id,First_Name__c,Last_Name__c,Ticket_Number__c FROM Ticket__c WHERE Event__c =:Event] an array values of {firstname:martin lastname:johnson,firstname:marvin lastname: jhon,firstname:peter lastname:blair}.Using this code String fullname = String.valueOf(obj.First_Name__c)+' '+String.valueOf(obj.Last_Name__c); it will concatenate the firstname and lastname values. then my Searchkey variable contains "MA" .. it will filter and assigned the ticket_number__c of (martin and marvin) into the List filtered by this code filtered.add(obj.Ticket_Number__c);

HERE IS MY CODE

 @AuraEnabled
public static List<Ticket__c> SAETH(String Searchkey,String Event){
    List<String> filtered = new List<String>();
    for(Ticket__c obj : [SELECT Id,First_Name__c,Last_Name__c,Ticket_Number__c  FROM Ticket__c WHERE Event__c =:Event])
    {
        String fullname = String.valueOf(obj.First_Name__c)+' '+String.valueOf(obj.Last_Name__c);
        if(fullname.contains(Searchkey))
        {
            filtered.add(obj.Ticket_Number__c);
        }
    }
    System.debug(filtered);
    return [SELECT Id, Name, Event_Product__c,First_Name__c,Last_Name__c,Ticket_Number__c, (SELECT Id, Check_In__c, Check_Out__c, Status__c FROM Ticket_Logs__r  ORDER BY CreatedDate DESC LIMIT 1 )  FROM Ticket__c t WHERE Ticket_Number__c IN:filtered];
}
3
  • can u add some example data that u hv used and what u see in the debug logs, and why don't you use SOSL FIND to search developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/… Commented Sep 10, 2015 at 7:16
  • Wouldn't there normally be a space between the first name and the last name? Commented Sep 10, 2015 at 7:18
  • read my post again i update it. Commented Sep 10, 2015 at 7:24

1 Answer 1

2

If I understand your question properly, you should be using containsIgnoreCase() instead of contains for your case. Should be working for you.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.