You need to sign in to do that
Don't have an account?
Anthony Piaia
I need a trigger that will create check list records automatically depending on the picklist value of an opportunity when the opportunity is created?
I have created an object named Application_Check_List__c which should create a record automatically based on the value i have in an opportunity picklist (Program_of_Study__c). Within the Application Check list object i created a Master detail relationship with Opportunity.
What i am looking to do is when an opportunity is created we have a picklist which has the program of study and based on the program of study their are a list of items that should be created under the Application checklist object.
Example:
If Program of study MSHRM
Insert checklist item 1
insert checklist item 2
insert checklist item 3
If program of study BBA online
Insert checklist item 1
insert checklist item 2 etc.
Please help as i am new to Apex Triggers
What i am looking to do is when an opportunity is created we have a picklist which has the program of study and based on the program of study their are a list of items that should be created under the Application checklist object.
Example:
If Program of study MSHRM
Insert checklist item 1
insert checklist item 2
insert checklist item 3
If program of study BBA online
Insert checklist item 1
insert checklist item 2 etc.
Please help as i am new to Apex Triggers
You need to create check list object record when a opportunity is create so you need to follow below step.
1) Create a new Trigger on opportunity.
Please follow best Practices
https://developer.salesforce.com/page/Trigger_Frameworks_and_Apex_Trigger_Best_Practices
Example:
if MSHRM then all the lists will be created with the subject values below:
Application Fee
Holds
Funding Plan
FL Residency Proof 1
FL Residency Proof 2
Official UGRD Transcripts
Official GRAD Transcripts
Official Transcripts Translation
Proof of Degree
GRE/GMAT Scores
TOEFL / IELTS Scores
Resume
Statement of Purpose
Letter of Recommendation 1
Letter of Recommendation 2
Admission Interview
Critical Thinking Assessment
So when i look in the opportunity under the Application checklist i should see 17 items with a subject value of each above.
trigger CreateChecklistbyProgramofStudy on Opportunity (after insert) {
OpportunityHandler.AfterCreation(Trigger.new);
}
public class OpportunityHandler{
static void AfterCreation(List<Opportunity> newOppList)
{
List<Application_Check_List__c > newApplicaitonList = new List<Application_Check_List__c>();
for(Opportunity o : newOppList)
{
if(o.Program_of_Study__c == 'MSHRM')
{
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Application Fee';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Holds';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Funding Plan';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'FL Residency Proof 1';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'FL Residency Proof 2';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Official UGRD Transcripts';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Official GRAD Transcripts';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Official Transcripts Translation';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Proof of Degree';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'GRE/GMAT Scores';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'TOEFL / IELTS Scores';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Resume';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Statement of Purpose';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Letter of Recommendation 1';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Letter of Recommendation 2';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Admission Interview';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Critical Thinking Assessment';));
}
if(o.Program_of_Study__c == 'MSIRE')
{
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Application Fee';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Holds';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Funding Plan';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'FL Residency Proof 1';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'FL Residency Proof 2';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Official UGRD Transcripts';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Official GRAD Transcripts';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Official Transcripts Translation';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Proof of Degree';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'GRE/GMAT Scores';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'TOEFL / IELTS Scores';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Resume';));
newApplicaitonList.add(new Application_Check_List__c(Subject__c = 'Statement of Purpose';));
}
}
if(newApplicaitonList.size()>0)
insert newApplicaitonList;
}
}