0

I have one text field on obj A , which stores ids of objB in below format

field 1 ='a712D000000AZ3yQAG','a712D000000AZ46QAG'

Now I have to query the objectB based upon the stored ids in field1. Below soql is not working

List<objA> alsit=[select id from objA where id IN : field1];

how to do achieve this? pls help on this

1 Answer 1

2

You need to parse these ids to List (remove single-quotes on both sides of field1 and split the result on ','):

String field1 = '\'a712D000000AZ3yQAG\',\'a712D000000AZ46QAG\'';

List<String> ids = new List<String>();
if (String.isNotBlank(field1)) {
    field1 = field1.substring(1, field1.length() - 1); // this removed single-quotes on both sides of field1
    ids = field1.split('\',\'');
}

List<objA> alsit = [SELECT id FROM objA WHERE id IN : ids];

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .