In order to have a custom button on the opportunity page, both the custom object and opportunity pages have been configured with page layouts for new & edit pages, not VF. The goal is to achieve the following: 1) When clicking on the button for the first time, it should open the "new" page of the custom object. Subsequent clicks should open the "edit" page. 2) It is also necessary to pass two or more parameters from the opportunity page to the new/edit pages, primarily for the new page.
3) Upon saving on the custom object page, the redirect should go to the opportunity view page.
Please provide a sample javascript or a better approach to accomplish this. The Javascript snippet below has caused some issues:
var oppId = "{!Opportunity.Id}";
If ({!Opportunity.PQQ__c})
{!URLFOR($Action.PQQ__c.New, null,
[
"PQQ__c.Name"="{!Opportunity.Name}",
"PQQ__c.Opportunity__c"="{!Opportunity.Id}",
"save"="1",
"retURL"=URLFOR($Action.Opportunity.View, oppId)
],
true)}
else{{!URLFOR($Action.PQQ__c.Edit, null,
[
"PQQ__c.Name"="{!Opportunity.Name}",
"PQQ__c.Opportunity__c"="{!Opportunity.Id}",
"save"="1",
"retURL"=URLFOR($Action.Opportunity.View, oppId)
],
true)}