You need to sign in to do that
Don't have an account?
podgercor1.3917890117104897E12
how to write a test method
I am trying to deploy a trigger i made but i keep getting an error message that says
"Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required"
from checking other boards I can see that I will have to write a test method for this but how do I do that?
My trigger is as follows
trigger Timestamper on Event (after insert, after update)
{
List <ID> AccId = New List <ID>();
for (Event e: trigger.new)
{
if (e.Meeting_Status__c == 'Completed' && e.WhatId !=null)
{
AccId.add(e.WhatId);
}
}
List <Account> accList = [SELECT id, Last_Event_Close_Date__c FROM Account WHERE id in:AccId];
for(Account acnt : accList)
{
acnt.Last_Event_Close_Date__c = System.today();
}
update accList;
}
I have tried to start writeg a test class but have no idea where to go with it
@isTest
private class Trig_Test_Timestamper
{
static testMethod void Timestamper() {
test.startTest();
Event e = new Event (name = 'test');
insert e;
}
any help would be appreciated
thanks
"Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required"
from checking other boards I can see that I will have to write a test method for this but how do I do that?
My trigger is as follows
trigger Timestamper on Event (after insert, after update)
{
List <ID> AccId = New List <ID>();
for (Event e: trigger.new)
{
if (e.Meeting_Status__c == 'Completed' && e.WhatId !=null)
{
AccId.add(e.WhatId);
}
}
List <Account> accList = [SELECT id, Last_Event_Close_Date__c FROM Account WHERE id in:AccId];
for(Account acnt : accList)
{
acnt.Last_Event_Close_Date__c = System.today();
}
update accList;
}
I have tried to start writeg a test class but have no idea where to go with it
@isTest
private class Trig_Test_Timestamper
{
static testMethod void Timestamper() {
test.startTest();
Event e = new Event (name = 'test');
insert e;
}
any help would be appreciated
thanks
What you will have to do in the test class:
>create an Event and Account
>associate the event to an Account
> write a system.asserts statement to check if the account custom field "Last_Event_Close_Date__c" is updated with today's date.
Sample code available on the link below:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm
{
static testMethod void Timestamper() {
test.startTest();
Account a = new Account (name = 'tester');
insert a;
Event e = new Event (name = 'test', Meeting_Status__c = 'Completed', WhatId = a.Id);
insert e;
a = [Select Last_Event_Close_Date__c from Account where id=:a.Id];
system.assert(a.Last_Event_Close_Date__c = system.today());
}
I have created the two records
i think I have associated the event to the account
Test to see if Last_Event_Close_Date__c is set to Today()
any ideas?
Can't you create a workflow rule for this. You don't even have to write a trigger.
Create the workflow Rule with Evaluation Rule- Created and everytime its edited and the criteria:
event: Meeting_Status__c equals 'Completed' and
event: Account not equal to Null
and then do the field update:
Last_Event_Close_Date__c; do the formula with Today() for date or Now() for date/time
Hope that works.
Let me know if does not then we can continue with the trigger.
Thanks,
justin~sfdc
no a workflow rule wont work here - cant cross update the date field on Accounts from Events
Podge