Monday, 10 March 2014

yes/no confirm pop up dialog box using jquery.





Hi Guys,

I am writing this post because some one comment on my blog and asked me for this requirement, i am happy to help him,

http://anuragsfdc.blogspot.in/p/salesforce-limits.html

his requirement is to show Yes /No buttons in place of Ok/Cancel buttons of javascript confirm function.

so for this i am creating a custom pop up dialog using JQuery.

here the code for same:-

<apex:page>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"/>
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script>
// jquery funtion for pop up.
$(function () {
$('#a').click(function(){
$( '<div></div>' ).dialog({
resizable: false,
height:140,
modal: true,
open: function() {
var markup = 'Are You Sure?';
$(this).html(markup);
},
title: "Confirmation",
buttons: {
"Yes": function() {
$( this ).dialog( "close" );
yesFunction();
},
"No": function() {
$( this ).dialog( "close" );
}
}
});
});
});
function yesFunction(){
// Write you code/logic of js here...
alert("call Apex method.");
}
</script>
<apex:form>
<h4>Click on Button for custom pop up. </h4>
// Button.
<div id="a" class="btn">
Ok
</div>
</apex:form>
</apex:page>
view raw jQueryPOPup hosted with ❤ by GitHub
here the screen shot:-


hope it helps, happy coding...

Thanks

Friday, 7 March 2014

SOQL Query on vf page using javascript without any controller.






Hi friends,

Many times you need record value on vf page for validation / viewing or for any other reason,
then you have to write a custom controller for query record.

here the example which show how you can query from vf page without any controller,
simply use JavaScript for query.


you can change the query according to your requirements.

<apex:page id="pageId">
<head>
<script src="/soap/ajax/20.0/connection.js" type="text/javascript"></script>
<script>
window.onload = function() {
var output = document.getElementById("output");
var startTime = new Date().getTime()
try {
sforce.connection.sessionId = "{!$Api.Session_ID}"; //Used for Session out
var queryResult = sforce.connection.query("Select Name, Industry From Account where Name != null");
layoutResults(queryResult, output, startTime); // call method.
} catch(error) {
queryFailed(error, output);
}
}
//if failed for Query
function queryFailed(error, out) {
out.innerHTML = "<font color=red >An error has occurred:</font> <p>" + error;
}
//if gets Results and pass to 'out' variable
function layoutResults(queryResult, out, startTime) {
var timeTaken = new Date().getTime() - startTime;
if (queryResult.size > 0) {
var output = "";
var records = queryResult.getArray('records');
for (var i = 0; i <records.length; i++) {
var account = records[i];
output += account.Name + " [Industry - "+ account.Industry + " ]<BR>";
}
out.innerHTML = output + "<BR> query complexed in: " + timeTaken + " ms.";
}
else {
out.innerHTML = "No records matched.";
}
}
</script>
</head>
<body>
<div id="output">
</div>
</body>
</apex:page>
view raw QueryOnVFPage hosted with ❤ by GitHub
Hope it helps
happy coding...:)
thanks
Anurag Jain