Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. // sync enrollments from SF to LMS. This emulates the click of the "Convert to LMS" button on Port Authority SF page
  2. // More than 3 records at a time may result in Too Many SOQL queries exception
  3. // This can be run in SF developer console
  4.  
  5. List<Section__c> allSections = [select id, Semester__c, name, course__r.name, course__r.course_code__c
  6. from Section__C
  7. where Semester__c like '%201903%'
  8. and name like '%PUBH%'
  9. and Non_LMS__c = False
  10. and ((NOT course__r.name like '%6271%') and (NOT course__r.name like '%6061%')
  11. and (NOT course__r.name like '%6416%') and (NOT course__r.name like '%6014%'))
  12. and Start__c > 2019-08-25T00:00:00z and id in (
  13. 'a2Y0V0000058cix',
  14. 'a2Y0V0000058cj7',
  15. 'a2Y0V0000058eJ6')
  16. ];
  17.  
  18. // case RecordType for the given org
  19. ID SFRecordTypeId = '012d0000001121HAAQ',
  20.  
  21.  
  22. System.debug('allSections :' + allSections.size() );
  23.  
  24. for (Section__c s: allSections){
  25. s.Non_LMS__c = True;
  26.  
  27. // MAIN
  28.  
  29. setSectionNonLmsFalse(s);
  30.  
  31. List<Case> enrollmentCases = generateEnrollmentCases(s.id);
  32. upsert enrollmentCases;
  33. System.debug('enrollmentCases:' + enrollmentCases);
  34.  
  35. List<Case> approvedEnrollmentCases = approveEnrollmentCases(enrollmentCases);
  36. upsert approvedEnrollmentCases;
  37. System.debug('approvedEnrollmentCases:' + approvedEnrollmentCases);
  38. }
  39.  
  40. //***********************************************************
  41.  
  42. public Case enrollmentCase(Enrollment__c enrollment) {
  43. return new Case(Subject='Enrollment Request',
  44. Description='Enrollment Request',
  45. RecordTypeId=SFRecordTypeId,
  46. Reason='Requested',
  47. Change_Object__c='Student Enrollment',
  48. Change_Type__c='new',
  49. Student__c=enrollment.Student__c,
  50. Section__c=enrollment.Section__c,
  51. Enrollment__c=enrollment.Id,
  52. Enrollment_Status__c='Enrolled',
  53. Reason_For_Request__c = 'Requested');
  54. }
  55.  
  56. private List<Case> generateEnrollmentCases(id section_id) {
  57. List<Case> enrollmentCases = new List<Case>();
  58. for(Enrollment__c enrollment: getEnrollments(section_id)) {
  59. enrollmentCases.add(enrollmentCase(enrollment));
  60. }
  61. return enrollmentCases;
  62. }
  63.  
  64. private List<Case> approveEnrollmentCases(List<Case> enrollmentCases) {
  65. for(Case enrollmentCase: enrollmentCases) {
  66. enrollmentCase.Approval__c = 'Approved';
  67. }
  68. return enrollmentCases;
  69. }
  70.  
  71. private List<Enrollment__c> getEnrollments(id section_id) {
  72. return [SELECT Id,
  73. Status__c,
  74. Student__c,
  75. Section__c
  76. FROM Enrollment__c
  77. WHERE Section__c = : section_id
  78. AND Student__c <> null
  79. AND Status__c = 'Enrolled'];
  80. }
  81.  
  82. private void setSectionNonLmsFalse(Section__c s) {
  83. s.Non_LMS__c = false;
  84. upsert s;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement