0

I have a request to replace contact personal information(name,phone, email) from task object. I have added all the personal info into a list of String, and I want to find out all the task records whose description/subject field contains any of the string in that list and do a replace by looping through the found tasks.

I have tried to use like: but it is not working. Thank you very much for your help!

for(task tsk: [SELECT Id, Subject, Description FROM task WHERE Subject Like :toBeReplaced]){
                    tskToUpdate.add(tsk);
                }
  • Please specify what should be replace with what? – Reshma Dec 20 '18 at 5:59
  • I want to basically scramble the data, so replace them with string 'GDPR' so we can know those information are redacted because of GDPR policy. – Yi Tan Dec 20 '18 at 17:15
0

You forgot add % around toBeReplaced.

String queryStr = 'SELECT Id, Subject, Description FROM task WHERE Subject Like : %' + toBeReplaced + '%';
for(task tsk: database.query(queryStr)){
                    tskToUpdate.add(tsk);
                }
  • thank you! it gave me this error message: no viable alternative at character '%' – Yi Tan Dec 20 '18 at 17:14
  • I did a slight change around '%' and the error seems like gone. String queryStr = 'SELECT Id, Subject, Description FROM task WHERE Description Like ' + '\'%'+ toBeReplaced + '%\''; for(task tsk: database.query(queryStr)) tskToUpdate.add(tsk); system.debug('tskToUpdate '+ tskToUpdate); – Yi Tan Dec 20 '18 at 17:29
  • But I had a new error: Description field can't be filter on query call.. I will need to search text in description which contains personal information. I have tried SOSL to get all tasks, but SOSL can't query archived tasks, and we have a lot of archived tasks need to be scrambled as well. Please advice. thank you! – Yi Tan Dec 20 '18 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.