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
prats23prats23 

Dynamic Apex Application for requirement

Hi all,

We have a requirement of using data from 2 custom objects to do some calculations and feed calculated data as a new record into a 3rd object. The operation is to be done once a month and on click of a button or something.

I thought of using Dynamic Apex to create a class having code to calculate the required numbers after fetching records from 2 objects and feed into the 3rd object as new record. Also, to initiate the operation, i would put a custom button on the view page 3rd(calculated object) and on click of it the code (Dynamic apex) should run!

Is my thought process okay? Is it feasible in SFDC using Dynamic APex? Please suggest as i am new to SF development!

Also, i am having problem in attaching the apex class to the custom button! How to make the button run the code on click??

Please suggest! Thanks a lott!!

Best Answer chosen by Admin (Salesforce Developers) 
EalesieEalesie

Hi

 

There is nothing wrong with your thought process of using dynamic apex (by this I assume you mean dynamic SOQL), but if the calculation algorithm does not change, or the fields to be used by the calculation do not change then there is no real need to use dynamic SOQL, you create a utility class to perform the function.  

 

Consideration:  - If you will be querying/updating/inserting more than 10,000 records then you will need to use batch apex (read up on governor limits)

 

To execute Apex from a button or link you need to declare the class as global and the method you want to call as a webservice - javascript can then be used to execute the code.   See solution on -http://boards.developerforce.com/t5/Apex-Code-Development/Call-an-Apex-class-from-a-button/m-p/55709

 

Hope this helps

 

Ealesie

All Answers

EalesieEalesie

Hi

 

There is nothing wrong with your thought process of using dynamic apex (by this I assume you mean dynamic SOQL), but if the calculation algorithm does not change, or the fields to be used by the calculation do not change then there is no real need to use dynamic SOQL, you create a utility class to perform the function.  

 

Consideration:  - If you will be querying/updating/inserting more than 10,000 records then you will need to use batch apex (read up on governor limits)

 

To execute Apex from a button or link you need to declare the class as global and the method you want to call as a webservice - javascript can then be used to execute the code.   See solution on -http://boards.developerforce.com/t5/Apex-Code-Development/Call-an-Apex-class-from-a-button/m-p/55709

 

Hope this helps

 

Ealesie

This was selected as the best answer
prats23prats23

Hey Ealesie!

 

Thanks a lot.. the button really worked =) I created a apex class and excuted it via button.. records are getting inserted!

 

Thanks again!