-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
5Questions
-
16Replies
Help creating a testClass
Hi all - I am totally stumped. I have been trying to figure out how to create a test class for the following class and I just can't get it to do it's thing. Any help?
trigger AssociatedSessions on Group__c (after insert) { List<Session__c> session = new List<Session__c>(); for (Group__c newGroup: Trigger.New) { Date sd1 = newGroup.Start_Date__c; Date ed1 = newGroup.End_Date__c; if (newGroup.Frequency__c == 'weekly') { integer numberOfWeeks = sd1.daysBetween(ed1) / 7 ; for(integer i = 0; i < numberOfWeeks ; i++){ //If MOnday is included IF(newGroup.Days_of_the_Week__c.contains('Monday') ){ IF(newGroup.Begins_on_a__c <= 1) { Date firstMonday = newGroup.Start_Date__c.toStartOfWeek() + 1; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstMonday + i * 7) ); } IF(newGroup.Begins_on_a__c > 1) { Date firstMonday = newGroup.Start_Date__c.toStartOfWeek() + 8; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstMonday + i * 7) ); } } //If Tuesday is included IF(newGroup.Days_of_the_Week__c.contains('Tuesday') ){ IF(newGroup.Begins_on_a__c <= 2) { Date firstTuesday = newGroup.Start_Date__c.toStartOfWeek() + 2; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstTuesday + i * 7) ); } IF(newGroup.Begins_on_a__c > 2) { Date firstTuesday = newGroup.Start_Date__c.toStartOfWeek() + 9; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstTuesday + i * 7) ); } } //If Wednesday is included IF(newGroup.Days_of_the_Week__c.contains('Wednesday') ){ IF(newGroup.Begins_on_a__c <= 3) { Date firstWednesday = newGroup.Start_Date__c.toStartOfWeek() + 3; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstWednesday + i * 7) ); } IF(newGroup.Begins_on_a__c > 3) { Date firstWednesday = newGroup.Start_Date__c.toStartOfWeek() + 10; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstWednesday + i * 7) ); } } //if Thursday is included IF(newGroup.Days_of_the_Week__c.contains('Thursday') ){ IF(newGroup.Begins_on_a__c <= 4) { Date firstThursday = newGroup.Start_Date__c.toStartOfWeek() + 4; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstThursday + i * 7) ); } IF(newGroup.Begins_on_a__c > 4) { Date firstThursday = newGroup.Start_Date__c.toStartOfWeek() + 11; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstThursday + i * 7) ); } } //If Friday is included IF(newGroup.Days_of_the_Week__c.contains('Friday') ){ IF(newGroup.Begins_on_a__c <= 5) { Date firstFriday = newGroup.Start_Date__c.toStartOfWeek() + 5; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstFriday + i * 7) ); } IF(newGroup.Begins_on_a__c > 5) { Date firstFriday = newGroup.Start_Date__c.toStartOfWeek() + 12; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstFriday + i * 7) ); } } //If Saturday is included IF(newGroup.Days_of_the_Week__c.contains('Saturday') ){ IF(newGroup.Begins_on_a__c <= 6) { Date firstSaturday = newGroup.Start_Date__c.toStartOfWeek() + 6; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSaturday + i * 7) ); } IF(newGroup.Begins_on_a__c > 6) { Date firstSaturday = newGroup.Start_Date__c.toStartOfWeek() + 12; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSaturday + i * 7) ); } } //If Sunday is included IF(newGroup.Days_of_the_Week__c.contains('Sunday') ){ IF(newGroup.Begins_on_a__c <= 0) { Date firstSunday = newGroup.Start_Date__c.toStartOfWeek() + 5; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSunday + i * 7) ); } IF(newGroup.Begins_on_a__c > 0) { Date firstSunday = newGroup.Start_Date__c.toStartOfWeek() + 12; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSunday + i * 7) ); } } } } if (newGroup.Frequency__c == 'daily') { integer numberOfDays = sd1.daysBetween(ed1); for(integer i = 0; i < numberOfDays ; i++){ session.add (new Session__c( Term__c = newGroup.Id, Date__c = sd1 + i) ); } } if (newGroup.Frequency__c == 'biweekly') { integer numberOfWeeks = sd1.daysBetween(ed1) / 14 ; for(integer i = 0; i < numberOfWeeks ; i++){ //If MOnday is included IF(newGroup.Days_of_the_Week__c.contains('Monday') ){ IF(newGroup.Begins_on_a__c <= 1) { Date firstMonday = newGroup.Start_Date__c.toStartOfWeek() + 1; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstMonday + i * 14) ); } IF(newGroup.Begins_on_a__c > 1) { Date firstMonday = newGroup.Start_Date__c.toStartOfWeek() + 8; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstMonday + i * 14) ); } } //If Tuesday is included IF(newGroup.Days_of_the_Week__c.contains('Tuesday') ){ IF(newGroup.Begins_on_a__c <= 2) { Date firstTuesday = newGroup.Start_Date__c.toStartOfWeek() + 2; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstTuesday + i * 14) ); } IF(newGroup.Begins_on_a__c > 2) { Date firstTuesday = newGroup.Start_Date__c.toStartOfWeek() + 9; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstTuesday + i * 14) ); } } //If Wednesday is included IF(newGroup.Days_of_the_Week__c.contains('Wednesday') ){ IF(newGroup.Begins_on_a__c <= 3) { Date firstWednesday = newGroup.Start_Date__c.toStartOfWeek() + 3; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstWednesday + i * 14) ); } IF(newGroup.Begins_on_a__c > 3) { Date firstWednesday = newGroup.Start_Date__c.toStartOfWeek() + 10; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstWednesday + i * 14) ); } } //if Thursday is included IF(newGroup.Days_of_the_Week__c.contains('Thursday') ){ IF(newGroup.Begins_on_a__c <= 4) { Date firstThursday = newGroup.Start_Date__c.toStartOfWeek() + 4; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstThursday + i * 14) ); } IF(newGroup.Begins_on_a__c > 4) { Date firstThursday = newGroup.Start_Date__c.toStartOfWeek() + 11; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstThursday + i * 14) ); } } //If Friday is included IF(newGroup.Days_of_the_Week__c.contains('Friday') ){ IF(newGroup.Begins_on_a__c <= 5) { Date firstFriday = newGroup.Start_Date__c.toStartOfWeek() + 5; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstFriday + i * 14) ); } IF(newGroup.Begins_on_a__c > 5) { Date firstFriday = newGroup.Start_Date__c.toStartOfWeek() + 12; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstFriday + i * 14) ); } } //If Saturday is included IF(newGroup.Days_of_the_Week__c.contains('Saturday') ){ IF(newGroup.Begins_on_a__c <= 6) { Date firstSaturday = newGroup.Start_Date__c.toStartOfWeek() + 6; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSaturday + i * 14) ); } IF(newGroup.Begins_on_a__c > 6) { Date firstSaturday = newGroup.Start_Date__c.toStartOfWeek() + 12; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSaturday + i * 14) ); } } //If Sunday is included IF(newGroup.Days_of_the_Week__c.contains('Sunday') ){ IF(newGroup.Begins_on_a__c <= 0) { Date firstSunday = newGroup.Start_Date__c.toStartOfWeek() + 5; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSunday + i * 14) ); } IF(newGroup.Begins_on_a__c > 0) { Date firstSunday = newGroup.Start_Date__c.toStartOfWeek() + 12; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSunday + i * 14) ); } } } } if (newGroup.Frequency__c == 'monthly') { integer numberOfMonths = sd1.daysBetween(ed1) / 30; integer beginsOnA = newGroup.Begins_on_a__c.intValue(); for(integer i = 0; i < numberOfMonths ; i++){ date startDay = newGroup.Start_Date__c + i * 30; session.add (new Session__c( Term__c = newGroup.Id, Date__c = startDay.toStartOfWeek() + beginsOnA )); } } insert session; } }
- Greer Zimmerman 5
- September 18, 2017
- Like
- 0
method does not exist or incorrect signature - can't figure it out!
hi all - so i'm trying to get a series of child session records to be created when I create a parent record with a date range, a frequency, and certain days of the week when the sessions will take place. I can get my code to create a weekly session if it only occurs once a week, but I can't figure out how to get sessions for other days of the week to be created!
For instance if the group starts on a monday, and it also meets on Wednesday - and the group meets for 3 weeks, how can i get 6 sessions to be created with the correct days?
My code is below - right now I am JUST working on getting Mondays to work and plan on just copying and pasting for Tues - Sun. Any help? Am I going in the right direction at all ?
Right now I'm getting the errors:
- Line 15: Method does not exist or incorrect signature: void INCLUDES(String, String) from the type AssociatedSessions
- Line 16: Method does not exist or incorrect signature: void DATE(Integer, Integer, Integer) from the type AssociatedSessions
Total newbie - any help is appreciated
For instance if the group starts on a monday, and it also meets on Wednesday - and the group meets for 3 weeks, how can i get 6 sessions to be created with the correct days?
My code is below - right now I am JUST working on getting Mondays to work and plan on just copying and pasting for Tues - Sun. Any help? Am I going in the right direction at all ?
Right now I'm getting the errors:
- Line 15: Method does not exist or incorrect signature: void INCLUDES(String, String) from the type AssociatedSessions
- Line 16: Method does not exist or incorrect signature: void DATE(Integer, Integer, Integer) from the type AssociatedSessions
Total newbie - any help is appreciated
trigger AssociatedSessions on Group__c (after insert) { List<Session__c> session = new List<Session__c>(); for (Group__c newGroup: Trigger.New) { Date sd1 = newGroup.Start_Date__c; Date ed1 = newGroup.End_Date__c; if (newGroup.Frequency__c == 'weekly') { integer numberOfWeeks = sd1.daysBetween(ed1) / 7 ; for(integer i = 1; i < numberOfWeeks ; i++){ IF(INCLUDES(newGroup.Days_of_the_Week__c, 'Monday')) { Date firstMonday = (newGroup.Start_Date__c + ( 1 - MOD( newGroup.Start_Date__c - DATE( 1900, 1, 7 ), 7 ) )); session.add (new Session__c( Term__c = newGroup.Id, Date__c = sd1 + i * 7) ); } } if (newGroup.Frequency__c == 'daily') { integer numberOfDays = sd1.daysBetween(ed1); for(integer i = 1; i < numberOfDays ; i++){ session.add (new Session__c( Term__c = newGroup.Id, Date__c = sd1 + i * 7) ); } } if (newGroup.Frequency__c == 'biweekly') { integer numberOfDays = sd1.daysBetween(ed1) / 14; for(integer i = 1; i < numberOfDays ; i++){ session.add (new Session__c( Term__c = newGroup.Id, Date__c = sd1 + i * 14) ); } } if (newGroup.Frequency__c == 'monthly') { integer numberOfDays = sd1.daysBetween(ed1) / 30; for(integer i = 1; i < numberOfDays ; i++){ session.add (new Session__c( Term__c = newGroup.Id, Date__c = sd1 + 30) ); } } insert session; } } }
- Greer Zimmerman 5
- September 06, 2017
- Like
- 0
create records on related object from the creation of another
Hi all,
I am trying to get Salesforce to create multiple records through flows. I have Object A, which is related to multiple Object B records through a lookup field. Every time a new Object A is created I need to create an Object C in a master-detail relationship with every Object B record related to Object A.
I am trying to use flows. I currently have one that does a fast look up of all of the Object Bs, then leads to a loop, then leads to a record create. But it isn't working! Please help!
I am trying to get Salesforce to create multiple records through flows. I have Object A, which is related to multiple Object B records through a lookup field. Every time a new Object A is created I need to create an Object C in a master-detail relationship with every Object B record related to Object A.
I am trying to use flows. I currently have one that does a fast look up of all of the Object Bs, then leads to a loop, then leads to a record create. But it isn't working! Please help!
- Greer Zimmerman 5
- August 30, 2017
- Like
- 0
Trigger to create multiple child "sessions" on multiple days of the week from a parent "workshop"
Hi all - first of all - this is my first trigger. I have workshops and individual sessions for that workshop in Salesforce. When a workshop is created I want the sessions to be created based on the information entered on the workshop record. I understand how to do this if the workshop meets just one day a week (see code below - I think it looks okay?) but sometimes these workshops meet two or three times a week and the particular days are stored in a multi picklist. The user can select which days they meet, the start date, and the end date.
I cannot for the life of me figure out how to create ongoing records for sessions occuring on, say, Mondays AND Thursdays AND Wednesdays or any other combo of days. Can anyone help?
I cannot for the life of me figure out how to create ongoing records for sessions occuring on, say, Mondays AND Thursdays AND Wednesdays or any other combo of days. Can anyone help?
- Greer Zimmerman 5
- August 23, 2017
- Like
- 0
Guest User unable to submit forms via Force.com sites
.I have several online forms through force.com sites that I use to collect volunteer information. It has recently stopped allowing the guest user to submit online forms. When a form is submitted the user is told that authorization is required and they must login. When i set up a bug log for the user this code was returned
24.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
21:47:48.019 (19944087)|EXECUTION_STARTED
21:47:48.019 (19969929)|CODE_UNIT_STARTED|[EXTERNAL]|066d0000001NshO|VF: /apex/Unauthorized
21:47:48.078 (78932209)|CUMULATIVE_LIMIT_USAGE
21:47:48.078 (78932209)|LIMIT_USAGE_FOR_NS|(default)| Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10
21:47:48.078 (78932209)|CUMULATIVE_LIMIT_USAGE_END
21:47:48.078 (78980608)|CODE_UNIT_FINISHED|VF: /apex/Unauthorized 21:47:48.080 (80157510)|EXECUTION_FINISHED
I have NO idea what this means! Can anyone help?
- Greer Zimmerman 5
- November 11, 2015
- Like
- 0
Help creating a testClass
Hi all - I am totally stumped. I have been trying to figure out how to create a test class for the following class and I just can't get it to do it's thing. Any help?
trigger AssociatedSessions on Group__c (after insert) { List<Session__c> session = new List<Session__c>(); for (Group__c newGroup: Trigger.New) { Date sd1 = newGroup.Start_Date__c; Date ed1 = newGroup.End_Date__c; if (newGroup.Frequency__c == 'weekly') { integer numberOfWeeks = sd1.daysBetween(ed1) / 7 ; for(integer i = 0; i < numberOfWeeks ; i++){ //If MOnday is included IF(newGroup.Days_of_the_Week__c.contains('Monday') ){ IF(newGroup.Begins_on_a__c <= 1) { Date firstMonday = newGroup.Start_Date__c.toStartOfWeek() + 1; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstMonday + i * 7) ); } IF(newGroup.Begins_on_a__c > 1) { Date firstMonday = newGroup.Start_Date__c.toStartOfWeek() + 8; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstMonday + i * 7) ); } } //If Tuesday is included IF(newGroup.Days_of_the_Week__c.contains('Tuesday') ){ IF(newGroup.Begins_on_a__c <= 2) { Date firstTuesday = newGroup.Start_Date__c.toStartOfWeek() + 2; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstTuesday + i * 7) ); } IF(newGroup.Begins_on_a__c > 2) { Date firstTuesday = newGroup.Start_Date__c.toStartOfWeek() + 9; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstTuesday + i * 7) ); } } //If Wednesday is included IF(newGroup.Days_of_the_Week__c.contains('Wednesday') ){ IF(newGroup.Begins_on_a__c <= 3) { Date firstWednesday = newGroup.Start_Date__c.toStartOfWeek() + 3; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstWednesday + i * 7) ); } IF(newGroup.Begins_on_a__c > 3) { Date firstWednesday = newGroup.Start_Date__c.toStartOfWeek() + 10; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstWednesday + i * 7) ); } } //if Thursday is included IF(newGroup.Days_of_the_Week__c.contains('Thursday') ){ IF(newGroup.Begins_on_a__c <= 4) { Date firstThursday = newGroup.Start_Date__c.toStartOfWeek() + 4; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstThursday + i * 7) ); } IF(newGroup.Begins_on_a__c > 4) { Date firstThursday = newGroup.Start_Date__c.toStartOfWeek() + 11; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstThursday + i * 7) ); } } //If Friday is included IF(newGroup.Days_of_the_Week__c.contains('Friday') ){ IF(newGroup.Begins_on_a__c <= 5) { Date firstFriday = newGroup.Start_Date__c.toStartOfWeek() + 5; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstFriday + i * 7) ); } IF(newGroup.Begins_on_a__c > 5) { Date firstFriday = newGroup.Start_Date__c.toStartOfWeek() + 12; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstFriday + i * 7) ); } } //If Saturday is included IF(newGroup.Days_of_the_Week__c.contains('Saturday') ){ IF(newGroup.Begins_on_a__c <= 6) { Date firstSaturday = newGroup.Start_Date__c.toStartOfWeek() + 6; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSaturday + i * 7) ); } IF(newGroup.Begins_on_a__c > 6) { Date firstSaturday = newGroup.Start_Date__c.toStartOfWeek() + 12; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSaturday + i * 7) ); } } //If Sunday is included IF(newGroup.Days_of_the_Week__c.contains('Sunday') ){ IF(newGroup.Begins_on_a__c <= 0) { Date firstSunday = newGroup.Start_Date__c.toStartOfWeek() + 5; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSunday + i * 7) ); } IF(newGroup.Begins_on_a__c > 0) { Date firstSunday = newGroup.Start_Date__c.toStartOfWeek() + 12; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSunday + i * 7) ); } } } } if (newGroup.Frequency__c == 'daily') { integer numberOfDays = sd1.daysBetween(ed1); for(integer i = 0; i < numberOfDays ; i++){ session.add (new Session__c( Term__c = newGroup.Id, Date__c = sd1 + i) ); } } if (newGroup.Frequency__c == 'biweekly') { integer numberOfWeeks = sd1.daysBetween(ed1) / 14 ; for(integer i = 0; i < numberOfWeeks ; i++){ //If MOnday is included IF(newGroup.Days_of_the_Week__c.contains('Monday') ){ IF(newGroup.Begins_on_a__c <= 1) { Date firstMonday = newGroup.Start_Date__c.toStartOfWeek() + 1; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstMonday + i * 14) ); } IF(newGroup.Begins_on_a__c > 1) { Date firstMonday = newGroup.Start_Date__c.toStartOfWeek() + 8; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstMonday + i * 14) ); } } //If Tuesday is included IF(newGroup.Days_of_the_Week__c.contains('Tuesday') ){ IF(newGroup.Begins_on_a__c <= 2) { Date firstTuesday = newGroup.Start_Date__c.toStartOfWeek() + 2; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstTuesday + i * 14) ); } IF(newGroup.Begins_on_a__c > 2) { Date firstTuesday = newGroup.Start_Date__c.toStartOfWeek() + 9; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstTuesday + i * 14) ); } } //If Wednesday is included IF(newGroup.Days_of_the_Week__c.contains('Wednesday') ){ IF(newGroup.Begins_on_a__c <= 3) { Date firstWednesday = newGroup.Start_Date__c.toStartOfWeek() + 3; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstWednesday + i * 14) ); } IF(newGroup.Begins_on_a__c > 3) { Date firstWednesday = newGroup.Start_Date__c.toStartOfWeek() + 10; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstWednesday + i * 14) ); } } //if Thursday is included IF(newGroup.Days_of_the_Week__c.contains('Thursday') ){ IF(newGroup.Begins_on_a__c <= 4) { Date firstThursday = newGroup.Start_Date__c.toStartOfWeek() + 4; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstThursday + i * 14) ); } IF(newGroup.Begins_on_a__c > 4) { Date firstThursday = newGroup.Start_Date__c.toStartOfWeek() + 11; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstThursday + i * 14) ); } } //If Friday is included IF(newGroup.Days_of_the_Week__c.contains('Friday') ){ IF(newGroup.Begins_on_a__c <= 5) { Date firstFriday = newGroup.Start_Date__c.toStartOfWeek() + 5; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstFriday + i * 14) ); } IF(newGroup.Begins_on_a__c > 5) { Date firstFriday = newGroup.Start_Date__c.toStartOfWeek() + 12; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstFriday + i * 14) ); } } //If Saturday is included IF(newGroup.Days_of_the_Week__c.contains('Saturday') ){ IF(newGroup.Begins_on_a__c <= 6) { Date firstSaturday = newGroup.Start_Date__c.toStartOfWeek() + 6; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSaturday + i * 14) ); } IF(newGroup.Begins_on_a__c > 6) { Date firstSaturday = newGroup.Start_Date__c.toStartOfWeek() + 12; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSaturday + i * 14) ); } } //If Sunday is included IF(newGroup.Days_of_the_Week__c.contains('Sunday') ){ IF(newGroup.Begins_on_a__c <= 0) { Date firstSunday = newGroup.Start_Date__c.toStartOfWeek() + 5; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSunday + i * 14) ); } IF(newGroup.Begins_on_a__c > 0) { Date firstSunday = newGroup.Start_Date__c.toStartOfWeek() + 12; session.add (new Session__c( Term__c = newGroup.Id, Date__c = firstSunday + i * 14) ); } } } } if (newGroup.Frequency__c == 'monthly') { integer numberOfMonths = sd1.daysBetween(ed1) / 30; integer beginsOnA = newGroup.Begins_on_a__c.intValue(); for(integer i = 0; i < numberOfMonths ; i++){ date startDay = newGroup.Start_Date__c + i * 30; session.add (new Session__c( Term__c = newGroup.Id, Date__c = startDay.toStartOfWeek() + beginsOnA )); } } insert session; } }
- Greer Zimmerman 5
- September 18, 2017
- Like
- 0
method does not exist or incorrect signature - can't figure it out!
hi all - so i'm trying to get a series of child session records to be created when I create a parent record with a date range, a frequency, and certain days of the week when the sessions will take place. I can get my code to create a weekly session if it only occurs once a week, but I can't figure out how to get sessions for other days of the week to be created!
For instance if the group starts on a monday, and it also meets on Wednesday - and the group meets for 3 weeks, how can i get 6 sessions to be created with the correct days?
My code is below - right now I am JUST working on getting Mondays to work and plan on just copying and pasting for Tues - Sun. Any help? Am I going in the right direction at all ?
Right now I'm getting the errors:
- Line 15: Method does not exist or incorrect signature: void INCLUDES(String, String) from the type AssociatedSessions
- Line 16: Method does not exist or incorrect signature: void DATE(Integer, Integer, Integer) from the type AssociatedSessions
Total newbie - any help is appreciated
For instance if the group starts on a monday, and it also meets on Wednesday - and the group meets for 3 weeks, how can i get 6 sessions to be created with the correct days?
My code is below - right now I am JUST working on getting Mondays to work and plan on just copying and pasting for Tues - Sun. Any help? Am I going in the right direction at all ?
Right now I'm getting the errors:
- Line 15: Method does not exist or incorrect signature: void INCLUDES(String, String) from the type AssociatedSessions
- Line 16: Method does not exist or incorrect signature: void DATE(Integer, Integer, Integer) from the type AssociatedSessions
Total newbie - any help is appreciated
trigger AssociatedSessions on Group__c (after insert) { List<Session__c> session = new List<Session__c>(); for (Group__c newGroup: Trigger.New) { Date sd1 = newGroup.Start_Date__c; Date ed1 = newGroup.End_Date__c; if (newGroup.Frequency__c == 'weekly') { integer numberOfWeeks = sd1.daysBetween(ed1) / 7 ; for(integer i = 1; i < numberOfWeeks ; i++){ IF(INCLUDES(newGroup.Days_of_the_Week__c, 'Monday')) { Date firstMonday = (newGroup.Start_Date__c + ( 1 - MOD( newGroup.Start_Date__c - DATE( 1900, 1, 7 ), 7 ) )); session.add (new Session__c( Term__c = newGroup.Id, Date__c = sd1 + i * 7) ); } } if (newGroup.Frequency__c == 'daily') { integer numberOfDays = sd1.daysBetween(ed1); for(integer i = 1; i < numberOfDays ; i++){ session.add (new Session__c( Term__c = newGroup.Id, Date__c = sd1 + i * 7) ); } } if (newGroup.Frequency__c == 'biweekly') { integer numberOfDays = sd1.daysBetween(ed1) / 14; for(integer i = 1; i < numberOfDays ; i++){ session.add (new Session__c( Term__c = newGroup.Id, Date__c = sd1 + i * 14) ); } } if (newGroup.Frequency__c == 'monthly') { integer numberOfDays = sd1.daysBetween(ed1) / 30; for(integer i = 1; i < numberOfDays ; i++){ session.add (new Session__c( Term__c = newGroup.Id, Date__c = sd1 + 30) ); } } insert session; } } }
- Greer Zimmerman 5
- September 06, 2017
- Like
- 0
create records on related object from the creation of another
Hi all,
I am trying to get Salesforce to create multiple records through flows. I have Object A, which is related to multiple Object B records through a lookup field. Every time a new Object A is created I need to create an Object C in a master-detail relationship with every Object B record related to Object A.
I am trying to use flows. I currently have one that does a fast look up of all of the Object Bs, then leads to a loop, then leads to a record create. But it isn't working! Please help!
I am trying to get Salesforce to create multiple records through flows. I have Object A, which is related to multiple Object B records through a lookup field. Every time a new Object A is created I need to create an Object C in a master-detail relationship with every Object B record related to Object A.
I am trying to use flows. I currently have one that does a fast look up of all of the Object Bs, then leads to a loop, then leads to a record create. But it isn't working! Please help!
- Greer Zimmerman 5
- August 30, 2017
- Like
- 0
Trigger to create multiple child "sessions" on multiple days of the week from a parent "workshop"
Hi all - first of all - this is my first trigger. I have workshops and individual sessions for that workshop in Salesforce. When a workshop is created I want the sessions to be created based on the information entered on the workshop record. I understand how to do this if the workshop meets just one day a week (see code below - I think it looks okay?) but sometimes these workshops meet two or three times a week and the particular days are stored in a multi picklist. The user can select which days they meet, the start date, and the end date.
I cannot for the life of me figure out how to create ongoing records for sessions occuring on, say, Mondays AND Thursdays AND Wednesdays or any other combo of days. Can anyone help?
I cannot for the life of me figure out how to create ongoing records for sessions occuring on, say, Mondays AND Thursdays AND Wednesdays or any other combo of days. Can anyone help?
- Greer Zimmerman 5
- August 23, 2017
- Like
- 0
Trigger to create multiple child records when a parent is created
Hi ,
i am tryinng to create multiple child records when a parent record is created . The records in child object should be coming from an another relaetd object . Here is my data model
Data model 1: Account (Parent)<<<<<< Invoices (Child)
Date Model 2 : Account (Master Parent)<<<<<<Payment(Parent)<<<<<<Payment Line Items (Child) <<<<<< Invoices
Example Salesforce is my account and it has 20 Invoices , now i am creating a Payment ( notthing related to invoice at this time ) record and when i save this payment record 20 payment line items should be created. One record for each invoice salesforce account has .
I can create a child to a parent automatically but not sure how to create mutiple child records based on the Invoices object .
Here is the start with able to create single child record
Thanks,
Akhil
i am tryinng to create multiple child records when a parent record is created . The records in child object should be coming from an another relaetd object . Here is my data model
Data model 1: Account (Parent)<<<<<< Invoices (Child)
Date Model 2 : Account (Master Parent)<<<<<<Payment(Parent)<<<<<<Payment Line Items (Child) <<<<<< Invoices
Example Salesforce is my account and it has 20 Invoices , now i am creating a Payment ( notthing related to invoice at this time ) record and when i save this payment record 20 payment line items should be created. One record for each invoice salesforce account has .
I can create a child to a parent automatically but not sure how to create mutiple child records based on the Invoices object .
Here is the start with able to create single child record
trigger CreatePaymentLineItems on Payment__c (after insert) { List<Payment_Item__c> PItem = new List<Payment_Item__c>(); for (Payment__c Pay : trigger.new) { Payment_Item__c PBI = new Payment_Item__c(); PBI.Payment__c = Pay.Id; // PBI.Financial__c = Pay.; PItem.add(PBI); } insert PItem; }
Thanks,
Akhil
- SF7
- April 05, 2016
- Like
- 1