0

Is there any way to autofill custom fields without using a trigger while still using Apex code? I have fields that are aimed to be filled in based on more complex logic and accessing information of related list object information. I read something that I could make a VisualForce Page that will autopopulate the fields? In addition, the only use I know of for Apex Classes is calling them in Apex triggers. If there was a way for an Apex Class to initially fill in the fields based on my apex code, that would be ideal: I could run this class at any time I choose and my fields will be updated accordingly.

EDIT: for context, I have many contacts ALL of which I want to batch update certain fields. I do not want to use a trigger as that will only update the object associated with the insertion/update the trigger was fired upon. I want to use my code as a way to mass populate all objects fields based on some more advanced logic.

Any suggestions will help greatly.

closed as off-topic by Sebastian Kessel, Pranay Jaiswal, Vijay Ganji, Mohith Shrivastava, Reshma Jun 17 at 8:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – Sebastian Kessel, Pranay Jaiswal, Vijay Ganji, Mohith Shrivastava, Reshma
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Why don't you want to use triggers? Can you edit your question to be clearer about the design intent, user experience, sequence of operations you are trying to perform? – David Reed Jun 10 at 20:15
  • yeah, sure. no problem. Let me know if I am still not clear – Sarah Jun 10 at 20:27
  • 1
    @Sarah A formula field might work: help.salesforce.com/… – identigral Jun 10 at 20:51
1

This sounds like a perfect use case for batch apex

You can create a batch class that loops through all your contacts and populates the fields based on the logic you define.

To run the batch, you have two options:

  • Run in manually through the developer console using anonymous apex (which is a way of calling apex on the fly)
  • Create a scheduled class that can call your batch class on a daily basis. See apex scheduler

Bonus: You mentioned you only know about apex being called from apex triggers. You can call apex classes from the following:

  • visualforce pages through visualforce controllers
  • anonymous apex
  • batch and scheduled apex
  • Via the process builder or flows

Not the answer you're looking for? Browse other questions tagged or ask your own question.