function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dbush2765dbush2765 

Possible to run APEX with user-selected options?

Fairly new to APEX, and just wasn't really sure on where to even start looking for this. Also haven't had a chance to learn any Visualforce, yet.

Is it possible to create APEX code that runs based off of what a user selects from a list of options? For example, say I had a batch setup that automatically does some stuff with Opportunities in a custom object. Is there anything I can put into that batch to make it so the user can select, before it runs, to only look at certain types of Opps? 

 

Essentially, I'm wondering if I can set the code up so that when it queries, for example, Opps, it selects the needed fields from Opp where Type equals *whatever types user selected*.

Tim BarsottiTim Barsotti

I don't believe you are referring to Apex Batchable context. You can have dynamic queries. You need to build your query string based upon the parameters the user enters then query with the string built.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_soql.htm