You need to sign in to do that
Don't have an account?
Eyal_Wiz
Automatic Create
Is there a way to add a custom button that automatically creates a new record in specific object.
For example:
I created a new custom object called "Invoices". I want to create a new button on the opportunity form that once clicked on- creates a new record on the "Inovices" custom object- using the data from the current opportunity record.
Is it possible to do such thing using Javascript?
Thanks,
Eyal
Code: Best, Steve.
I'll try that right away.
Thanks for the quick reply- I really appreciate it.
Eyal
It's like he's trying to open the new custom record but failing because the record isn't really there.
The code that is currently "e-retUTL" should have been "e?retURL" . So, a question mark instead of a dash, and spell URL correctly.
For example, this code works:
Code:
Steve - I read this post with interest as I need to do something similar but, rather than using a button, I would like this to happen on Save (dangerous I know). Essentially, we have a number of instances where once a certain object enters status, a new record on a related object needs to be created. For example, once we move an opportunity to "Sold" stage, I need to create a new "Delivery Project" (custom object). Currently, I am constantly educating my users that they need to do these two actions separately and, guess what, they forget and only do one of them.
Is this possible?
Your advice would be very much welcomed.
Regards,
Gordon.
Hi Gordon,
You can implement exactelly what you want using triggers. create a trriger on the opportunity object, the trigger will raise on update or insert. It should look something like this:
The current variant contains the data of the opportunity that caused the trigger to raise.
just change the "if" statement to the condition that you are looking for and thats it.
Hope this helps (If not feel free to ask),
Eyal
The only thing you should add in your case is an "if statment" to check the condition you've mentioned.
Well, with Apex it's easy and that would be the pretty way to go. Albeit expensive.
I don't think there's is a simple, clean way to override Save and interject your own behaviors and then return to the default Save behavior.
You could write your own s-control to do the entire job of editing the fields, then you can obviously do anything you want and save the data yourself, but that's way overkill and far too much work to be practical.
You could write an administrative s-control that only the admin would run (like once a week or day, etc.) which checks to see if any "Sold" stage opportunities do not have a Delivery project and create them as needed.
You could create an in-line s-control which checks the Stage and if it's equal to "Sold" goes and checks for a Delivery Project, creating one if needed. However, that relies on the user allowing the s-control to finish, not closing the window or navigating away, etc. Not hugely reliable, but perhaps doable. It's also slow because every time anybody brings up an opportunity to view it would do this check. (You could of course try to optimize it, perhaps first check if the time last modified is within the last 10 seconds, and only do the rest of the checks if it is, etc.)
No clean answers.
Perhaps you can accomplish something via an obvious message to your users? For example, you could create an in-line s-control to be displayed in the Opportunity page layout. This s-control simply looks at the status of the Stage, and if it's "Sold" displays: 'Remember to create a Delivery Project if you just marked this as "Sold" ' in glowing red flaming letters! :-)
Apex is the best answer... that's why they charge for it. I always find it interesting when SFDC says "yes, our platform can be used as a database", when they charge extra for one of the most basic database features... triggers.
Best, Steve.
If you did this, then at least you would be making the job far easier for your users, they could just click on the button (which could verify that it's "Sold" and no pre-existing Delivery Project object is already associated with this Opportunity), and it would create it for the users.
If the user doesn't have to enter any data, then they are done. If they do need to enter data, then the s-control could bring them directly to the Edit page for the newly created Deliver Project object.
That's very similar to the s-control code posted earlier in this thread.
Best, Steve.
Hi Eyal!
I Wonder if you could help me on this. I Found your message here and is exactly what I´m trying to do.
I Have a custom object named "Contratacao__c" and when the field "Status_do_Contrato__c" is filled with the value 'Emitir Boletos' it was suposed to create a new record on the related custom object "Faturamento__c".
But after insert or update a "Contratacao__c" record, the trigger below returns the following error:
Erro:O acionador CreateBilling do Apex causou uma exceção inesperada. Entre em contato com o administrador: CreateBilling: execution of AfterUpdate caused by: System.StringException: Invalid id: 0001282: Trigger.CreateBilling: line 8, column 36
Which means that the "Faturamento__c.Contrato__c" field related to the "Contratacao__c.name" is not filled with the right value.
In the above example, I have a record in "Contratacao__c" registered as "0001282" and the related record "Faturamento__c" should have a field "Faturamento__c.Contrato__c" filled with the same "0001282"
Faturamento__c.Contrato__C: Relationship field (Master and Detail)
Contratacao__c.name = automatica numbered
What am I doing wrong? How to Fix it?
Here´s the code:
Contratacao__c[] Contratos = Trigger.new;
if (Contratos[0].Status_do_Contrato__c == 'Emitir Boletos')
{
Faturamento__c Billing = new Faturamento__c (
Contrato__c = Contratos[0].name,
F__c = Contratos[0].Total_do_Contrato__c,
V__c = Contratos[0].Nascimento__c);
insert Billing;
}
}