Skip to main content
2 of 2
added 2 characters in body
Peter Knolle
  • 29.2k
  • 12
  • 104
  • 164

Is using a class a good option for creating a new Object and how could I send an error string to javascript?

Thank you for taking the time to look into my question, this is my first Apex/Salesforce project, I am familiar with Java and javascript.

I have been tasked to creating a new Object called 'Service Agreement' from the Opportunity. I just need to automate the creation of the object and fill in certain fields that I get from the Opportunity and related Quote, I also need to do some calculations and such. It seems to me that making a class is the best solution and calling the method within the class from a button in the Opportunity. So the button I assume should use Javascript.

My questions are as follows:

  1. Is this the best approach? ( I could use a db trigger but if the object is created outside of the Opportunity there would be errors)
  2. If I want to do alert('var') in javascript and also return a boolean of true or false is it possible? (I want to customize the visual errors this way for the user)

I will be using

CurrentPageId = ApexPages.CurrentPage().getParameters().get('id'); 

To get the id from the opportunity and then use SOQL to get the necessary field info.

Any opinions would be greatly appreciated, I have been reading into this, and becoming more and more confused

jnoel10
  • 1k
  • 1
  • 11
  • 25