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
Eyal_WizEyal_Wiz 

Opportunity Trigger

I've created a new custom object called "Class Registrations". I've created a new button called "create registration record" that once clicked on creates a new record for my custom object.
 
I've used Javascript to do it, this is the code I used:
 
Code:
<script language="JavaScript">
function redirect() 
{
parent.frames.location.replace( "/a0H/e—retUTL=/{Opportunity.id}" 
+ "&00N60000001K1qM={!Opportunity.Class_Price__c}" + "&save=0");
}
redirect();
</script>

 
Eyal_WizEyal_Wiz

I accidentenly submited the post before entering my question :smileyvery-happy:

Now I want the custom object record to be automatically created with a trigger. everytime a new oppertunity is inserted a custom object record should be created.

Can I use the same Javascript code inside the trigger? I tried to do that and I keep getting errors.

If I can't use javascript - can I do the same thing I did with apex code??

Thanks
Eyal

gokubigokubi
You're js code is filling a form in the Salesforce.com UI in order to create a record. That works in the way you're using it, but won't work in Apex. It's pretty easy to create records in Apex. Check out the language reference for lots of examples.

Here's a simple example of how to create a Contact:
Contact firstContact = new Contact (
 FirstName='Joe',
 LastName='Johanssen',
 MailingStreet='123 Elm St',
 MailingCity='Wauwatosa',
 MailingState='WI',
 MailingPostalCode='53213',
 MailingCountry='USA'   
);

insert firstContact;

 

Eyal_WizEyal_Wiz
It worked - thanks!
 
I did see this example but I didn't think it would work with custom objects as well.
Thanks!
 
JulsJuls
Hi,
 
I am currently trying to get Opportunities from Salesforce and I don't seems to be able to get it to work.  I got the account to work though.
 
If you are able to help me on this, please write me and I will provide you with more information.  Or anyone out there able to help, please write me.
 
Thanks.
 
Best regards
JS