Using JavaScript, you can open a new/edit page for a custom object and pass parameters by clicking on a

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)}

Answer №1

Use the following method to pass parameters:

window.location = "apex/yourCustomPage?param1={!Opportunity.Id}&param2={!Opportunity.Name}";

You can access these parameters directly on the visualforce page like this:

{!$CurrentPage.parameters.param1}

In the controller:

If (ApexPages.currentPage().getParameters().containsKey('param1'))
{
    yourVariable = ApexPages.currentPage().getParameters().get('param1');
}

To open a new window, use the following code:

window.open("apex/yourCustomPage?param1={!Opportunity.Id}&param2=edit";

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Regular expression that prohibits the acceptance of numbers with leading zeros

Below is the directive I am using to ensure that the input consists purely of numbers from 0-9. import { Directive, HostListener, ElementRef } from "@angular/core"; @Directive({ selector: "[numbersOnly]", }) export class OnlynumberDi ...

Displaying an image in a Bootstrap 5 tooltip / Issue 304

Working on a project using Bootstrap 5. I've implemented a tooltip that displays text and an image successfully by using data-bs-html="true". Here is how my input, including the tooltip, is structured: <input class="form-control ...

Angular - Execute a function once the observable has finished

I am currently working with a 2 part process that involves importing a list of usernames in Component 1, submitting it to a service, and then using the returned user profile data in Component 2. The issue I am facing is that when I receive the data back f ...

Execute JavaScript function after completion of CSS animation using jQuery

I'm working on an accordion feature that uses CSS animation to expand the clicked item. The expansion is triggered by li:target. However, I'm facing an issue where when clicking on an item, the scroll position doesn't align correctly with t ...

Only authenticated users are permitted to write to Firebase databases

Currently, I am in the process of setting up a new Vue JS project for a blog with Firebase integration. The main objective is to allow any logged-in user to create blog posts that are saved in the Firebase real-time database at https://xxx.firebaseio.com/b ...

Both Google Chrome and Firefox are recognizing the Binance WSS api url as an HTTPS connection

My attempt to execute the code from my Chrome browser was unsuccessful. import io from 'socket.io-client'; const socket = io('wss://stream.binance.com:9443'); socket.on('connect', () => { console.log('binance [so ...

A method to transfer a floating point number from Python to JavaScript without using cgi

Running an Apache server from a Raspberry Pi, I have a Python script that prints sensor input to the console. A PHP script then processes this output and controls a light based on the sensor reading before printing it again. Everything works fine when exec ...

Manipulating arrays of objects with handlebars.js

I need help with my node.js app that is returning JSON data for computers. { computers: { john: { cpu: "intel", ram: "8MB", hd: "1TB" }, jane: { cpu: "intel", ram: "12MB", hd: "500GB" }, mary: { ...

an all-encompassing loading animation designed specifically for updates to location.href

We have a situation where a customer's website is displaying extremely slowly within an iFrame, taking about 7 seconds to load. All we can do is provide the customer with a JavaScript file for inclusion on their site, as they are not willing to make a ...

Refresh the content of a webpage in AngularJS without the need to fully reload the entire page

Within my controller and view files, I have content that is sourced from various places, including API calls. For instance, I have information retrieved from the database where users can update certain details like their last name. After submitting the up ...

I am encountering difficulties while attempting to generate the chart series in Highcharts

This is just a demonstration https://jsfiddle.net/kkulig/0k4m5d2q/ I have made some changes to the original code Swapped out the following var originalCategories = [new Category('A'), new Category('B'), new Category('C')].m ...

The predicament encountered with user registration in the realm of Node.js

I am encountering a problem with the sign-up route in node.js and MongoDB. Whenever I attempt to post data using Insomnia, it displays an error message. You can find the screenshot of the error [here](https://i.stack.imgur.com/qnGAv.png). Here is the code ...

Updating two separate <DIV> elements with a single AJAX request

Can two different targeted DIVs be updated simultaneously using a single ajax call? Consider the index.html code snippet below: <script> xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.rea ...

Include some text before and after the bar element

I am attempting to insert text preceding and succeeding the bar, as depicted in the image below. <div class="container"> <div class="progress progress-info progress-striped"> <div id="storage-component" class="bar" style="wi ...

Create a duplicate of a div using JavaScript and modify the IDs of the inner elements within

I have two static div tags with a select tag and a text box inside, each with different IDs. When I clone the tag, it duplicates the same div tag in the DOM. How can I change the inner elements' tags? Below is the code snippet: <div id="m ...

Can you explain the concept of the "one true source"?

After reviewing this particular article, I came across a significant statement in the "Controlled Components" section: The integration of both can be achieved by ensuring that the React state is considered as the “single source of truth”. Can you ...

Encountered an error: Invalid usage of hooks. Hooks are intended to be called only within the body of a functional component. - issue with useEffect() function

Encountering an error while attempting to call a function imported within the useEffect() hook in Dashboard.jsx. The goal is to fetch data from the database upon page load, ensuring that users can send the correct credentials to the API with a button click ...

I encountered an error when attempting to integrate Node.js with my terminal in the text editor - permission was denied

After installing node.js and npm, I encountered permission issues when trying to run them from my text editor (VSC). I was advised to open the terminal within the text editor, drag and drop the .js files I'm working on, add "node" and hit "enter" to r ...

Changes in date format using jQuery datepicker

I am having trouble with the code below. Whenever I attempt to change the date, it switches from 15/5/2012 to 05/15/2012. <script> $(document).ready(function(){ $("#date").datepicker({ }); var myDate = new Date(); var month = myDa ...

retrieving identifiers from a separate table for an array of values

As a newcomer to node and noSQL databases, I am facing challenges in grasping the concept of passing an array of IDs and retrieving the corresponding values from another table. I have 'users' and 'products' tables in my database. The st ...