Get parent id on related list new button's click.Salesforce lightning component.
In this post I will explain how to get parent id from a related list New Button click.
If you are working on an object which is accessible from another object's related list so you might have a situation to get the Parent record id while creating a record from related list.
Here is code below to get parent id from url.
helper.js
getParameterByName: function(component, event, name) {
name = name.replace(/[\[\]]/g, "\\$&");
var url = window.location.href;
var regex = new RegExp("[?&]" + name + "(=1\.([^&#]*)|&|#|$)");
var results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
controller.js
var value = helper.getParameterByName(component , event, 'inContextOfRef');
Share this blog with your friends if you find this post useful.
2 Comments
No use
ReplyDeleteThis snippet will not work for mobile version
ReplyDelete