You need to sign in to do that
Don't have an account?

Help with apex code reference
I have a custome object built names Config_Object__c from which i need to access the values to my scheduler class.
Here is the code. please suggest if you have any ideas.
My Config_Object__C has fields
1.HFSurveyCode__c="HF1Mrov'
2.Survey_Date__c
3.SOQL_query="Select o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c, o.Account.Survey_Code__c, o.Account.Name
From Opportunity o
where o.StageName='Active'
AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30
AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60"
Please suggest what should be done.
This is a wierd request, and potentially a bad thing to do. But, that's your issue. :-)
Your code isn't querying for the values of the Config_Object__c anywhere. This is a custom object, and there can obviously be multiple records in that object, each with different stored queries and query criteria. So, how are you going to determine which Config_Object__c record you want. Again, your issue, I'll assume you want the most recently created one.
However:
1. You should add a bunch of Try/Catch around several things here because the potential for bad queries is vast.
2. What happens to your code if the query stored in the Config object is, literally: "Select Peanuts from classic comix from the 1950s". Or, even better, "#T9834ugrewn3(*9r2", or even null. So, if you're going to let users store queries, you've better be sure they are valid queries. I'd think it's better to store the values that you want the user to be able to change and then build the query string yourself. At least then you can use validation rules to check the values, and you'll always have the fields that you require.
Best, Steve.
All Answers
Few things going on here:
1. You are going to have problems as strings within Apex are delimited with single quotes and the value in your custom field is also using them. try escaping single quotes in your query
2. Because you are dynamically creating the query string, you are using SOSL. SOSL rules are different and you should check out the docs on how to use them.
I basically dont have quotes, I can remove them.
The requirement is i should be able to enter any query in the SOQL_query filed and my scheduler class should be able to pick it up to my opportunity object.
Can you help me how to reference the code here.
My Config_Object__C has fields
1.HFSurveyCode__c="HF1Mrov'
2.(Date type)Survey_Date__c
3.(Text Area data type) SOQL_query=Select o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c, o.Account.Survey_Code__c, o.Account.Name
From Opportunity o
where o.StageName='Active'
AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30
AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60
This is a wierd request, and potentially a bad thing to do. But, that's your issue. :-)
Your code isn't querying for the values of the Config_Object__c anywhere. This is a custom object, and there can obviously be multiple records in that object, each with different stored queries and query criteria. So, how are you going to determine which Config_Object__c record you want. Again, your issue, I'll assume you want the most recently created one.
However:
1. You should add a bunch of Try/Catch around several things here because the potential for bad queries is vast.
2. What happens to your code if the query stored in the Config object is, literally: "Select Peanuts from classic comix from the 1950s". Or, even better, "#T9834ugrewn3(*9r2", or even null. So, if you're going to let users store queries, you've better be sure they are valid queries. I'd think it's better to store the values that you want the user to be able to change and then build the query string yourself. At least then you can use validation rules to check the values, and you'll always have the fields that you require.
Best, Steve.