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
zeezackisbackzeezackisback 

Finding Custom Objects Id in s-controls

How do I recover the Id for a custom objcet?

 

This was for the case

 

 

var caseId = '{!Case.Id}';

 

this was for my custom object claim..

 

 

var caseId = '{!Claim__c.Id}';

 

 but its not working.

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
zeezackisbackzeezackisback

well for anyone out there wanting to know... you can't use an s-control timer with a visualforce detail page.

The detail page sees the s-control as an iframe and thus variables are not pulled down from it.

 

Visualforce timer is needed

All Answers

zeezackisbackzeezackisback

I need an answer soon.. its not even recovering other variables?

 

 

var timerStart = '{!TEXT( Claim__c.FM_Timer_Timer_Start__c )}'; var timerRunning = '{!Claim__c.FM_Timer_Timer_Running__c}'; var timerSeconds = parseInt('{!TEXT(Claim__c.FM_Timer_Timer_Current_Seconds__c)}'); var timerPrevSeconds = parseInt('{!TEXT(Claim__c.FM_Timer_Timer_Previous_Seconds__c)}');

 

 complete code

 

 

<html> <head> <link href="/dCSS/Theme2/default/common.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" > <link href="/dCSS/Theme2/default/custom.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" > <script src="/soap/ajax/10.0/connection.js"></script> <style type=text/css> table {font-size:12px} .fTitle {font-size:11px; width:150px} .fData {font-size:12px;} </style> <script> var tO = null; //var caseId ='{!Claim__c.Id}' ; var caseId = 'a07300000045eHI'; alert(caseId); var caseNumber = '{!SUBSTITUTE(SUBSTITUTE(Claim__c.Name,"<","&lt;"),">","&gt;")}'; var timerStart = '{!TEXT( Claim__c.FM_Timer_Timer_Start__c )}'; var timerRunning = '{!Claim__c.FM_Timer_Timer_Running__c}'; var timerSeconds = parseInt('{!TEXT(Claim__c.FM_Timer_Timer_Current_Seconds__c)}'); var timerPrevSeconds = parseInt('{!TEXT(Claim__c.FM_Timer_Timer_Previous_Seconds__c)}'); alert(timerStart ); alert(timerRunning ); alert(timerSeconds ); alert(timerPrevSeconds ); if (!(timerPrevSeconds)) { timerPrevSeconds = 0; } if (!(timerSeconds)) { timerSeconds = 0; } function UpdateTimer(s) { Timer.innerHTML = FormatDate(s); TimerTotal.innerHTML = FormatDate(s + timerPrevSeconds); } function RunTimer() { timerSeconds += 1; UpdateTimer(timerSeconds); tO = setTimeout("RunTimer();",1000); } function Zero(n) { if (n < 10) return "0" + n; else return n; } function FormatDate(d) { days = Math.floor(d / 86400); hours = Math.floor((d % 86400) / 3600); mins = Math.floor((d % 3600) / 60); secs = (d % 60); return days + "D " + Zero(hours) + ":" + Zero(mins) + ":" + Zero(secs); } function setupPage() { if (timerRunning == '1') { ToggleButton(true); RunTimer(); } else { UpdateTimer(0); } } function ToggleButton(b) { if (b) { document.getElementById('startButton').style.display = 'none'; document.getElementById('stopButton').style.display = 'inline'; } else { startButton.style.display = 'inline'; stopButton.style.display = 'none'; } } function SetTimer() { result = sforce.connection.query("Select Id,FM_Timer_Timer_Running__c from Claim__c where Id = '" + caseId + "'"); var records = result.getArray("records"); if (records.length != 1) { alert("An error occurred when starting the timer: cannot find case"); } else { if (records[0].getBoolean("FM_Timer_Timer_Running__c")) { alert('Timer already started'); } else { serverTime = sforce.connection.getServerTimestamp().timestamp; thisClaim__c = new sforce.SObject("Claim__c"); thisClaim__c.id = caseId; thisClaim__c.FM_Timer_Timer_Start__c = serverTime; thisClaim__c.FM_Timer_Timer_Running__c = 1; result = sforce.connection.update([thisClaim__c]); if (!(result[0].getBoolean("success"))) { alert('An error occurred when starting the timer: update failed'); } else { ToggleButton(true); RunTimer(); } } } } function StopTimer() { result = sforce.connection.query("Select Id,FM_Timer_Timer_Running__c,FM_Timer_Timer_Total_Seconds__c from Claim__c where Id = '" + caseId + "'"); var records = result.getArray("records"); if (records.length != 1) { alert("An error occurred when stopping the timer: cannot find case"); } else { if (records[0].getBoolean("FM_Timer_Timer_Running__c")) { t = records[0].getInt("FM_Timer_Timer_Total_Seconds__c"); thisClaim__c = new sforce.SObject("Claim__c"); thisClaim__c.id = caseId; thisClaim__c.FM_Timer_Timer_Start__c = null; thisClaim__c.FM_Timer_Timer_Running__c = false; thisClaim__c.FM_Timer_Timer_Previous_Seconds__c = t; result2 = sforce.connection.update([thisClaim__c]); if (!(result2[0].getBoolean("success"))) { alert('An error occurred when stopping the timer: update failed'); } else { clearTimeout(tO); timerPrevSeconds += timerSeconds; timerSeconds = 0; ToggleButton(false); } } else { alert('Timer already stopped'); } } } </script> </head> <body onload=setupPage() class="case" style="text-align:center; background-color:#f3f3ec"> <table border="0" cellpadding="0" cellspacing="0" style="text-align:center"> <tr> <td class="fTitle" >Current Time</td> <td class="fTitle">Total Time</td> </tr> <tr> <td class="fData"><div id=Timer>0D 00:00:00</div></td> <td class="fData"><div id=TimerTotal>0D 00:00:00</div></td> </tr> <tr> <td> <input type=button class=btn id=startButton value=Start onclick=SetTimer() style="font-size:10px;"> <input type=button class=btn id=stopButton value=Stop onclick=StopTimer() style="font-size:10px; display:none;"> </td> </tr> </tr> </table> </body> </html>

 

 

 

 

zeezackisbackzeezackisback

well for anyone out there wanting to know... you can't use an s-control timer with a visualforce detail page.

The detail page sees the s-control as an iframe and thus variables are not pulled down from it.

 

Visualforce timer is needed

This was selected as the best answer
DevAngelDevAngel
Well, that's interesting.  Anyway, since s-controls are depricated, a Visualforce custom component make more sense any way.