Last active
March 30, 2017 20:17
-
-
Save keithmancuso/24c5c2adf1db4fcdce6d4cae02e8ab59 to your computer and use it in GitHub Desktop.
Art Matters Nominate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public PageReference nominate() | |
{ | |
try { | |
// check to see if anyone else has already nominated someone with this email addres in this same year | |
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]; | |
// if so make a second instead of an application | |
Second__c Second = new Second__c(); | |
Second.Nominator__c = NominationRound.Id; | |
Second.Application__c = application.Id; | |
insert Second; | |
PageReference pageRef = pageRef = new PageReference('/nominate?id='+NominationRound.id+'&key='+NominationRound.name+'&second=true'); | |
pageRef.setRedirect(true); | |
return pageRef; | |
} catch (exception e) { | |
// if not already nominated | |
// check if contact wtih same email address exists | |
try { | |
applicant = [select Id from Contact where email = :newapplicant.Email__c limit 1]; | |
} catch (exception f) { | |
Applicant = new Contact(); | |
} | |
// update contact | |
Applicant.LastName = newapplicant.Last_Name__c; | |
Applicant.FirstName = newapplicant.First_Name__c; | |
Applicant.npe01__HomeEmail__c = newapplicant.Email__c; | |
Applicant.npe01__Preferred_Email__c = 'Personal'; | |
upsert Applicant; | |
// create new application and related contact with it | |
newapplicant.applicant__c = Applicant.id; | |
newapplicant.nomination_type__c = 'Nominee'; | |
if already nominated 2 or more make this one an alternate vs regular nominee | |
try { | |
List <Application__c> totalApplications = getApplications(); | |
if (totalApplications.size() >= 2){ | |
newapplicant.nomination_type__c = 'Alternate'; | |
NominationRound.Completed_Nominations__c = true; | |
} | |
} catch (exception f) { | |
} | |
insert newapplicant; | |
PageReference pageRef = pageRef = new PageReference('/nominate?id='+NominationRound.id+'&key='+NominationRound.name); | |
pageRef.setRedirect(true); | |
return pageRef; | |
} | |
} | |
// if they say they are done before submitting 3 nominees | |
public PageReference completedNomations() | |
{ | |
NominationRound.Completed_Nominations__c = true; | |
upsert NominationRound; | |
PageReference pageRef = pageRef = new PageReference('/nominate?id='+NominationRound.id+'&key='+NominationRound.name); | |
pageRef.setRedirect(true); | |
return pageRef; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment