Skip to main content
Mod Moved Comments To Chat
added 114 characters in body
Source Link
David Reed
  • 93.7k
  • 14
  • 90
  • 166

You need to build out a dynamic query and you'll also need to loop through the scope records so you can run the query and get the IDs for them all.

// Set for storing found ids Set ids = new set();

//Loop through scope for(sObject s:scope){

// Set variables String objectname = s.Objects__c; String fieldname = s.Fields__c; String targetvalue = s.Field_Value__c;

// Build query String query = 'SELECT Id FROM' + objectname + 'WHERE' + fieldname + '= : ' + targetvalue;

// Loop through query and add Ids to set for(sObject sob:Database.query(query)){

Ids.add((String) sob.get(id));

}

// Set for storing found ids
Set<string> ids = new set<string>();

//Loop through scope
for(sObject s:scope){

// Set variables
String objectname = s.Objects__c;
String fieldname = s.Fields__c;
String targetvalue = s.Field_Value__c;

// Build query
String query = 'SELECT Id FROM' + objectname + 'WHERE' + fieldname + '= : ' + targetvalue;


// Loop through query and add Ids to set
for(sObject sob:Database.query(query)){

Ids.add((String) sob.get(id));

}

Then you attachment query should yield some results.

Might need some tweaking on phone

You need to build out a dynamic query and you'll also need to loop through the scope records so you can run the query and get the IDs for them all.

// Set for storing found ids Set ids = new set();

//Loop through scope for(sObject s:scope){

// Set variables String objectname = s.Objects__c; String fieldname = s.Fields__c; String targetvalue = s.Field_Value__c;

// Build query String query = 'SELECT Id FROM' + objectname + 'WHERE' + fieldname + '= : ' + targetvalue;

// Loop through query and add Ids to set for(sObject sob:Database.query(query)){

Ids.add((String) sob.get(id));

}

Then you attachment query should yield some results.

Might need some tweaking on phone

You need to build out a dynamic query and you'll also need to loop through the scope records so you can run the query and get the IDs for them all.

// Set for storing found ids
Set<string> ids = new set<string>();

//Loop through scope
for(sObject s:scope){

// Set variables
String objectname = s.Objects__c;
String fieldname = s.Fields__c;
String targetvalue = s.Field_Value__c;

// Build query
String query = 'SELECT Id FROM' + objectname + 'WHERE' + fieldname + '= : ' + targetvalue;


// Loop through query and add Ids to set
for(sObject sob:Database.query(query)){

Ids.add((String) sob.get(id));

}

Then you attachment query should yield some results.

Might need some tweaking on phone

Source Link

You need to build out a dynamic query and you'll also need to loop through the scope records so you can run the query and get the IDs for them all.

// Set for storing found ids Set ids = new set();

//Loop through scope for(sObject s:scope){

// Set variables String objectname = s.Objects__c; String fieldname = s.Fields__c; String targetvalue = s.Field_Value__c;

// Build query String query = 'SELECT Id FROM' + objectname + 'WHERE' + fieldname + '= : ' + targetvalue;

// Loop through query and add Ids to set for(sObject sob:Database.query(query)){

Ids.add((String) sob.get(id));

}

Then you attachment query should yield some results.

Might need some tweaking on phone