function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ElenaCaptaElenaCapta 

How I can optimize the code?

Code:
while (stopLooping == false) { 

for (var i=0;i<_qrCases.records.length;i++) { 
var row; 
docContents += "<tr class=\"letraGris\">"; 



case = _qrCases.records[i];
var contactname=case.get("ContactId");
var idcase = case.get("Id");

docContents += "<td align='left'><a href = '/"+idcase+"' target=_parent> "+ case.get("Type")+"</a></td>";

docContents += "<td bgcolor=\"#F3F3EC\" width=1 nowrap><img src=\"https://na1.salesforce.com/s.gif\"></td>";

docContents += "<td align='left'><a href = '/"+idcase+"' target=_parent> "+ case.get("CaseNumber")+"</a></td>";

docContents += "<td bgcolor=\"#F3F3EC\" width=1 nowrap><img src=\"https://na1.salesforce.com/s.gif\"></td>";

//The next it's slow

if(contactname !=''){
var contactquery = sforceClient.Query("Select FirstName, LastName from Contact where Id='"+contactname+"'");
docContents += "<td align='left'><a href = '/"+contactname+"' target=_parent>"+contactquery.records[0].get("FirstName")+" "+contactquery.records[0].get("LastName")+"</a></td>";
docContents += "<td bgcolor=\"#F3F3EC\" width=1 nowrap><img src=\"https://na1.salesforce.com/s.gif\"></td>";}
else{
docContents += "<td align='left'></td>";
docContents += "<td bgcolor=\"#F3F3EC\" width=1 nowrap><img src=\"https://na1.salesforce.com/s.gif\"></td>";}

//***************

docContents += "<td align='left'><a href = '/"+idcase+"' target=_parent> "+case.get("Status")+"</a></td>";

docContents += "<td bgcolor=\"#F3F3EC\" width=1 nowrap><img src=\"https://na1.salesforce.com/s.gif\"></td>";

docContents += "<td align='left'><a href = '/"+idcase+"' target=_parent> "+case.get("LastModifiedById")+"</a></td>";

docContents += "<td bgcolor=\"#F3F3EC\" width=1 nowrap><img src=\"https://na1.salesforce.com/s.gif\"></td>";

docContents += "</tr>"; 
docContents += "<tr height='5'><td>&nbsp;</td></tr>";
_cases[case.get("Id")] = case; 
} //for

if (_qrCases.done == true) { 
stopLooping = true; 
} else { 
_qrCases = sforceClient.QueryMore(_qrCases.queryLocator); 
}
 
hello!
 
I have a problem because the previous code it's more slow, Somebody Knows how I can optimize the code?
 
Thanks!!
 
 
David GorslineDavid Gorsline
Two suggestions: (1) Use .retrieve() instead of .query() (2) As for the spacer gifs that you're pulling in with "https://na1.salesforce.com/s.gif", you'd be better off to copy the .gif to your own server, and serve it with plain HTTP. Better yet, just use a non-breaking space ( ). -- David L. Gorsline, MCAD Senior Software Developer WebSurveyor Corporation Herndon, Virginia
SuperfellSuperfell
batch up the contact ids and make a single retrieve call, rather than calling query (or retrieve) for each row.