function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
fiona gentryfiona gentry 

Resolve Trigger Error For Trigger when Email subject is AIRTEL

Dear Folks,

I have a queue named "Prepaid" and want to route Email 2 case to a particular Prepaid Queue  when emails  contains "Airtel" in Subject

Wrote a Trigger for Email 2 case queue such that  it triggers when Email subject is AIRTEL(Space Before and After)

Step 1:
Created below Custom Label with   string to match against. As I want to route emails which contains Airtel in Subject to a above Prepaid queue

EmailSubjectAsw = “Airtel”

Step 2:
Created Case Trigger (beforeInsert) and used this code snippet below:
 
trigger PrepaidEmailSubjectAsw on Case (before insert) {

					
					public static void setCaseType(List<Case> records) {
					String searchWords;
					List<String> strings;
					for(Case c : records) {
						searchWords = Label.EmailSubjectAsw;
						strings = searchWords.split(',');
						if (isStringInTarget(strings, c.Subject)) {
							continue; 
						}
							} // end for loop
				} 
				public static Boolean isStringInTarget(List<String> strings, String target) {
					String strRegEx = '(?i)\\b(';
					// case insensitive and exact match only 
					for (String s : strings) {
						strRegEx = strRegEx + s + '|'; // build up a list of strings using | separator 
					}
					strRegEx = strRegEx.removeEnd('|'); // get rid of the last OR
					strRegEx = strRegEx + ')\\b';
					Matcher matcher=Pattern.compile(strRegEx).matcher(target);
					Boolean result= matcher.find();
					return result;
					ID queueId = [SELECT Queue.Id FROM queuesobject WHERE queue.name='Prepaid'];
					Case.OwnerId = queueId;
				}
				}

Getting Error as
 
Line 26 Illegal assignment from List<QueueSobject> to Id
            Line 27 A value cannot be stored to OwnerId in type Case
            Line 26 Unreachable statement


Can some one provide resolution above and  fix the Trigger code 


Thanks In Advance,your help is appreciated

Fiona



 
Best Answer chosen by fiona gentry
PriyaPriya (Salesforce Developers) 
Hey Fiona,

In line 26, your querry may be returning multiple value i.e., list of values. so it has to be strore in list only. 
try like below :- 
List<ID> queueId = [SELECT Queue.Id FROM queuesobject WHERE queue.name='Prepaid'];


In line 27, you are trying to pass the id of queue to ownerid field. you 

If it solve the error, kindly mark it as the best answer.

Thanks,
Priya Ranjan

All Answers

PriyaPriya (Salesforce Developers) 
Hey Fiona,

In line 26, your querry may be returning multiple value i.e., list of values. so it has to be strore in list only. 
try like below :- 
List<ID> queueId = [SELECT Queue.Id FROM queuesobject WHERE queue.name='Prepaid'];


In line 27, you are trying to pass the id of queue to ownerid field. you 

If it solve the error, kindly mark it as the best answer.

Thanks,
Priya Ranjan
This was selected as the best answer
siwij remarsiwij remar
KFC is the largest fast-food restaurant chain in South Africa. With around 900 outlets in South Africa, KFC is looking for more improvements. 
KFC Survey