You need to sign in to do that
Don't have an account?
Arik
Task Created from Workflow to trigger new Workfow
I want a field update to take place via workflow once a task is created with another workflow. The field is custom so it cant be added when task created...any ideas
acct.TestDate__c = Date.newInstance(2011,5,1);
All Answers
You could key off of the Subject Name - have a Trigger in place that updates a checkbox field to TRUE based on that subject. Then, you could have a workflow trigger off of that field change.
-Andy
i tried that - it didnt work
Ahhh - found out why. Salesforce doesn't allow this to happen.
You may have to go 100% APEX on this route.
-Andy
Any thoughts on how to write the APEX ?
How are you kicking off the initial workflow? That's the object that we'd have to start from.
Thanks for answering.
The object has a field called "Contract Signed" which is a check box. Then there are a bunch of dates on the object representing differents steps in the process, such as last day for this, last day for that, etc. What we want is when the checkbox checks, events are created from that checkbox. Right now, the way it works, is tasks are created using a workflow. I thought i could use a field update and put a custom box on the task to trigger a apex trigger to turn task into event, which does not work if task is created from workflow. Understand ?
To get all of the fields you want on that Task (or Event), you'd have to forgo Workflow altogether on the object and go full on APEX Triggers. Using the trigger, you can detect if a field has changed from the previous value (false to true, or "a" to "b") and then create a Task or Event that way.
If you give me your object and field names that you want to do this from - I can structure up some code for you to start from.
-Andy
Thank you
Just use generic fields - they are real specific
Something like this...
This works great !!!
I am going to do the following with it. I am going to basically make many copies of this because I have many events that have to be generated. In other words, closing is 1 event, inspection is another event. So my plan is to put a bunch of check marks on the object (hidden from view - meaning not on the layout), and then have 1 checkbox on the layout, whcih will cause (via workflow) all of the checkboxes to be marked true. That would trigger the event creation for each one.
The next tiny small favor is (i know big deal) is to ask how to grab a field called eventdate and not the system date to create the event. Also, how can I make it an "all day event".
Finally - I need the test class.
Thank you so much !!!!
One "best practice" note - if you're going to do this on multiple checkboxes, use IF statements within the single trigger to do it.
One small error I just saw - in the code I provided...this is wrong..
should be:
Sorry about that.
If "eventdate" is a field on the object that you're triggering on - you'll just substitute out the "System.Today()". for the field name.
Test Class - just spin an @isTest class up and:
1) insert your parent record
2) flip your checkboxes to true and update the record
That should get them all to fire.
-Andy
Again sorry to be a pain -
How do you make the event an all day event ?
and honestly - the test class thing i never know how to do that
Thank You again
In the code, add this line:
(big smile) - it's not a completely full ride on the Test Class. Start one up and take an initial stab at it. I'll help you as you encounter issues, but I have to challenge you a *little*. *smile*
-Andy
You rock andy - Thank you !!!
Can you please look at this:
I don't regret it! I'm absolutely happy I can help!
You need to have the StartDate filled in - that's required.
-Andy
It's the all day event thing that is throwing the error - I have it in the wrong place - any thoughts ?
The APEX error you referenced is talking about the StartDateTime field - put that back in the code and you should be fine.
-Andy
Attached is where i am & it Works :-) !!!
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
trigger AccountSimpleTrigger on Account (before update) {
////////////////////////////////////
// This trigger detects the change of the TestCheckbox field
// and creates an Event
////////////////////////////////////
if(trigger.isUpdate && trigger.isBefore) {
// Create empty List to hold new Events (bulk DML)
List<Event> lstNewEvents = new List<Event>();
for(Account a : trigger.new) {
// Determine if the checkbox is TRUE and the user has just flipped it from FALSE.
if(a.TestCheckbox__c == true && a.TestCheckbox__c != trigger.oldMap.get(a.Id).TestCheckbox__c) {
// Set Start Date
Datetime dtmStart = a.TestDate__c;
Datetime dtmEnd = dtmStart.addMinutes(60);
Long lngClassDuration = (dtmEnd.getTime() - dtmStart.getTime()) / 60000;
// Create Event
Event newEvent = new Event();
newEvent.OwnerId = UserInfo.getUserId(); // Sets the current userId as the Event Owner
newEvent.WhatId = a.Id; // Sets the Account as the Event's "Related To"
newEvent.Subject = 'New Event - Some Reason';
newEvent.StartDateTime = dtmStart;
newEvent.EndDateTIme = dtmEnd;
newEvent.DurationInMinutes = Integer.valueOf(lngClassDuration);
lstNewEvents.add(newEvent);
}
}
if(lstNewEvents.size() > 0) { insert lstNewEvents; }
}
}
However, I have tried 100 diffeent ways to make it a all day event and every way gives error -
Please tell me hwere to put statement and what to delete
Thank you again !!!
Here is the code modfied to make it an all-day event:
Self-initiated effort is never pathetic. Showing that you're taking the initiative to ask and learn is what this community is all about.
Best practices dictate that you should create a new Account from within your Test Class:
Then, (using our sample trigger as the basis), set your checkboxe to TRUE and update the account again:
-Andy
This is beyond out of my league - is there any chance for the answer key - please
Ahhh but you were so close!
I swear - last post -
What did your trigger end up looking like?
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
////////////////////////////////////
// This trigger detects the change of the TestCheckbox field
// and creates an Event
////////////////////////////////////
if(trigger.isUpdate && trigger.isBefore) {
// Create empty List to hold new Events (bulk DML)
List<Event> lstNewEvents = new List<Event>();
for(Account a : trigger.new) {
// Determine if the checkbox is TRUE and the user has just flipped it from FALSE.
if(a.TestCheckbox__c == true && a.TestCheckbox__c != trigger.oldMap.get(a.Id).TestCheckbox__c) {
// Set Start Date
Date dteStart = a.TestDate__c;
// Create Event
Event newEvent = new Event();
newEvent.OwnerId = UserInfo.getUserId(); // Sets the current userId as the Event Owner
newEvent.WhatId = a.Id; // Sets the Account as the Event's "Related To"
newEvent.Subject = 'New Event - Some Reason';
newEvent.ActivityDate = a.TestDate__c;
newEvent.IsAllDayEvent = true;
lstNewEvents.add(newEvent);
}
}
if(lstNewEvents.size() > 0) { insert lstNewEvents; }
}
Your a.TestDate__c field is null when the Trigger fires.
-Andy
Pardon my iggnorance, but see below:
Error: Compile Error: Variable does not exist: a.TestDate__c at line 8 column 9
@isTest
private class testAccountSimpleTrigger {
public static testMethod void unitTestAccountSimpleTrigger() {
Account acct = new Account();
acct.Name = 'Test Account';
a.TestDate__c = '1/1/2012';
insert acct;
test.startTest();
acct.TestCheckbox__c = true;
update acct;
test.stopTest();
}
}
acct.TestDate__c = '1/1/2012';
So close....
Error: Compile Error: Illegal assignment from String to Date at line 8 column 9
@isTest
private class testAccountSimpleTrigger {
public static testMethod void unitTestAccountSimpleTrigger() {
Account acct = new Account();
acct.Name = 'Test Account';
acct.TestDate__c = '1/1/2012';
insert acct;
test.startTest();
acct.TestCheckbox__c = true;
update acct;
test.stopTest();
}
}
acct.TestDate__c = Date.newInstance(2011,5,1);
you are god !!!
Nice thread....
Glad to see someone willing to help so much and someone willing to learn.....
This is what this community is about!!!!
Andrew is the greatest !!!
What is the trigger you're really working with - and what errors are you seeing?
-Andy
its the exact same one.
I cant get past the basic things like eof curly bracket, etc
I assumed I could just copy the trigger, make it work on the custom object and it just doesnt. I could do a screen shot if you want
Nothing to be embarassed of - this is how we all learn this stuff. =) Post up what you're working with and we'll parse through it.
-Andy
trigger <ErnestMoney> on rethink2__Closing__c (before update) {
////////////////////////////////////
// This trigger detects the change of the TestCheckbox field
// and creates an Event
////////////////////////////////////
if(trigger.isUpdate && trigger.isBefore) {
// Create empty List to hold new Events (bulk DML)
List<Event> lstNewEvents = new List<Event>();
for(rethink2__Closing__c a : trigger.new) {
// Determine if the checkbox is TRUE and the user has just flipped it from FALSE.
if(a.TestCheckbox__c == true && a.TestCheckbox__c != trigger.oldMap.get(a.Id).TestCheckbox__c) {
// Set Start Date
Date dteStart = a.TestDate__c;
// Create Event
Event newEvent = new Event();
newEvent.OwnerId = UserInfo.getUserId(); // Sets the current userId as the Event Owner
newEvent.WhatId = a.Id; // Sets the Account as the Event's "Related To"
newEvent.Subject = 'New Event - Some Reason';
newEvent.ActivityDate = a.TestDate__c;
newEvent.IsAllDayEvent = true;
lstNewEvents.add(newEvent);
}
}
if(lstNewEvents.size() > 0) { insert lstNewEvents; }
}
You're missing one "close" curly brace } at the end of the trigger - that should do it for ya. Everything else looks good.
-Andy
hi this is the error:
Error: Compile Error: expecting right curly bracket, found 'EOF' at line 0 column -1
trigger ErnestMoney on rethink2__Closing__c (before update) {
////////////////////////////////////
// This trigger detects the change of the TestCheckbox field
// and creates an Event
////////////////////////////////////
if(trigger.isUpdate && trigger.isBefore) {
// Create empty List to hold new Events (bulk DML)
List<Event> lstNewEvents = new List<Event>();
for(rethink2__Closing__c a : trigger.new) {
// Determine if the checkbox is TRUE and the user has just flipped it from FALSE.
if(a.TestCheckbox__c == true && a.TestCheckbox__c != trigger.oldMap.get(a.Id).TestCheckbox__c) {
// Set Start Date
Date dteStart = a.TestDate__c;
// Create Event
Event newEvent = new Event();
newEvent.OwnerId = UserInfo.getUserId(); // Sets the current userId as the Event Owner
newEvent.WhatId = a.Id; // Sets the Account as the Event's "Related To"
newEvent.Subject = 'New Event - Some Reason';
newEvent.ActivityDate = a.TestDate__c;
newEvent.IsAllDayEvent = true;
lstNewEvents.add(newEvent);
}
}
if(lstNewEvents.size() > 0) { insert lstNewEvents; }
}
Yup - that's exactly it. Put a } "right curly bracket" on the last line of the trigger file.
It Works !!!!!
Halalujua -
I didnt undertand because the error said it needed a bracket at the beggining not the end
Thank You !!!!
I'm Back - I know you want to hit delete, but just look at this for 1 second - pleaseeeee:
Error: Compile Error: Expression cannot be assigned at line -1 column -1
@isTest
private class testCICDocumentsObjectionDeadline{
public static testMethod void unitTestCICDocumentsObjectionDeadline() {
rethink2__Closing__c.Name = new Name();
rethink2__Closing__c.Name = 'Test Closing';
rethink2__Closing__c.CIC_Documents_Objection_Deadline__c = Date.newInstance(2011,5,1);
insert rethink2__Closing__c.Name;
test.startTest();
rethink2__Closing__c.CIC_Documents_Objection_Deadline_Checkbo__c = true;
update rethink2__Closing__c.Name;
test.stopTest();
}
}
Give this a whirl:
In APEX when you're working with records - you need to declare a variable as an instance of an object. The "thisObj" is an example of this. All of the work you do post-variable declaration is with the variable only - no need to reference the object again.
-Andy
Thank You Very very Much !!!!!