You need to sign in to do that
Don't have an account?
Daniel B Probert
Dynamic object use within query.
i've confused myself
i have an object with 2 fields
Form Name (external reference and unique name that is stored within the form_id field within a different custom object)
ObjectName__c (formula field that based on name enter the correct custom object mycustomobject__c)
Salesforce_Record_Count__c (i want to put the number of records that match my search critera in here)
i then want to create a batch process that will do something like this:
so basically my challenge is how can I build my select count to use potentially a different customobject__c each time it runs.
I plan to limit this batch to only updating 20 records at time.
any thoughts or betters ways of doing this, please do as for clarification.
dan
i have an object with 2 fields
Form Name (external reference and unique name that is stored within the form_id field within a different custom object)
ObjectName__c (formula field that based on name enter the correct custom object mycustomobject__c)
Salesforce_Record_Count__c (i want to put the number of records that match my search critera in here)
i then want to create a batch process that will do something like this:
global class UpdateMonitoringForms implements Database.Batchable<sObject>{ string query; global Database.querylocator start(Database.BatchableContext BC){ Query = 'Select ID,Form_Name__c,Salesforce_Record_Count__c From Monitoring_Form__c'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<Monitoring_Form__c> scope){ List<Monitoring_Form__c> lstmforms = new List<Monitoring_Form__c>(); for (Monitoring_Form__c mf:scope) { string object = mf.ObjectName__c; IF(mf.ObjectName__c!= 'DO NOT PROCESS'){ mf.Salesforce_Record_Count__c = [select count() from object where Form_ID__c =:mf.Form_Name__c]; } lstmforms.add(mf) } update lstmforms; } global void finish(Database.BatchableContext BC){ } }
so basically my challenge is how can I build my select count to use potentially a different customobject__c each time it runs.
I plan to limit this batch to only updating 20 records at time.
any thoughts or betters ways of doing this, please do as for clarification.
dan
then it started working perfectly..
All Answers
I think you can do it by use of this.
First error: Only variable references are allowed in dynamic SOQL/SOSL.
any ideas i've been playing around with the code but just can't get past this error now..
then it started working perfectly..