Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. <apex:page showHeader="false" sidebar="false" standardController="Inspection_Step__c">
  2. <!-- Remote Objects definition to set accessible sObjects and fields -->
  3. <apex:remoteObjects >
  4. <apex:remoteObjectModel name="Inspection_Step__c" jsShorthand="step"
  5. fields="Name,Id,Inspection__c,Step_Number__c,Rating__c">
  6. </apex:remoteObjectModel>
  7. </apex:remoteObjects>
  8.  
  9.  
  10. <script type="text/javascript">
  11.  
  12. //create a js variable for the remoteObjects
  13. var step = new SObjectModel.step();
  14.  
  15. // find steps for the matching inspection, where there is no status
  16. step.retrieve({
  17. where: {
  18. //same parent as the context object
  19. Inspection__c: {eq: '{!Inspection_Step__c.Inspection__c}'},
  20. //hasn't been rated yet
  21. Rating__c: {eq: ''},
  22. },
  23. //in ascending order
  24. orderby: [{Step_Number__c: 'ASC'}],
  25. }, function(err, records, event){
  26. if(err) {
  27. alert(err.message);
  28. }
  29. else {
  30. //no records left, navigate back to inspection
  31. if (records.length===0){
  32. alert('all steps are complete!');
  33. navigate('{!Inspection_Step__c.Inspection__c}');
  34. } else if (records[records.length-1].get('Step_Number__c') < {!Inspection_Step__c.Step_Number__c} ) {
  35. //the higest step is lower number than context step; go back to the lowest step
  36. navigate(records[0].get("Id"));
  37. } else {
  38. //loop through records
  39. for (var i=0; i<records.length; i++) {
  40. if (records[i].get('Step_Number__c') > {!Inspection_Step__c.Step_Number__c} ){
  41. console.log('navigate to next: ' + records[i].get('Step_Number__c'));
  42.  
  43. navigate(records[i].get("Id"));
  44. break;
  45. }
  46. };
  47. }
  48. }
  49. });
  50.  
  51. //universal navigation that works in SF1 or in web desktop UI
  52. function navigate (recordId){
  53.  
  54. if (typeof sforce !== 'undefined'){
  55. sforce.one.navigateToSObject(recordId);
  56. } else {
  57. //.top to deal with the fact that publisher actions in chatter feed are iframe
  58. window.top.location.href= "/" + recordId;
  59. }
  60.  
  61. }
  62.  
  63. </script>
  64.  
  65. </apex:page>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement