You need to sign in to do that
Don't have an account?
sandeepathadu
hi problem with too many scrip statements
hi all
plz rewrite my code to avoid too many script statements error
public class Dev_From_To_Ctrl { public Dev_From_To_Ctrl(ApexPages.StandardController controller) { userInputAppointment = new Appointment__c(); } public Appointment__c userInputAppointment {get; set;} public list<appointment__c> apps {get;set;} public list<appointment__c> apps1 {get;set;} public list<appointment__c> apps2 {get;set;} public list<appointment__c> apps3 {get;set;} public list<appointment__c> apps4 {get;set;} public list<appointment__c> apps5 {get;set;} public list<appointment__c> getall {get;set;} /*code starts from here first scenario----from hour less than to hour ex:8<9 8<15 sub scenarios in first scenario ex: from 8:10 to 12:50 scenario 1)8:10 to 8:50 scenario 2)9:00 to 9:50 & 10:00 to 10:50 &11:00 to 11:50 scenario 3)12:00 to 12:50*/ public PageReference save() { apps = new list<appointment__c>(); apps1 = new list<appointment__c>(); apps2 = new list<appointment__c>(); apps3 = new list<appointment__c>(); apps4 = new list<appointment__c>(); apps5 = new list<appointment__c>(); string j=userInputAppointment.Appt_24_From_Min__c; string v =userInputAppointment.Appt_24_To_Min__c; integer i=integer.valueof(userInputAppointment.Appt_24_From_Hour__c); integer i1=integer.valueof(userInputAppointment.Appt_24_To_Hour__c); integer i2=integer.valueof(userInputAppointment.Appt_24_From_Min__c); integer i3=integer.valueof(userInputAppointment.Appt_24_To_Min__c); if(i<i1) { //scenerio 1 i.e 8:10 to 8:50 stars here for(integer k=0;k<(60-i2)/10;k++) { //first take the given values by user appointment__c ap = new appointment__c(); ap.Appt_24_From_Hour__c=String.valueOf(i); ap.Appt_24_To_Hour__c=String.valueOf(i1); ap.Appt_24_From_Min__c=String.valueOf(j); ap.Appt_24_To_Min__c=String.valueOf(v); ap.Dev_Appt_Type_Normal_Or_From_To__c =true; ap.branch__c = userInputAppointment.branch__c; ap.account__c = userInputAppointment.Account__c; ap.doctor__c=userInputAppointment.doctor__c; ap.appt_date__c = userInputAppointment.appt_date__c; ap.Appt_AM_PM__c= 'AM'; if(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)>=12) { ap.Appt_AM_PM__c= 'PM'; } ap.Appt_Hour__c =String.valueOf(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)); if(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)>12) { ap.Appt_Hour__c =String.valueOf(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)-12); } ap.Appt_Minute__c = userInputAppointment.Appt_24_From_Min__c; ap.RecordTypeid=userInputAppointment.RecordTypeid; if(i2!=integer.valueof(userInputAppointment.Appt_24_From_Min__c)) { //LIVE ID // app1.RecordTypeid='01290000000ZXNL'; //SB ID ap.RecordTypeid='012N0000000CgZ2'; } apps1.add(ap); } insert apps1[0]; // here the first record in the list userInputAppointment.Appt_24_From_Min__c=String.valueOf(i2); for(integer k=0;k<(50-i2)/10;k++) { appointment__c ap8 = new appointment__c(); ap8.Appt_24_From_Hour__c=String.valueOf(i); ap8.Appt_24_To_Hour__c=String.valueOf(i1); ap8.Appt_24_From_Min__c=String.valueOf(j); ap8.Appt_24_To_Min__c=String.valueOf(v); ap8.Dev_Appt_Type_Normal_Or_From_To__c =true; ap8.branch__c = userInputAppointment.branch__c; ap8.account__c = userInputAppointment.Account__c; ap8.doctor__c=userInputAppointment.doctor__c; ap8.appt_date__c = userInputAppointment.appt_date__c; ap8.Appt_AM_PM__c= 'AM'; if(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)>=12) { ap8.Appt_AM_PM__c= 'PM'; } ap8.Appt_Hour__c =String.valueOf(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)); if(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)>12) { ap8.Appt_Hour__c =String.valueOf(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)-12); } ap8.Appt_Minute__c = String.valueOf( integer.valueof(userInputAppointment.Appt_24_From_Min__c)+10); //LIVE ID // app1.RecordTypeid='01290000000ZXNL'; //SB ID ap8.RecordTypeid='012N0000000CgZ2'; ap8.Dev_Parent_Appt__c=apps1[0].id; apps4.add(ap8); userInputAppointment.Appt_24_From_Min__c=String.valueOf(integer.valueof(userInputAppointment.Appt_24_From_Min__c)+10); } insert apps4; //scenerio 1 i.e 8:10 to 8:50 ends here //scenario 2 starts here i.e 9:00 to 9:50 & 10 to 10:50 &11:00 to 11:50 for( integer l=1;l<i1-i;l++) { userInputAppointment.Appt_24_From_Hour__c=String.valueOf(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)+1); string x='00'; if(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)<integer.valueof(userInputAppointment.Appt_24_To_Hour__c)) { for(integer g=0;g<6;g++) { appointment__c ap1=new appointment__c(); ap1.Appt_24_From_Hour__c=String.valueOf(i); ap1.Appt_24_To_Hour__c=String.valueOf(i1); ap1.Appt_24_From_Min__c=String.valueOf(j); ap1.Appt_24_To_Min__c=String.valueOf(v); ap1.Dev_Appt_Type_Normal_Or_From_To__c =true; ap1.Appt_24_From_Hour__c=userInputAppointment.Appt_24_From_Hour__c; ap1.Appt_24_To_Hour__c=userInputAppointment.Appt_24_To_Hour__c; ap1.Appt_24_From_Min__c=userInputAppointment.Appt_24_From_Min__c; ap1.Appt_24_To_Min__c=userInputAppointment.Appt_24_To_Min__c; ap1.branch__c = userInputAppointment.branch__c; ap1.account__c = userInputAppointment.Account__c; ap1.appt_date__c = userInputAppointment.appt_date__c; ap1.doctor__c=userInputAppointment.doctor__c; ap1.Appt_AM_PM__c= 'AM'; //LIVE ID // app1.RecordTypeid='01290000000ZXNL'; //SB ID ap1.RecordTypeid='012N0000000CgZ2'; if(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)>=12) { ap1.Appt_AM_PM__c= 'PM'; } ap1.Appt_Hour__c =String.valueOf(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)); if(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)>12) { ap1.Appt_Hour__c =String.valueOf(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)-12); } ap1.Appt_Minute__c=x; ap1.Dev_Parent_Appt__c=apps1[0].id; apps2.add(ap1); x=String.valueOf(integer.valueof(x)+10); } } } insert apps2; //scenario 2 ends here i.e 9:00 to 9:50 & 10 to 10:50 &11:00 to 11:50 //scenario 3 i.e 12:00 to 12:50 stars here string q='00'; userInputAppointment.Appt_24_From_Hour__c=String.valueOf(i+(i1-i)); if(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)==integer.valueof(userInputAppointment.Appt_24_To_Hour__c)) { for(integer b=0;b<((i3/10));b++) { appointment__c ap3=new appointment__c(); ap3.Appt_24_From_Hour__c=String.valueOf(i); ap3.Appt_24_To_Hour__c=String.valueOf(i1); ap3.Appt_24_From_Min__c=String.valueOf(j); ap3.Appt_24_To_Min__c=String.valueOf(v); ap3.Dev_Appt_Type_Normal_Or_From_To__c =true; ap3.account__c = userInputAppointment.Account__c; ap3.branch__c = userInputAppointment.branch__c; ap3.doctor__c=userInputAppointment.doctor__c; //LIVE ID // app1.RecordTypeid='01290000000ZXNL'; //SB ID ap3.RecordTypeid='012N0000000CgZ2'; ap3.appt_date__c = userInputAppointment.appt_date__c; ap3.Appt_Hour__c =String.valueOf(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)); if(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)>12) { ap3.Appt_Hour__c =String.valueOf(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)-12); } ap3.Appt_AM_PM__c= 'AM'; if(integer.valueof(userInputAppointment.Appt_24_From_Hour__c)>=12) { ap3.Appt_AM_PM__c= 'PM'; } ap3.Dev_Parent_Appt__c=apps1[0].id; ap3.Appt_Minute__c=q; ap3.Dev_Parent_Appt__c=apps1[0].id; apps3.add(ap3); q=String.valueOf(integer.valueof(q)+10); } } } insert apps3; //scenario 3 i.e 12:00 to 12:50 ends here
Like replace this code (written in for loop) :
With this :
Thanks
Ankit Arora
Blog | Facebook | Blog Page
All Answers
Duplicate post:
Your post
sir thanks for the reply . can u rewrite a small part of my code so that i can re write it entirely
In the first shot I can find some problems and you can replace them using these cookbook recipes :
http://developer.force.com/cookbook/recipe/using-sobject-constructors-to-save-script-statements
http://developer.force.com/cookbook/recipe/initialising-maps-from-queries
Also avoid using for loop in for loop. Once you are done with these steps post your updated code here if the error persists. Will try to resolve it.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Like replace this code (written in for loop) :
With this :
Thanks
Ankit Arora
Blog | Facebook | Blog Page
thanks will try and let u know
thanks it helped reduce my script statements