You need to sign in to do that
Don't have an account?
D.Younai
Pleas tell me how to write Extension's test code.
Hi,Community!
I want to test the following code.
Plead tell me how to write test code.
public with sharing class LogACallControllerExtension { public Task task; ApexPages.Standardcontroller controller; public LogACallControllerExtension(ApexPages.StandardController controller) { this.task = (Task)controller.getRecord(); User u = [Select Id From User Where id = :UserInfo.getUserId()]; List<Lead> lead = [Select Id,Email,Phone From Lead Where Lead.Id =:ApexPages.currentPage().getParameters().get('who_id')]; task.WhoId = lead[0].Id; task.WhatId = ApexPages.currentPage().getParameters().get('what_id'); task.Status = ApexPages.currentPage().getParameters().get('tsk12'); task.OwnerId = u.Id; } public PageReference save() { Task t = new Task(); t.ownerId = task.ownerId; t.status = task.status; t.subject = task.subject; t.whoId = task.whoId; t.activityDate = task.activityDate; t.Description = task.Description; insert t; return null; } }
Thanks.
Hi,
You can use the following class,
public static void testmethod logcallextensiontest(){
Task t = new Task();
//fill all the values needed for task.
Insert t;
ApexPages.Standardcontroller std = new ApexPages.standardcontroller(t);
LogCallControllerExtension logcall = new Logcallextension(std);
//You can use System.assert methods here to validate the data before you save.
logcall.save();
}
All Answers
Hi,
You can use the following class,
public static void testmethod logcallextensiontest(){
Task t = new Task();
//fill all the values needed for task.
Insert t;
ApexPages.Standardcontroller std = new ApexPages.standardcontroller(t);
LogCallControllerExtension logcall = new Logcallextension(std);
//You can use System.assert methods here to validate the data before you save.
logcall.save();
}
Hi,Prakashb.
Thank you taught me.
I added the class.
But I get the following error.
"unexpected token: 'testmethod'"
What should I do?
Thanks.
Hi
Sorry for the typo..
it is static testmethod void instead of public static void testmethod..
Hi,
Sorry to keep pestering you.
I get the following error.
"Invalid type: Logcallextension"
How do I do next?
Thanks.
Again sorry for the typo..
It should be your class name in both the places..
LogCallControllerExtension logcall = new LogCallControllerExtension (std);
Sorry to keep pestering you.
First, it summarizes the current code.
I get the following error.
"Invalid type: LogCallControllerExtension"
How do I do next?
Thanks.
Hi,
I'm Sorry.
I was a typo.
I could be save.
After running the test, I get the following error.
"System.ListException: List index out of bounds: 0"
Error in this part:"LogACallControllerExtension logcall = new LogACallControllerExtension(std);"
I'm thought,but I cannot get an answer.
Please tell me what to do.
Thanks.
Hi,All.
Please tell me test code.
I come here to get help.
But, after running the test, I get the following error.
"System.ListException: List index out of bounds: 0"
Error in this part:"LogACallControllerExtension logcall = new LogACallControllerExtension(std);"
The following lists the log.
I can not be resolved in my skills.
Please help me.
Thanks.
Hi,All.
Has been successfully tested with the following code.
Thank you very much for everything.