You need to sign in to do that
Don't have an account?
Gwirizanani Sinoia
Help in adding trigger update
Hi everyone. I am a newbie..
My working trigger is as follows. As you can see record insertion works perfectly well. However i am trying to add update functionality to it.
Please help?. A few lines of test class will be good too.
Thanks so much in advance
My trigger handler
public class PreAppLifeUpdateInsert {
public static void myPreAppTable(List <Pre_Application__c> preApplication){
List <PA_Pre_App_Life_Assured__c> preAppCreateList = new List <PA_Pre_App_Life_Assured__c>();
for(Pre_Application__c preAppLoop : preApplication){
PA_Pre_App_Life_Assured__c insertRecords;
insertRecords = new PA_Pre_App_Life_Assured__c(Pre_Application__c = preAppLoop.Id);
// Begining of Life Prelife Table
if(preAppLoop.Age_at_next_birthday__c>=17 && preAppLoop.Age_at_next_birthday__c<=35 && preAppLoop.PA_Life_Sum_Assured__c>= 0 && preAppLoop.PA_Life_Sum_Assured__c<=750000 ||
preAppLoop.Age_at_next_birthday__c>=36 && preAppLoop.Age_at_next_birthday__c<=40 && preAppLoop.PA_Life_Sum_Assured__c>= 0 && preAppLoop.PA_Life_Sum_Assured__c<=600000
{ insertRecords.Life_Assured__c = 'NO NML EVIDENCE NEEDED'; }
//begining of Life NSE_c update
if(preAppLoop.Age_at_next_birthday__c>=17 && preAppLoop.Age_at_next_birthday__c<=35 && preAppLoop.PA_Life_Sum_Assured__c>= 750001 && preAppLoop.PA_Life_Sum_Assured__c<=1000000 ||
preAppLoop.Age_at_next_birthday__c>=36 && preAppLoop.Age_at_next_birthday__c<=40 && preAppLoop.PA_Life_Sum_Assured__c>= 600001 && preAppLoop.PA_Life_Sum_Assured__c<=1000000
{ insertRecords.Life_Assured__c = 'NSE*'; } //end of Life (NSE_c update)
//begining of Life NSE_c NML_GPR__c update
if (preAppLoop.Age_at_next_birthday__c>=17 && preAppLoop.Age_at_next_birthday__c<=35 && preAppLoop.PA_Life_Sum_Assured__c>= 1000001 && preAppLoop.PA_Life_Sum_Assured__c<=1500000 ||
preAppLoop.Age_at_next_birthday__c>=36 && preAppLoop.Age_at_next_birthday__c<=40 && preAppLoop.PA_Life_Sum_Assured__c>= 1000001 && preAppLoop.PA_Life_Sum_Assured__c<=1500000
{ insertRecords.Life_Assured__c = 'NSE* NML GPR';} // end of Life NSE_c NML_GPR__c update
//begining of Life NSE* NML GPR HIV~ update
if (preAppLoop.Age_at_next_birthday__c>=17 && preAppLoop.Age_at_next_birthday__c<=35 && preAppLoop.PA_Life_Sum_Assured__c>= 1500001 && preAppLoop.PA_Life_Sum_Assured__c<=2000000 ||
preAppLoop.Age_at_next_birthday__c>=36 && preAppLoop.Age_at_next_birthday__c<=40 && preAppLoop.PA_Life_Sum_Assured__c>= 1500001 && preAppLoop.PA_Life_Sum_Assured__c<=2000000 )
{insertRecords.Life_Assured__c = 'NSE* NML GPR HIV~';}//End of Life NSE* NML GPR HIV~ update
//begining of Life NML GPR HIV~ FQ MER* FBP
if (preAppLoop.Age_at_next_birthday__c>=17 && preAppLoop.Age_at_next_birthday__c<=35 && preAppLoop.PA_Life_Sum_Assured__c>= 2000001 && preAppLoop.PA_Life_Sum_Assured__c<=3500000 ||
preAppLoop.Age_at_next_birthday__c>=36 && preAppLoop.Age_at_next_birthday__c<=40 && preAppLoop.PA_Life_Sum_Assured__c>= 2000001 && preAppLoop.PA_Life_Sum_Assured__c<=3500000 )
{insertRecords.Life_Assured__c = 'NML GPR HIV~ FQ MER* FBP';}//end of NML GPR HIV~ FQ MER* FBP update
//begining of Life NML GPR HIV~ FQ MER* FBP FC update
if(preAppLoop.Age_at_next_birthday__c>=17 && preAppLoop.Age_at_next_birthday__c<=35 && preAppLoop.PA_Life_Sum_Assured__c>= 3500001 && preAppLoop.PA_Life_Sum_Assured__c<=7500000 ||
preAppLoop.Age_at_next_birthday__c>=36 && preAppLoop.Age_at_next_birthday__c<=40 && preAppLoop.PA_Life_Sum_Assured__c>= 3500001 && preAppLoop.PA_Life_Sum_Assured__c<=7500000 ||
preAppLoop.Age_at_next_birthday__c>=46 && preAppLoop.Age_at_next_birthday__c<=50 && preAppLoop.PA_Life_Sum_Assured__c>= 3500001 && preAppLoop.PA_Life_Sum_Assured__c<=4000000 )
{insertRecords.Life_Assured__c = 'NML GPR HIV~ FQ MER* FBP FC';} //end of NML GPR HIV~ FQ MER* FBP FC update
preAppCreateList.add(insertRecords);} //End of for loop
insert preAppCreateList;
}// end of Method
}// end of class
My trigger class
trigger PreAppTrigger on Pre_Application__c ( after insert, after update) {
PreAppLifeUpdateInsert.myPreAppTable(trigger.new);
}
My working trigger is as follows. As you can see record insertion works perfectly well. However i am trying to add update functionality to it.
Please help?. A few lines of test class will be good too.
Thanks so much in advance
My trigger handler
public class PreAppLifeUpdateInsert {
public static void myPreAppTable(List <Pre_Application__c> preApplication){
List <PA_Pre_App_Life_Assured__c> preAppCreateList = new List <PA_Pre_App_Life_Assured__c>();
for(Pre_Application__c preAppLoop : preApplication){
PA_Pre_App_Life_Assured__c insertRecords;
insertRecords = new PA_Pre_App_Life_Assured__c(Pre_Application__c = preAppLoop.Id);
// Begining of Life Prelife Table
if(preAppLoop.Age_at_next_birthday__c>=17 && preAppLoop.Age_at_next_birthday__c<=35 && preAppLoop.PA_Life_Sum_Assured__c>= 0 && preAppLoop.PA_Life_Sum_Assured__c<=750000 ||
preAppLoop.Age_at_next_birthday__c>=36 && preAppLoop.Age_at_next_birthday__c<=40 && preAppLoop.PA_Life_Sum_Assured__c>= 0 && preAppLoop.PA_Life_Sum_Assured__c<=600000
{ insertRecords.Life_Assured__c = 'NO NML EVIDENCE NEEDED'; }
//begining of Life NSE_c update
if(preAppLoop.Age_at_next_birthday__c>=17 && preAppLoop.Age_at_next_birthday__c<=35 && preAppLoop.PA_Life_Sum_Assured__c>= 750001 && preAppLoop.PA_Life_Sum_Assured__c<=1000000 ||
preAppLoop.Age_at_next_birthday__c>=36 && preAppLoop.Age_at_next_birthday__c<=40 && preAppLoop.PA_Life_Sum_Assured__c>= 600001 && preAppLoop.PA_Life_Sum_Assured__c<=1000000
{ insertRecords.Life_Assured__c = 'NSE*'; } //end of Life (NSE_c update)
//begining of Life NSE_c NML_GPR__c update
if (preAppLoop.Age_at_next_birthday__c>=17 && preAppLoop.Age_at_next_birthday__c<=35 && preAppLoop.PA_Life_Sum_Assured__c>= 1000001 && preAppLoop.PA_Life_Sum_Assured__c<=1500000 ||
preAppLoop.Age_at_next_birthday__c>=36 && preAppLoop.Age_at_next_birthday__c<=40 && preAppLoop.PA_Life_Sum_Assured__c>= 1000001 && preAppLoop.PA_Life_Sum_Assured__c<=1500000
{ insertRecords.Life_Assured__c = 'NSE* NML GPR';} // end of Life NSE_c NML_GPR__c update
//begining of Life NSE* NML GPR HIV~ update
if (preAppLoop.Age_at_next_birthday__c>=17 && preAppLoop.Age_at_next_birthday__c<=35 && preAppLoop.PA_Life_Sum_Assured__c>= 1500001 && preAppLoop.PA_Life_Sum_Assured__c<=2000000 ||
preAppLoop.Age_at_next_birthday__c>=36 && preAppLoop.Age_at_next_birthday__c<=40 && preAppLoop.PA_Life_Sum_Assured__c>= 1500001 && preAppLoop.PA_Life_Sum_Assured__c<=2000000 )
{insertRecords.Life_Assured__c = 'NSE* NML GPR HIV~';}//End of Life NSE* NML GPR HIV~ update
//begining of Life NML GPR HIV~ FQ MER* FBP
if (preAppLoop.Age_at_next_birthday__c>=17 && preAppLoop.Age_at_next_birthday__c<=35 && preAppLoop.PA_Life_Sum_Assured__c>= 2000001 && preAppLoop.PA_Life_Sum_Assured__c<=3500000 ||
preAppLoop.Age_at_next_birthday__c>=36 && preAppLoop.Age_at_next_birthday__c<=40 && preAppLoop.PA_Life_Sum_Assured__c>= 2000001 && preAppLoop.PA_Life_Sum_Assured__c<=3500000 )
{insertRecords.Life_Assured__c = 'NML GPR HIV~ FQ MER* FBP';}//end of NML GPR HIV~ FQ MER* FBP update
//begining of Life NML GPR HIV~ FQ MER* FBP FC update
if(preAppLoop.Age_at_next_birthday__c>=17 && preAppLoop.Age_at_next_birthday__c<=35 && preAppLoop.PA_Life_Sum_Assured__c>= 3500001 && preAppLoop.PA_Life_Sum_Assured__c<=7500000 ||
preAppLoop.Age_at_next_birthday__c>=36 && preAppLoop.Age_at_next_birthday__c<=40 && preAppLoop.PA_Life_Sum_Assured__c>= 3500001 && preAppLoop.PA_Life_Sum_Assured__c<=7500000 ||
preAppLoop.Age_at_next_birthday__c>=46 && preAppLoop.Age_at_next_birthday__c<=50 && preAppLoop.PA_Life_Sum_Assured__c>= 3500001 && preAppLoop.PA_Life_Sum_Assured__c<=4000000 )
{insertRecords.Life_Assured__c = 'NML GPR HIV~ FQ MER* FBP FC';} //end of NML GPR HIV~ FQ MER* FBP FC update
preAppCreateList.add(insertRecords);} //End of for loop
insert preAppCreateList;
}// end of Method
}// end of class
My trigger class
trigger PreAppTrigger on Pre_Application__c ( after insert, after update) {
PreAppLifeUpdateInsert.myPreAppTable(trigger.new);
}
All Answers
According to me it is already working in both update and insert event scenarios with same functionality.
Thanks
thanks
If You Can see in your trigger there are no condition for insert or update.
If you can explain what you need to in update then i will suggest you a solution.
What I am trying to do is insert a child record (PA_Pre_App_Life_Assured__c) when a parent records (Pre_Application__c) is created based on conditions . Also update PA_Pre_App_Life_Assured__c when Pre_Application__c is updated. At the moment its inserting but not updating. As a new devoloper i think i might be over complicating things . Your help is most appreciated. thanks again
is it possible to start me up with a test class?
thanks once again