You need to sign in to do that
Don't have an account?
how to Create Test Case for visual forcepage class?
Hello
can anyone please throw some ideas..on how to solve the below issue ....many thanks in advance
Right now I have problems in writing test case when I want to deploy this class to the production. could you help me with writing the test case or example for the test case for the class below.
public class UpdateItemQuoteCurrency {
// Constructor - this only really matters if the autoRun function doesn't work right
private final Quotation__c q;
public UpdateItemQuoteCurrency(ApexPages.StandardController stdController) {
this.q = (Quotation__c)stdController.getRecord();
}
// Code we will invoke on page load.
public PageReference autoRun() {
String theId = ApexPages.currentPage().getParameters().get('id');
Quotation__c Quote = [select CurrencyIsoCode from Quotation__c where Id= :theId];
if (theId == null) {
// Display the Visualforce page's content if no Id is passed over
return null;
}
List<Item__c> itemsToUpdate = new List<Item__c>();
List<Item__c> items = new List<Item__c>([SELECT Id FROM Item__c WHERE Quotation_No__c = :theId]);
for (Item__c item : items) {
item.CurrencyIsoCode = Quote.CurrencyIsoCode;
itemsToUpdate.add(item);
}
update(itemsToUpdate);
return null;
}
}
Hey
I can help you getting started
@isTest
private Class myTest{
static testMethod void ConstructorTestMethod(){
Quotation__c quote = new Quotation__c(name='myTest'); // create object with any required fields
insert quote;
ApexPages.StandardController sc = new ApexPages.StandardController(quote);
UpdateItemQuoteCurrency uiqc = new UpdateItemQuoteCurrency(sc);
}
static testMethod void TestMethod(){
Quotation__c quote = new Quotation__c(name='myTest'); // create object with any required fields
insert quote;
ApexPages.CurrentPage().getParameters().put('id',quote.id);
UpdateItemQuoteCurrency uiqc = new UpdateItemQuoteCurrency();
uiqc.autoRun();
}
}
Please note I haven't tested this code, but this is the gist of what you need to get started.
Cheers,
Wes
All Answers
Hey
I can help you getting started
@isTest
private Class myTest{
static testMethod void ConstructorTestMethod(){
Quotation__c quote = new Quotation__c(name='myTest'); // create object with any required fields
insert quote;
ApexPages.StandardController sc = new ApexPages.StandardController(quote);
UpdateItemQuoteCurrency uiqc = new UpdateItemQuoteCurrency(sc);
}
static testMethod void TestMethod(){
Quotation__c quote = new Quotation__c(name='myTest'); // create object with any required fields
insert quote;
ApexPages.CurrentPage().getParameters().put('id',quote.id);
UpdateItemQuoteCurrency uiqc = new UpdateItemQuoteCurrency();
uiqc.autoRun();
}
}
Please note I haven't tested this code, but this is the gist of what you need to get started.
Cheers,
Wes
Hi Wes,
Thanks for your input
Best Regards,
Andry