You need to sign in to do that
Don't have an account?
Soundar
Test Class Coverage Problem - expecting a right parentheses, found 'controller'
Hi Friends,
I getting small problem while covering a test class. I am not able to call one method from controller to testclass. Could you please help to me.
------------------------------------------ Controller -----------------------------------------
public with sharing class AccountDealOpportunity {
public AccountDealOpportunity(ApexPages.StandardController controller) // I Want to call This method
{
lstOpp = new List<Opportunity__c>();
AccId = ApexPages.currentPage().getParameters().get('id');
Account iAcc = [SELECT id, Recordtype.Name, Name FROM Account WHERE Id =: AccId];
String Query = 'SELECT id, Name, Originator__c, Investor__c, Interested_Products__c, Asset_Class__c, Investor_Category__c,'+
+'Amount__c,Valid_Till__c,RecordType.Name FROM Opportunity__c where ';
if(iAcc.RecordType.Name == 'Investor')
{
query = query + 'Investor__c =: AccId';
}
else if(iAcc.RecordType.Name == 'Originator')
{
query = query + 'Originator__c =: AccId';
}
lstOpp = Database.query(query);
}
public List<Opportunity__c> lstOpp {get;set;}
Public Boolean isShowOpp {get;set;}
String AccId;
public AccountDealOpportunity()
{
}
public pageReference CreateDeal()
{
PageReference DealPage = new PageReference('/apex/CreateDeals?id=' + AccId);
DealPage.setRedirect(true);
return DealPage;
}
public pageReference OpportunitytoDeal()
{
return Null;
}
}
------------------------------------------------- Test Class --------------------------------
/*-------------------------------------------------
Created Date : 10/05/2017
Refered Class : AccountDealOpportunity.
------------------------------------------------- */
@IsTest(SeeAllData = True)
public class AccountDealOpportunityTest{
public static testMethod void AccountDealMethod(){
String AccId;
//List<Opportunity__c> lstOpp = new List<Opportunity__c>();
AccId = ApexPages.currentPage().getParameters().get('id');
/*Account Duplicate Values Fixed */
Account acc = New Account();
acc.Name = 'Test Account';
//acc.Recordtype.Name = 'Originator';
insert acc;
/* String Query = 'SELECT id, Name, Originator__c, Investor__c, Interested_Products__c, Asset_Class__c, Investor_Category__c,'+
+'Amount__c,Valid_Till__c,RecordType.Name FROM Opportunity__c where ';
if(acc.RecordType.Name == 'Investor')
{
query = query + 'Investor__c = 00Np0000001FjCGEA0';
}
else if(acc.RecordType.Name == 'Originator')
{
query = query + 'Originator__c = 00Np0000001FjCL';
}
*/
/*Opportunity Duplicate Values Fixed */
Opportunity__c opp = New Opportunity__c();
opp.name = 'Test Opportunity';
//opp.Originator__c = '00Np0000001FjCL';
//opp.Investor__c = '00Np0000001FjCGEA0';
opp.Interested_Products__c = 'Term Loan';
opp.Asset_Class__c ='AHF';
opp.Investor_Category__c = 'NBFC';
opp.Amount__c = 1000;
opp.Valid_Till__c = date.parse('11/6/2017');
//opp.RecordType.Name = 'Originator';
insert opp;
AccountDealOpportunity accts = New AccountDealOpportunity();
accts.CreateDeal();
accts.OpportunitytoDeal();
//accts.AccountDealOpportunity();
AccountDealOpportunity(ApexPages.StandardController controller) //
}
}
Error: Compile Error: expecting a right parentheses, found 'controller' at line 55 column 58
Many Thanks In Advance ......
Regards,
Soundar Rajan P
7418425418
I getting small problem while covering a test class. I am not able to call one method from controller to testclass. Could you please help to me.
------------------------------------------ Controller -----------------------------------------
public with sharing class AccountDealOpportunity {
public AccountDealOpportunity(ApexPages.StandardController controller) // I Want to call This method
{
lstOpp = new List<Opportunity__c>();
AccId = ApexPages.currentPage().getParameters().get('id');
Account iAcc = [SELECT id, Recordtype.Name, Name FROM Account WHERE Id =: AccId];
String Query = 'SELECT id, Name, Originator__c, Investor__c, Interested_Products__c, Asset_Class__c, Investor_Category__c,'+
+'Amount__c,Valid_Till__c,RecordType.Name FROM Opportunity__c where ';
if(iAcc.RecordType.Name == 'Investor')
{
query = query + 'Investor__c =: AccId';
}
else if(iAcc.RecordType.Name == 'Originator')
{
query = query + 'Originator__c =: AccId';
}
lstOpp = Database.query(query);
}
public List<Opportunity__c> lstOpp {get;set;}
Public Boolean isShowOpp {get;set;}
String AccId;
public AccountDealOpportunity()
{
}
public pageReference CreateDeal()
{
PageReference DealPage = new PageReference('/apex/CreateDeals?id=' + AccId);
DealPage.setRedirect(true);
return DealPage;
}
public pageReference OpportunitytoDeal()
{
return Null;
}
}
------------------------------------------------- Test Class --------------------------------
/*-------------------------------------------------
Created Date : 10/05/2017
Refered Class : AccountDealOpportunity.
------------------------------------------------- */
@IsTest(SeeAllData = True)
public class AccountDealOpportunityTest{
public static testMethod void AccountDealMethod(){
String AccId;
//List<Opportunity__c> lstOpp = new List<Opportunity__c>();
AccId = ApexPages.currentPage().getParameters().get('id');
/*Account Duplicate Values Fixed */
Account acc = New Account();
acc.Name = 'Test Account';
//acc.Recordtype.Name = 'Originator';
insert acc;
/* String Query = 'SELECT id, Name, Originator__c, Investor__c, Interested_Products__c, Asset_Class__c, Investor_Category__c,'+
+'Amount__c,Valid_Till__c,RecordType.Name FROM Opportunity__c where ';
if(acc.RecordType.Name == 'Investor')
{
query = query + 'Investor__c = 00Np0000001FjCGEA0';
}
else if(acc.RecordType.Name == 'Originator')
{
query = query + 'Originator__c = 00Np0000001FjCL';
}
*/
/*Opportunity Duplicate Values Fixed */
Opportunity__c opp = New Opportunity__c();
opp.name = 'Test Opportunity';
//opp.Originator__c = '00Np0000001FjCL';
//opp.Investor__c = '00Np0000001FjCGEA0';
opp.Interested_Products__c = 'Term Loan';
opp.Asset_Class__c ='AHF';
opp.Investor_Category__c = 'NBFC';
opp.Amount__c = 1000;
opp.Valid_Till__c = date.parse('11/6/2017');
//opp.RecordType.Name = 'Originator';
insert opp;
AccountDealOpportunity accts = New AccountDealOpportunity();
accts.CreateDeal();
accts.OpportunitytoDeal();
//accts.AccountDealOpportunity();
AccountDealOpportunity(ApexPages.StandardController controller) //
}
}
Error: Compile Error: expecting a right parentheses, found 'controller' at line 55 column 58
Many Thanks In Advance ......
Regards,
Soundar Rajan P
7418425418
ApexPages.StandardController sc = new ApexPages.StandardController(accts);
AccountDealOpportunity ext=new AccountDealOpportunity(sc);
ext.AccountDealOpportunity ();
Really Thanks to Quick Response ... now i am getting an another one error.
---------------------------------------- TestClass -----------------------
/*-------------------------------------------------
Created Date : 10/05/2017
Refered Class : AccountDealOpportunity.
------------------------------------------------- */
@IsTest(SeeAllData = True)
public class AccountDealOpportunityTest{
public static testMethod void AccountDealMethod(){
String AccId;
AccId = ApexPages.currentPage().getParameters().get('id');
//List<Opportunity__c> lstOpp = new List<Opportunity__c>();
/*Account Duplicate Values Fixed */
Account acc = New Account();
acc.Name = 'Test Account';
//acc.Recordtype.Name = 'Originator';
insert acc;
/*Opportunity Duplicate Values Fixed */
Opportunity__c opp = New Opportunity__c();
opp.name = 'Test Opportunity';
//opp.Originator__c = '00Np0000001FjCL';
//opp.Investor__c = '00Np0000001FjCGEA0';
opp.Interested_Products__c = 'Term Loan';
opp.Asset_Class__c ='AHF';
opp.Investor_Category__c = 'NBFC';
opp.Amount__c = 1000;
opp.Valid_Till__c = date.parse('11/6/2017');
//opp.RecordType.Name = 'Originator';
insert opp;
AccountDealOpportunity accts = New AccountDealOpportunity();
accts.CreateDeal();
accts.OpportunitytoDeal();
ApexPages.StandardController sc = new ApexPages.StandardController(accts);
AccountDealOpportunity ext=new AccountDealOpportunity(sc);
ext.AccountDealOpportunity ();
}
}
Error: Compile Error: Constructor not defined: [ApexPages.StandardController].<Constructor>(AccountDealOpportunity) at line 42 column 35
Thanks in Advance ..
Regards,
Soundar Raj.
if it would be linked then u can try
ApexPages.StandardController sc = new ApexPages.StandardController(opp);
AccountDealOpportunity ext=new AccountDealOpportunity(sc);
ext.AccountDealOpportunity ();
I am new to development, So i am struggling in some important points.
Can you able to create a test class for the below controller. Please Cover a test class if you can.
----------------------------------------------- Controller ----------------------------
public with sharing class AccountDealOpportunity {
public AccountDealOpportunity(ApexPages.StandardController controller) {
lstOpp = new List<Opportunity__c>();
AccId = ApexPages.currentPage().getParameters().get('id');
Account iAcc = [SELECT id, Recordtype.Name, Name FROM Account WHERE Id =: AccId];
String Query = 'SELECT id, Name, Originator__c, Investor__c, Interested_Products__c, Asset_Class__c, Investor_Category__c,'+
+'Amount__c,Valid_Till__c,RecordType.Name FROM Opportunity__c where ';
if(iAcc.RecordType.Name == 'Investor')
{
query = query + 'Investor__c =: AccId';
}
else if(iAcc.RecordType.Name == 'Originator')
{
query = query + 'Originator__c =: AccId';
}
lstOpp = Database.query(query);
}
public List<Opportunity__c> lstOpp {get;set;}
Public Boolean isShowOpp {get;set;}
String AccId;
public AccountDealOpportunity()
{
}
public pageReference CreateDeal()
{
PageReference DealPage = new PageReference('/apex/CreateDeals?id=' + AccId);
DealPage.setRedirect(true);
return DealPage;
}
public pageReference OpportunitytoDeal()
{
return Null;
}
}
------------------------------------------------------------------------------------------------------------------------
Thanks In Advance.
Soundar Raj.
Now it's showing new Error ....
Error Message : System.NullPointerException: Attempt to de-reference a null object
Stack Trace: Class.AccountDealOpportunityTest.AccountDealMethod: line 18, column 1
---------------------------Controller -----------
@IsTest(SeeAllData = True)
public class AccountDealOpportunityTest{
public static testMethod void AccountDealMethod(){
String AccId;
AccId = ApexPages.currentPage().getParameters().get('id');
//List<Opportunity__c> lstOpp = new List<Opportunity__c>();
/*Account Duplicate Values Fixed */
Account acc = New Account();
acc.Name = 'Test Account';
acc.Recordtype.Name = 'Originator'; // Error Showing In This Line.
insert acc;
/*Opportunity Duplicate Values Fixed */
Opportunity__c opp = New Opportunity__c();
opp.name = 'Test Opportunity';
opp.Originator__c = '00Np0000001FjCL';
opp.Investor__c = '00Np0000001FjCGEA0';
opp.Interested_Products__c = 'Term Loan';
opp.Asset_Class__c ='AHF';
opp.Investor_Category__c = 'NBFC';
opp.Amount__c = 1000;
opp.Valid_Till__c = date.parse('11/6/2017');
opp.RecordType.Name = 'Originator';
insert opp;
AccountDealOpportunity accts = New AccountDealOpportunity();
accts.CreateDeal();
accts.OpportunitytoDeal();
//ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(opp);
//AccountDealOpportunity ext = new AccountDealOpportunity (setcon);
//ext.AccountDealOpportunity();
Apexpages.StandardController stdController = new Apexpages.StandardController(opp); // here t is the contact instance
AccountDealOpportunity controller = new AccountDealOpportunity(StdController);
//ApexPages.StandardController const1 = new ApexPages.standardController(opp);
//ApexPages.StandardController sc = new ApexPages.StandardController(accts);
//AccountDealOpportunity ext=new AccountDealOpportunity(sc);
//ext.AccountDealOpportunity ();
}
}
Thanks ....
Regards,
Soundar.
public static Id strRecordTypeC;
strRecordTypeC = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Originator').getRecordTypeId();
Account acc = New Account();
acc.Name = 'Test Account';
acc.RecordtypeId.Name = strRecordTypeC;
insert acc;
Now It's Covering 94% as well. But onle line is not covering. Can you please advise why it's not covering.
public with sharing class AccountDealOpportunity {
public AccountDealOpportunity(ApexPages.StandardController controller) {
lstOpp = new List<Opportunity__c>();
AccId = ApexPages.currentPage().getParameters().get('id');
Account iAcc = [SELECT id, Recordtype.Name, Name FROM Account WHERE Id =: AccId];
String Query = 'SELECT id, Name, Originator__c, Investor__c, Interested_Products__c, Asset_Class__c, Investor_Category__c,'+
+'Amount__c,Valid_Till__c,RecordType.Name FROM Opportunity__c where ';
if(iAcc.RecordType.Name == 'Investor')
{
query = query + 'Investor__c =: AccId';
}
else if(iAcc.RecordType.Name == 'Originator')
{
query = query + 'Originator__c =: AccId';
}
lstOpp = Database.query(query);
}
public List<Opportunity__c> lstOpp {get;set;}
Public Boolean isShowOpp {get;set;} // This Line Is Not Covering....
String AccId;
public AccountDealOpportunity()
{
}
public pageReference CreateDeal()
{
PageReference DealPage = new PageReference('/apex/CreateDeals?id=' + AccId);
DealPage.setRedirect(true);
return DealPage;
}
public pageReference OpportunitytoDeal()
{
return Null;
}
}
Regards,
Soundar Raj.
Public Boolean isShowOpp {get;set;} this is varible declaration.I think you didnt reference this variable anywhere in code .so you can leave it.
I you want use then you can use like following
AccountDealOpportunity asd=new AccountDealOpportunity();
asd.isShowOpp=true;(true and false depends on your requirement)
If you like my answer please like or mark as best answer.
it's working fine . Thank you very much!!
Regards,
Soundar Raj