#JS_Alternatives I have created a VF page button for Related list. However it is opening in a new window with white background leaving the parent record. Is there a way we can Open it on the same page? Attached image is the behavior.
@Vin Addala , Here is the same VF page which is creating a New record using sforce.one. If I close the window, I see only white background, it does not go back to Parent record unlike Classic.
<apex:page standardController="Opportunity" recordSetVar="opps" extensions="recordCreateExtension">
<script src="
https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<apex:includeScript value="/soap/ajax/28.0/connection.js"/>
<apex:includeScript value="/soap/ajax/28.0/apex.js"/>
<script type="text/javascript">
sforce.connection.sessionId = "{!$Api.Session_ID}";
$( window ).ready(function() {
createOpportunity();
});
var recordId = '{!$
CurrentPage.parameters.Id}';
var today = new Date();
var monthDigit = today.getMonth() + 1;
if (monthDigit <= 9) {
monthDigit = '0' + monthDigit;
}
var url ='/006/e?retURL=%2F&RecordType=012500000005Epb&opp3='
url +='DV '+"-"+ today.getFullYear() + "-" + monthDigit + "-" + today.getDate();
url +='&CF00N50000001oGFn_lkid='+recordId;
try{
var cons = sforce.connection.query("SELECT Id,Name,AccountId,
Account.NameFROM Contact WHERE Id = '" + recordId + "'");
//var records = sforce.connection.query(query);
var stats= cons.getArray("records");
url +='&CF00N50000001oGFn='+stats[0].Name;
url +='&CF00N50000001oGFd='+stats[0].
Account.Name;
url +='&CF00N50000001oGFd_lkid='+stats[0].AccountId;
url +='&opp4='+stats[0].
Account.Name;
url +='&opp4_lkid='+stats[0].AccountId;
var defaultValues = {
'Name' : 'DV '+"-"+ today.getFullYear() + "-" + monthDigit + "-" + today.getDate(),
'AccountId':stats[0].AccountId,
'Donor_Account__c':stats[0].AccountId,
'Donor_Contact__c':stats[0].Id,
'retURL':'/006',
'nooverride':'1'
}
}
catch(e){
alert('An Error has Occured. Error:' +e);
}
alert('MyId '+'{!$
CurrentPage.parameters.Id}');
function createOpportunity(){
if( (typeof sforce != 'undefined') && sforce && (!!sforce.one) ) {
sforce.one.createRecord('Opportunity','012500000005EpbAAE',defaultValues);
}else{
window.location='{!URLFOR($Action.Opportunity.New, null, [RecordType='012500000005Epb',save=1], true)}';
}
}
</script>
</apex:page>