You need to sign in to do that
Don't have an account?
chrismclaren
function main(){
var d = new Date();
d.setDate(d.getDate()-130);
var orden = new Array();
orden.count = 0;
sforceClient.QueryAllSorted("select Id, My_Commision__c, Name, CloseDate,
function displayResults(opps)
{
totallength = opps.length;
Retrieving record count to file
I'd like to be able to create a query then return the record count and store this into a file. I can do all this but store it into a file. I have managed to sumbit the query, retireve the data and then store the array count into a variable. I cannot then print this record count to a file. Can anyone help. This is the code.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>AOC</title>
<script
<html>
<head>
<title>AOC</title>
<script
" type="text/javascript"></script>
<script type="text/javascript">
function load(){
sforceClient.registerInitCallback(main);
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", true);
}
<script type="text/javascript">
function load(){
sforceClient.registerInitCallback(main);
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", true);
}
function main(){
var d = new Date();
d.setDate(d.getDate()-130);
var orden = new Array();
orden.count = 0;
var cd = new Array();
cd.push("CloseDate");
cd.push("ASC");
var n = new Array();
n.push("Name");
n.push("DESC");
orden.push(cd);
orden.push(n);
cd.push("CloseDate");
cd.push("ASC");
var n = new Array();
n.push("Name");
n.push("DESC");
orden.push(cd);
orden.push(n);
sforceClient.QueryAllSorted("select Id, My_Commision__c, Name, CloseDate,
Amount from Opportunity" , orden);
}
}
function displayResults(opps)
{
totallength = opps.length;
var out ="";
out += ""
document.getElementById("DivWritetext").innerHTML = out;
}
sforceClient.QueryAllSorted = function(soql, sort_orders) {
sforceClient.sortArray = sort_orders;
sforceClient.sobjects = new Array();
this.Query(soql, queryCallback);
}
sforceClient.sortArray = new Array();
queryCallback = function(ret) {
if (ret.size > 0){
sforceClient.sobjects = sforceClient.sobjects.concat(ret.records);
if (ret.done == false){
sforceClient.queryMore(ret.queryLocator, queryCallback)
} else {
displayResults(sforceClient.sobjects.sort(sortSObject));
sforceClient.sobjects = new Array();
this.Query(soql, queryCallback);
}
sforceClient.sortArray = new Array();
queryCallback = function(ret) {
if (ret.size > 0){
sforceClient.sobjects = sforceClient.sobjects.concat(ret.records);
if (ret.done == false){
sforceClient.queryMore(ret.queryLocator, queryCallback)
} else {
displayResults(sforceClient.sobjects.sort(sortSObject));
}
}
}
}
}
</script>
</head>
<FORM ACTION="https://na1.salesforce.com/home/home.jsp">
<div style="position: absolute; left: 640px; text-align: center; top: 29px; width:
</head>
<FORM ACTION="https://na1.salesforce.com/home/home.jsp">
<div style="position: absolute; left: 640px; text-align: center; top: 29px; width:
155px; height: 44px; font-family: Bradley Hand ITC; font-weight: bold; font-size:
14pt">
<INPUT TYPE=submit value="Salesforce.com" style="position: absolute; left: 1;
<INPUT TYPE=submit value="Salesforce.com" style="position: absolute; left: 1;
text-align: center; top: 0; width: 152px; height: 43px; font-family: Bradley Hand ITC;
font-weight: bold; font-size: 14pt">
</FORM>
<body onLoad="load();">
<div id=DivWritetext>
<script
</FORM>
<body onLoad="load();">
<div id=DivWritetext>
<script
src='https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js?browser=true
' type='text/javascript'>
var fso = new ActiveXObject("Scripting.FileSystemObject");
var newFileObject = fso.CreateTextFile("C:\\acccounts.txt",true);
newFileObject.WriteLine ("1");
newFileObject.Close();</script>
</div>
var fso = new ActiveXObject("Scripting.FileSystemObject");
var newFileObject = fso.CreateTextFile("C:\\acccounts.txt",true);
newFileObject.WriteLine ("1");
newFileObject.Close();</script>
</div>
</body>
</html>
</html>
did you check return values for the activeX calls?
I tried this once, found it was very tricky and basicaly a security risk to allow a web page to write to the user's hard disk. several browser settings must be correct to allow active x to write to your hard disk, i eventualy gave up as this is not portable across supported browsers.
if you close the object, does that save it ?
just guessing, but you may just need a flush() or save() before closing the object. unless write() does that for you.
<html>
<head>
<title>sort</title>
<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js?browser=true" type="text/javascript"></script>
<script type="text/javascript">
sforceClient.registerInitCallback(main);
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", true);
}
function main(){
var d = new Date();
d.setDate(d.getDate()-130);
orden.count = 0;
cd.push("Id");
cd.push("ASC");
var n = new Array();
n.push("Name");
n.push("DESC");
orden.push(cd);
orden.push(n);
sforceClient.QueryAllSorted("select Id from Account" , orden);
}
function displayResults(opps) {
var sum_amount = 0;
var textlength = "Total records= "
var totallength = opps.length;
var out ="";
out += "<table border='1'><tbody>";
out += "<br>" + "<BR><B> " + (textlength) + (totallength) + "<BR>"
document.getElementById("maindiv").innerHTML = out;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var newFileObject = fso.CreateTextFile("C:\\totalaccounts.xml",true);
newFileObject.WriteLine ("<graph caption='Salesforce.com data' xAxisName='Month' showgridbg='0'canvasBgColor='99CC99' baseFontColor='333333' canvasbgcolor='99CC99' hovercapborder='889E6D'hovercapborder='CECE00' hovercapbg='FFFFDD' divlinecolor='F47E00' lineThickness='3' yaxisminvalue='0' limitsDecimalPrecision='0' divLineDecimalPrecision='0' numdivlines='4'>");
newFileObject.WriteLine ("<category name='Mar 06' hoverText='March'/>");
newFileObject.WriteLine ("<category name='Apr 06' hoverText='April'/>");
newFileObject.WriteLine ("<category name='May 06' hoverText='May'/>");
newFileObject.WriteLine ("<category name='Jun 06' hoverText='June'/>");
newFileObject.WriteLine ("</categories>");
newFileObject.WriteLine ("<dataset seriesname='Opportunities' color='222222' showValue='0'>");
newFileObject.WriteLine ("<set value='1845' />");
newFileObject.WriteLine ("<set value='1854' />");
newFileObject.WriteLine ("<set value='1098' />");
newFileObject.WriteLine ("<set value='" + totallength + "'/>");
newFileObject.WriteLine ("</dataset></graph>");
newFileObject.WriteLine ("");
newFileObject.Close();
function sortSObject(a, b){
for (var i=0; i<sforceClient.sortArray.length; i++){
var va = a.get(sforceClient.sortArray[i][0]);
var vb = b.get(sforceClient.sortArray[i][0]);
var s = 1;
if (sforceClient.sortArray[i][1] == "DESC"){
s = -1;
}
if (va > vb){
return 1 * s;
} else {
if (va < vb){
return -1 *s;
}
}
}
return 0;
}
sforceClient.QueryAllSorted = function(soql, sort_orders) {
sforceClient.sortArray = sort_orders;
sforceClient.sobjects = new Array();
this.Query(soql, queryCallback);
}
sforceClient.sortArray = new Array();
queryCallback = function(ret) {
if (ret.size > 0){
sforceClient.sobjects = sforceClient.sobjects.concat(ret.records);
if (ret.done == false){
sforceClient.queryMore(ret.queryLocator, queryCallback)
} else {
displayResults(sforceClient.sobjects.sort(sortSObject));
}
}
}
</script>
<body onLoad="load();">
<div id="maindiv"></div>
</body>
</html>