You need to sign in to do that
Don't have an account?
Sangeet kasera
Dynamic SOQL query StartsWith To: ?
Hi All,
I am creating a filter with checkboxes, I want when case comment checkbox is true then all comment associated with case are shown and when we check checkbox Email, Then only comments which are added by mail should be shown means-
My sample code are -
if(filterLabel.isEmpty() && commentFilter==true){
System.debug('Inside custom setting Enable If query');
String srchValue = 'To:';
string tempInput = '%' + srchValue + '%';
commentQuery = commentQuery + ' And CommentBody NOT LIKE \'%' + srchValue + '%\'';
System.debug('Inside if of custom setting check'+commentQuery);
}
else if(!filterLabel.isEmpty() && commentFilter==true && !filterLabel.contains('Email')){
String srchValue = 'To:';
string tempInput = '%' + srchValue + '%';
commentQuery = commentQuery + ' And CommentBody LIKE \'%' + srchValue + '%\'';
System.debug('Inside first else of custom setting check'+commentQuery);
}
else if(!filterLabel.isEmpty() && !commentFilter==true && !filterLabel.contains('Email')){
commentQuery = commentQuery +' And Createdby.Id IN: Ids';
System.debug('Inside second else of custom setting check'+commentQuery);
}
else if(!filterLabel.isEmpty() && !commentFilter==true && FilterStringValue=='Email' && filterLabel.contains('Email')){
String srchValue = 'To:';
string tempInput = '%' + srchValue + '%';
commentQuery = commentQuery + ' And CommentBody LIKE \'%' + srchValue + '%\'';
System.debug('Inside third else of custom setting check'+ commentQuery);
}
else if(!filterLabel.isEmpty() && commentFilter==true && FilterStringValue=='Email' && filterLabel.contains('Email')){
commentQuery = commentQuery;
System.debug('Inside fourth else of custom setting check'+ commentQuery);
}
else if(!filterLabel.isEmpty() && commentFilter==true && filterLabel.contains('Email')){
commentQuery = commentQuery;
System.debug('Inside fifth else of custom setting check'+commentQuery);
}
I also used below query -
String startValue = 'To:';
commentQuery = commentQuery + ' And CommentBody NOT LIKE '+ startValue +'%\'';
Regards,
Sangeet
I am creating a filter with checkboxes, I want when case comment checkbox is true then all comment associated with case are shown and when we check checkbox Email, Then only comments which are added by mail should be shown means-
- If Email is check for email-to-case then only comment are shown which startsWith To:
- and If Case Comment is checked then except To: comments should be shown.
My sample code are -
if(filterLabel.isEmpty() && commentFilter==true){
System.debug('Inside custom setting Enable If query');
String srchValue = 'To:';
string tempInput = '%' + srchValue + '%';
commentQuery = commentQuery + ' And CommentBody NOT LIKE \'%' + srchValue + '%\'';
System.debug('Inside if of custom setting check'+commentQuery);
}
else if(!filterLabel.isEmpty() && commentFilter==true && !filterLabel.contains('Email')){
String srchValue = 'To:';
string tempInput = '%' + srchValue + '%';
commentQuery = commentQuery + ' And CommentBody LIKE \'%' + srchValue + '%\'';
System.debug('Inside first else of custom setting check'+commentQuery);
}
else if(!filterLabel.isEmpty() && !commentFilter==true && !filterLabel.contains('Email')){
commentQuery = commentQuery +' And Createdby.Id IN: Ids';
System.debug('Inside second else of custom setting check'+commentQuery);
}
else if(!filterLabel.isEmpty() && !commentFilter==true && FilterStringValue=='Email' && filterLabel.contains('Email')){
String srchValue = 'To:';
string tempInput = '%' + srchValue + '%';
commentQuery = commentQuery + ' And CommentBody LIKE \'%' + srchValue + '%\'';
System.debug('Inside third else of custom setting check'+ commentQuery);
}
else if(!filterLabel.isEmpty() && commentFilter==true && FilterStringValue=='Email' && filterLabel.contains('Email')){
commentQuery = commentQuery;
System.debug('Inside fourth else of custom setting check'+ commentQuery);
}
else if(!filterLabel.isEmpty() && commentFilter==true && filterLabel.contains('Email')){
commentQuery = commentQuery;
System.debug('Inside fifth else of custom setting check'+commentQuery);
}
I also used below query -
String startValue = 'To:';
commentQuery = commentQuery + ' And CommentBody NOT LIKE '+ startValue +'%\'';
Regards,
Sangeet
Why don't you try any of the below code snippets,
String srchValue = 'To:';
String tempInput = '%' + srchValue + '%';
String commentQuery = commentQuery + ' And NOT CommentBody LIKE: tempInput' ;
OR
String srchValue = 'To:';
String tempInput = '\'%' +srchValue + '%\'';
String commentQuery = commentQuery + ' And NOT CommentBody LIKE' + tempInput;
OR
String srchValue = 'To:';
String commentQuery = commentQuery + ' And NOT CommentBody LIKE' + '\'%' +srchValue + '%\'';