Salesforce Opportunity Confirmation Warning on Save - salesforce

I'm trying to get a Yes/Cancel confirmation screen to appear when a user tries to save a opportunity with a "Proposal" stage that asks "Are you sure?"
The route I'm taking is adding a Visualforce page to a standard Opportunity object. The code I've included launching the confirmation window after it's been saved
Please help!
Error 1 enter image description here
Error 2 enter image description here
<apex:page standardController="Opportunity" rendered="{!Opportunity.StageName == 'Proposal Request'}">
<script type="text/javascript">
{ window.alert("Are you ready to send a proposal?"); }
</script>
</apex:page>

You can achieve this by Jquery and call the below while loading the page.
var htmlhead = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
var$g=jQuery.noConflict();$g(function({$g('head').append(htmlhead);$g('head').append('<linkrel="stylesheet"href="yourstaticresources"type="text/css"media="all"/>');$g('body').append('Any dialog box');$g("#dialog").dialog({autoOpen: true,buttons: {'{!$Label.Yes}': function() {ifYes();},'{!$Label.No}': function() {$g(this).dialog("close");}}});})} else{ifNo();}}
This will open dialog box with Yes or No. Handle your logic accordingly

Related

How To Lock Code With password in reactjs

I Want To Add a Password System To My Code To Prevent My Code From Being Run By Someone else, is There Any Way How Can i do so?
Interface can be like asking for password before starting development server in reactjs
I have put together an example of what I meant in the comments:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>SourceCode Encryption example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.8/sjcl.min.js" integrity="sha512-s0r9TyYSs5CusSDL5s/QEZQZ4DNYLDXx0S+imS+SHR9mw0Yd0Z5KNS9dw7levSp7GpjOZu/bndds3FEDrKd8dg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body>
<script type="text/javascript">
// Hide this part from the end user
var password = "MySourceCodePassword";
var sourceCode = 'alert(\'Ur name is: \' + prompt("What is ur name?"))';
var encryptedSourceCode = sjcl.encrypt(password, sourceCode);
// User endpoint code
// You would have the encryptedSourceCode stored into an string and only
// is the propper key is used then it would be decrypted and evaluated.
try {
var userPassword = prompt("Whats the sourceCode password?");
eval(sjcl.decrypt(userPassword, encryptedSourceCode));
} catch (error) {
alert(error.message);
}
</script>
</body>
</html>
In your case you would have to provide your encoded Reactjs code and the required html dom element, I have simplied this example wrapping it in an html page and prompting the user for a password but u could use a form or whatever you might require.
Be aware that once the know the key to decrypt the will be able to see your javascript source code, and so far it is the way it works, since the browser need to read javascript you cannot hide it from it. If you wanna make it harded you can always minify so it is harder to read.

cant redirect outside an iframe with cakephp3

I have an application where I need to redirect to a website ( example below). My issue is that the cakephp3 application is embedded in a wordpress iframe and for some reason the below command executes inside an iframe so i have a webpage within a webpage. How can i redirect to a webpage outside an iframe?
//controller
if ....
return $this->redirect('http://www.xxxxxx/thank-you-application/');
What goes on in Vegas, stays in Vegas
What goes on in an iframe, stays in that iframe
I don't think what you want is possible with PHP (and any PHP framework),
Maybe with getting the content of the page that you want to load inside the iframe with:
$http = new Client();
$response = $http->get('http://example.com');
$content = $response->body();
and put the $content in the view in the "top level page / mean not inside iframe" (like they do in financial website), but i'm not sure of the exact way.
the easiest solution is to send in your controller a value ($redirect = true) to the view that will say: "Hey! view, plz open this link to the top level window! / mean outside the iframe".
write something like this in your view (or template):
<!-- ... -->
<?php if($redirect) : ?>
<body onload="javascript:window.top.location.href='<?= $this->Url->build([
"controller" => "Pages",
"action" => "display",
"thank-you"
]) ?>'";>
<?php else: ?>
<body>
<?php endif; ?>
<!-- ... -->
Hope it helps

Why is data not received from node server to angular client?

I've the following SETUP: AngularJS for UI, MongoDB for database and Node.js for server.
FUNCTIONALITY of my web page: It is tabular website and 3 tabs to enter details all of which is saved to Database and one tab called EDIT/DOWNLOAD to display specific details like 4-5 columns(fields) of each row(document) and further, for each document displayed there is an option to edit or download details.
WORK FLOW: on click of tab EDIT/DOWNLOAD a function [ say viewDatabaseDetails()] is called which in turns gets those details to be displayed as a table for each document in database.
On click of download button again that specific document detail goes to NODE and then calls the specific document and save it all according to a template text file and send that file for download to client and deletes that file.
On click of edit button, it again picks up data and populate those 3 tabs where user has to enter but here any changes made is updated in database instead of saving as a new document.
ISSUE: : When I click on function viewDatabaseDetails(), sometimes Angular displays data, sometimes it fails. Success of receiving data to display varies between 1-4 clicks on tab button to call viewDatabaseDetails(). Also, when I click on download button, sometimes files is received for download on the first click, sometimes after clicking on download button for 2-4 times file is received by client. I have checked node part on console, angular is sending all the details correctly every single time I click on download button or viewDatabaseDetails(), node is doing all the processing like data operations, creating file to send, creating proper response to send all the documents details but somehow it is not being received by angular.
What might be happening is either the data is lost in network or timeout happens before receiving data/file as only server to client communication has issue. I checked network console in IE [i've a restriction to use only IE] upon success time taken is greater than time taken upon failure.
EDIT:
Error explained according to below code: When I click on view button in UI, sometimes data is displayed correctly, sometimes I get error as SyntaxError: Invalid Character.
UI:
<button ng-click="viewDatabase()"> View </button>
Controller:
$scope.viewDatabase = function(){
$http.get('/getDatabase').success(function(response){
$scope.outputs = response;
}).error(function(){
console.log("error");
});
};
UI: for displaying response
<div>
<table>
<tr>
<td>Name </td>
<td>City </td>
<td>Country </td>
</tr>
<tr ng-repeat="output in outputs">
<td>{{output.Name}} </td>
<td>{{output.City}} </td>
<td>{{output.Country}} </td>
</tr>
</table>
</div>
Node and MongoDB code:
//other require statements
var mongoose = require('mongoose');
var db = mongoose.connect(ConnectionString:port);
var PropertyFileSchema = new Schema({
Name: String,
City: String,
Country: String
});
PropertyFile = db.model('PropertyFile', PropertyFileSchema');
http.createServer(function(req,res){
//putting only required part of code
if(req.url=="/getDatabase"){
res.writeHead(200,{'content-type': 'application/json'});
PropertyFile({},'Name City Country', function(err, docs){
console.log(docs); //always displays if anything in database
res.end(JSON.stringify(docs));
});
}
});

Http-post parameters and display response in a browser using Silverlight and JavaScript

While doing Silverlight's interoperability with JavaScript I've faced a strange behaviour in my Silverlight Out-of-Browser (OOB) application. My goal is to http-post some data to the specific site. We can post data using WebClient or HTTPWebRequest classes. But then how to redirect the response to external web browser?
I thought I would generate a dynamic HTML form with post method and invoke a JavaScript function from Silverlight which would submit the form. Unfortunately it only submits the form with target="_self" and not with target="_blank".
Code for loading generated html string into Silverlight's WebBrowser control:
WebBrowser wb = parameter as WebBrowser;
if (wb == null)
return;
wb.NavigateToString(GetHtml());
Simple test method to generate HTML:
private string GetHtml ()
{
StringBuilder sb = new StringBuilder ();
sb.Append ("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
sb.Append ("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
sb.Append ("<head><title></title>");
sb.Append(
"<script type=\"text/javascript\">function submitForm(){" +
"document.forms[0].submit(); window.external.notify(\"Form Submitted!\");}</script>");
sb.Append("</head>");
sb.Append ("<body>");
sb.Append ("<form id=\"mainForm\" name=\"formName1\" action=\"http://localhost:53222/ReceivePost.aspx\" method=\"POST\" target=\"_blank\">");
sb.Append ("<input type=\"text\" name=\"u\" value=\"username\"/>");
sb.Append ("<input type=\"password\" name=\"p\" value=\"password\"/>");
sb.Append ("<input type=\"submit\" value=\"Submit\"/>");
sb.Append("</form>");
sb.Append("</body></html>");
return sb.ToString ();
}
which generates such HTML page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function submitForm(){
document.forms[0].submit();
window.external.notify("Form Submitted!");
}
</script>
</head>
<body>
<form id="mainForm" name="formName1" action="http://localhost:53222/ReceivePost.aspx" method="POST" target="_blank">
<input type="text" name="u" value="username"/>
<input type="password" name="p" value="password"/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
And the code for invoking JS function:
innerWebBrowser.ScriptNotify += (o, args) =>
{
MessageBox.Show("JS says: " + args.Value);
};
innerWebBrowser.InvokeScript ("submitForm");
As I said, this code works fine with target set to "_self" but doesn't work with target set to "_blank". Even if I press Submit button with a mouse the post data is not sent, just web site is rendered in external browser without post data. Is it due to the security mechanism in Silverlight? I should also mention that I am posting to the same site where Silverlight app is published: http://localhost:53222 (well it's not published yet as I run it straight from VisualStudio in OOB mode). Thus it shouldn't be categorized as cross-site scripting I guess...
Is there any way to post data to some website (not necessarily from the same domain) and redirect the response to external browser?
Anyway, your comments are most welcome.
I've come up with a workaround which performs exactly what I wanted (starts external browser and loads specific web site while posting some parameters to it). Instead of using WebBrowser control HTML file (similar as in the question) with Form and a JavaScript to submit the form onLoad event is generated. Then the generated HTML content is written into the file system and started with default browser later on.
File may be created with similar code:
using (StreamWriter file = File.CreateText (filePath))
{
file.WriteLine (GetHtml());
file.Close ();
}
Default browser may be opened with something like the following code:
using (dynamic shell = AutomationFactory.CreateObject ("WScript.Shell"))
{
shell.Run (filePath, 7, false);
}
And after the default browser is up and running we may delete the file we just generated:
if (File.Exists (filePath))
{
File.Delete (filePath);
}
Please note that in order to create/delete a file your SL application needs to be trusted application. That is, it has to have elevated permissions (check Application.Current.HasElevatedPermissions property).
Access local file system in Silverlight 5. In SL 4 one could use com interoperability and Scripting.FileSystemObject to access local file system.

ajaxSubmit does not reload page after first request (in CakePHP)

I'm creating a CMS which has a page edit section. I'm trying to create a Preview function. It works fine on the first attempt, but if you then change some text and preview again, the preview is the old version. It also appears very quickly. It's as if the ajaxSubmit function doesn't bother reloading the page.
I tried to get round this by changing the url each time (by adding on a timestamp to the end), but this made no difference. I'm using jquery, cakePHP and fck editor.
Here's what I have:
<script type="text/javascript">
$('#page_modal').jqm();
$('#preview_btn').click(function(e){
// Get current page content from fck iframe
var oEditor = FCKeditorAPI.GetInstance('PageContent');
var newcontent = oEditor.GetData();
$('#PageContent').html(newcontent);
// Submit form via Ajax
var d=new Date();
var t=d.getTime();
var thisurl = '/admin/pages/preview/' + t.toString();
$('#ajaxForm').ajaxSubmit({
url: thisurl,
error: function(XMLHttpRequest, textStatus, errorThrown){
alert(textStatus);
},
success: function(responseText){
$('#page_modal').jqmShow().find('#page_modal_content').html(responseText);
}
});
e.preventDefault();
});
</script>
As I said, it works fine first time, but then on subsequent calls the content is not updated. Can anyone suggest anything?
Try marking the view (/admin/pages/preview) with no cache. In the actual view put:
<cake:nocache>
// your view content here
</cake:nocache>
It may be that the view is being cached by cake so it does not update with subsequent calls.
http://book.cakephp.org/view/347/Marking-Non-Cached-Content-in-Views

Resources