You need to sign in to do that
Don't have an account?
SMaster
How to Create a new record in the related list of an opportunity??
Hi,
I want to create a new record in the related list of the Opportunity, using the visualforce button on the Opportunity Page layout.
I have an Proposal object as a related list in an opportunity. Whenever a user click a button on the oportunity page layout a new record inside Proposal should get created.... how can i achieve that??
At first reading,
We understand like you are creating Prpoposal record on button click,
To create this proposal record you are using some information from current opportunity,
steps
Create a detail Page button on Opportunity object, with content source as execute javascript.
you can use sforce.connection.create call from ajax toolkit.
dont miss to link current Opportunity record to newlly created Proposal record.
after successful insert, reload the page,
you can see newlly created record in related list
If you face any issue, let me know your Custom object API name and Opportunity -to-Proposal field Mapping
I will help you for script
Cheers,
Bala
All Answers
At first reading,
We understand like you are creating Prpoposal record on button click,
To create this proposal record you are using some information from current opportunity,
steps
Create a detail Page button on Opportunity object, with content source as execute javascript.
you can use sforce.connection.create call from ajax toolkit.
dont miss to link current Opportunity record to newlly created Proposal record.
after successful insert, reload the page,
you can see newlly created record in related list
If you face any issue, let me know your Custom object API name and Opportunity -to-Proposal field Mapping
I will help you for script
Cheers,
Bala
Hi Bala,
You have understood this absolutely correct...
My Custom Object API name is opportunity_proposals__c and in this custom object i have a custom field Opportunity__c ( a lookup to an opportunity)
i need to create the proposal record with proposal name as an opportunity name followed by "Proposal".
I am really looking forward to it....
Thanks
Hi Bala,
I am using the following code:
{!requireScript("/soap/ajax/20.0/connection.js")}
{!requireScript("/soap/ajax/20.0/apex.js")}
var t1= new sforce.SObject("opportunity_proposals__c" );
//t1.Proposal_Name__c = "{!Opportunity.Name}" + "Proposal";
t1.Opportunity__c = "{!Opportunity.Name}";
result = sforce.connection.create([t1]);
alert(result );
But i am not able to relate an opportunity with newly created record... and the record is not getting created... please let me know what have i missed??
you was very close to success,
You was trying to link newly created record by name, which should be by Id
One more suggestion always do any DML inside try----catch
Here is updated code
this will work for you, let me know
Cheers,
Bala
Hi Bala,
Its done sucessfully.... :)
Actually my requirement is something like... I need a button on the opportunity page layout.. as i click on that button, I should have two options...
<Option1> for Creating a new record in the related list (opportunity_proposals__c) of opportunity and go back to an opportunity page. [Now this is happening on clicking of a button]
<Option2> for Creating a new record in the related list (opportunity_proposals__c) of opportunity and go back to the new record created page (i.e. Record created in the related list)
Please suggest the way of doing this....
Give me some time .. we have an idea :)
Hey this is for you
just copy and run above code. [you can update message as per your business need]
Cheers,
Bala
Hi Bala,
You have just dropped me out of this trouble.... :)
Just wanted to know is there any way to change the Button Labels... I mean in place of Ok.. if i want to write "See the newly created record" or something like it..... I certainly don't know wheather this can be achieved or not.....
Oooops Its our Bad :(
It is not possible to change button text with confirm window , we need to stop here :(
Instead of thinking button labels, You can show more meaningfull message on Confirm window. This is the only way
Cheers,
Bala
Okay Bala,
Thanks for confirmation.. even i doubted about it..
Thanks
Great..... :)