Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. public PageReference nominate()
  2. {
  3.  
  4. try {
  5. // check to see if anyone else has already nominated someone with this email addres in this same year
  6. Application__c application = [select Id from Application__c where Nomination_Round__r.Grant_Round__c = :NominationRound.Grant_Round__c and email__c = :newapplicant.Email__c limit 1];
  7.  
  8. // if so make a second instead of an application
  9. Second__c Second = new Second__c();
  10.  
  11. Second.Nominator__c = NominationRound.Id;
  12. Second.Application__c = application.Id;
  13.  
  14. insert Second;
  15.  
  16. PageReference pageRef = pageRef = new PageReference('/nominate?id='+NominationRound.id+'&key='+NominationRound.name+'&second=true');
  17. pageRef.setRedirect(true);
  18. return pageRef;
  19.  
  20. } catch (exception e) {
  21. // if not already nominated
  22.  
  23. // check if contact wtih same email address exists
  24. try {
  25. applicant = [select Id from Contact where email = :newapplicant.Email__c limit 1];
  26. } catch (exception f) {
  27. Applicant = new Contact();
  28. }
  29.  
  30. // update contact
  31. Applicant.LastName = newapplicant.Last_Name__c;
  32. Applicant.FirstName = newapplicant.First_Name__c;
  33. Applicant.npe01__HomeEmail__c = newapplicant.Email__c;
  34. Applicant.npe01__Preferred_Email__c = 'Personal';
  35.  
  36. upsert Applicant;
  37.  
  38. // create new application and related contact with it
  39. newapplicant.applicant__c = Applicant.id;
  40.  
  41. newapplicant.nomination_type__c = 'Nominee';
  42.  
  43.  
  44. if already nominated 2 or more make this one an alternate vs regular nominee
  45. try {
  46. List <Application__c> totalApplications = getApplications();
  47.  
  48. if (totalApplications.size() >= 2){
  49. newapplicant.nomination_type__c = 'Alternate';
  50. NominationRound.Completed_Nominations__c = true;
  51. }
  52. } catch (exception f) {
  53.  
  54. }
  55.  
  56. insert newapplicant;
  57.  
  58. PageReference pageRef = pageRef = new PageReference('/nominate?id='+NominationRound.id+'&key='+NominationRound.name);
  59. pageRef.setRedirect(true);
  60. return pageRef;
  61.  
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. }
  69.  
  70.  
  71. // if they say they are done before submitting 3 nominees
  72. public PageReference completedNomations()
  73. {
  74.  
  75. NominationRound.Completed_Nominations__c = true;
  76. upsert NominationRound;
  77.  
  78.  
  79. PageReference pageRef = pageRef = new PageReference('/nominate?id='+NominationRound.id+'&key='+NominationRound.name);
  80. pageRef.setRedirect(true);
  81. return pageRef;
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement