+ Start a Discussion
sfdc dev 2264sfdc dev 2264 

Apex class using metadata

Hi ,

I have the following requirement for which i need help to acheive via apex class using custom metadata

1) I have a metadata which has few words in it 



2) i want to check if any of the keywords from the metadata are present in the case description (exact match along with the content) 
then change the case owner to a particular queue.

I need help on the same with the apex class

Thanks in Advance
I have Created a Custom Metadata for it -
Api name of metadata - Case_Description__mdt
Created a field in metadata - API name of the field in metadata - Description_Keywords__c.
Created two records in metadata like this -

User-added image

And then created an apex class - We can't filter queries on the basis of fields with type - long text area.

public  class CaseTestDescription {
    public static void HandleCase(string RecId){
        List<string> ListCaseIds = new List<string>(); 
        map<Id, string> mapIdWiseDescCase = new  map<Id, string>();
        for(case occ : [SELECT id, Description from Case WHERE id = :ListCaseIds]){
            mapIdWiseDescCase.put(occ.Id, occ.Description);
        List<Case_Description__mdt> ListCaseKeyWords = [SELECT Description_Keywords__c FROM Case_Description__mdt];
        List<string> KeywordsCaseDescriptionString = new List<string>();
        for(Case_Description__mdt oCDMdt : ListCaseKeyWords){
        List<string> CaseToMoveForowrd = new List<string>();
        for(string skey : mapIdWiseDescCase.keySet()){
            string Description = mapIdWiseDescCase.get(skey);
            for(string keyWord : KeywordsCaseDescriptionString){
        List<case> ListcaseToUpdateOwner= new   List<case>();
        List<case> ListCaseToChange = [Select id, owner.Id, OwnerId from Case where id = :CaseToMoveForowrd];
        Group sGQueue = [select Id from Group where  Type = 'Queue' AND NAME = 'Booyah'];
        for(case occ : ListCaseToChange){
            occ.OwnerId = sGQueue.Id;
            //Either----->  occ.owner.Id = sGQueue.Id;
            update ListcaseToUpdateOwner;

Let me know if it works, Thank you