-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
3Questions
-
4Replies
I need help writing increase code coverage
My test class:
@isTest
public class AccountSummaryTestClass {
static testMethod void SummaryAccountwithOpportunity(){
Account testAccount = new Account();
testAccount.Name='Test Account';
testAccount.BillingCountry='France';
insert(testAccount);
Boolean ShowLostOpportunity;
ShowLostOpportunity=True;
Opportunity testOpp = new Opportunity();
testOpp.Name='test Opp';
testOpp.AccountId=testAccount.id;
testOpp.StageName='Closed Won';
testOpp.CloseDate=Date.today();
testOpp.CurrencyIsoCode='EUR';
testOpp.Pricebook2Id='01sD0000000V1Zk';
testOpp.Won_Reason_Explanation__c='competitive pricing';
testOpp.Perdue_pour__c='ACCLAIM IP';
testOpp.Probability__c='1 - Very likely to win';
testOpp.Has_a_LeadGen_been_involved_in_this_opp__c='No';
testOpp.Has_a_SME_been_involved_in_this_opp__c='No';
testOpp.Needs_Motivations__c='testing';
testOpp.Decision_Maker__c='0033N00000FwkexQAB';
testOpp.type='Cross Sell';
testOpp.Opportunity_Origin__c='Corporate Website';
testOpp.Opportunity_Terrirory__c='France';
testOpp.Solution_Already_in_Place__c='No Existing Solution';
testOpp.Are_other_solutions_being_evaluated__c='No';
testOpp.NextStep='recall';
testOpp.Start_Date__c=Date.today();
insert(testOpp);
Opportunity testOpp2 = new Opportunity();
testOpp2.Name='test Opp2';
testOpp2.AccountId=testAccount.id;
testOpp2.StageName='Interest';
testOpp2.CloseDate=Date.today();
testOpp2.CurrencyIsoCode='EUR';
testOpp2.Pricebook2Id='01sD0000000V1Zk';
testOpp2.Main_Product__c='Orbit Intelligence';
insert(testOpp2);
Opportunity testOpp3 = new Opportunity();
testOpp3.Name='test Opp3';
testOpp3.AccountId=testAccount.id;
testOpp3.StageName='Closed Lost';
testOpp3.CloseDate=Date.today();
testOpp3.CurrencyIsoCode='EUR';
testOpp3.Pricebook2Id='01sD0000000V1Zk';
testOpp3.Won_Lost_Reason__c='Duplicated Opportunity';
testOpp3.Perdue_pour__c='ANAQUA';
testOpp3.Probability__c='3 - Very unlikely to win';
testOpp3.Has_a_LeadGen_been_involved_in_this_opp__c='No';
testOpp3.Has_a_SME_been_involved_in_this_opp__c='No';
testOpp3.Needs_Motivations__c='testing';
testOpp3.Decision_Maker__c='0033N00000FwkexQAB';
testOpp3.type='Cross Sell';
testOpp3.Opportunity_Origin__c='Corporate Website';
testOpp3.Opportunity_Terrirory__c='France';
testOpp3.Solution_Already_in_Place__c='No Existing Solution';
testOpp3.Are_other_solutions_being_evaluated__c='No';
testOpp3.NextStep='recall';
insert(testOpp3);
Product2 prod = new Product2();
prod.Product_Category__c = 'SaaS';
prod.Family='IPBI';
prod.Product_Sub_Family__c='Orbit Intelligence';
prod.Name='Product Test';
insert(prod);
PricebookEntry standardPBE = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod.Id, UnitPrice = 1000, IsActive = true);
insert standardPBE;
PricebookEntry pb = new PricebookEntry(UnitPrice = 10, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod.Id,isActive = true);
insert(pb);
OpportunityLineItem Line4 = new OpportunityLineItem(PricebookEntryId=pb.Id, OpportunityId=testOpp3.Id, Quantity=1,TotalPrice=100);
insert(Line4);
ShowLostOpportunity = True;
Contract testContract = new Contract();
testContract.accountId = testAccount.id;
testContract.Name='Test Contract';
testContract.Status='Draft';
testContract.StartDate = Date.today();
testContract.Total_Amount__c = 25000;
testContract.ContractTerm=12;
testContract.CurrencyIsoCode='EUR';
testContract.Product_Description__c='test Asset';
testContract.Product__c='Orbit Asset';
insert(testContract);
testContract = [Select Total_Amount__c,Name,StartDate,EndDate,Status from Contract Where Id =: testContract.Id limit 1];
testContract.Status='Activated';
update testContract;
Contract testContract2 = new Contract();
testContract2.accountId = testAccount.id;
testContract2.Name='Test Contract2';
testContract2.Status='Draft';
testContract2.StartDate = date.today().addDays(-760);
testContract2.Total_Amount__c = 25000;
testContract2.ContractTerm=12;
testContract2.CurrencyIsoCode='EUR';
testContract2.Product_Description__c='test expired';
testContract2.Product__c='Orbit Asset';
insert(testContract2);
Task testTask = new Task();
testTask.whatId = testAccount.id;
testTask.Product_Family__c = 'IAM';
testTask.ActivityDate=Date.today();
insert(testTask);
testOpp3.ContractId =testContract.Id;
Event testEvent = new Event();
testEvent.whatId = testAccount.id;
testEvent.Subject = 'Call';
testEvent.OwnerId = '0052p000008rA5o';
testEvent.StartDateTime = Datetime.now().addDays(-800);
testEvent.EndDateTime = Datetime.now().addDays(-800).addHours(1);
testEvent.Meetings__c='Demo on-site';
testEvent.Product_Service_of_Interest__c = 'Orbit Asset';
insert(testEvent);
testOpp3.Pricebook2Id='01sD0000000V1Zk';
Product2 prod2 = new Product2();
prod2.Product_Category__c = 'SaaS';
prod2.Family='IPBI';
prod2.Product_Sub_Family__c='Orbit Trademark';
prod2.Name='Product Test 2';
insert(prod2);
PricebookEntry standardPB = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod2.Id, UnitPrice = 1000, IsActive = true);
insert standardPB;
PricebookEntry pb2 = new PricebookEntry(UnitPrice = 10, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod2.Id,isActive = true);
insert(pb2);
OpportunityLineItem Line = new OpportunityLineItem(PricebookEntryId=pb2.Id, OpportunityId=testOpp3.Id, Quantity=1,TotalPrice=100);
insert(Line);
Product2 prod3 = new Product2();
prod3.Product_Category__c = 'SaaS';
prod3.Family='IAM';
prod3.Product_Sub_Family__c='Orbit Asset';
prod3.Name='Product Test 3';
insert(prod3);
PricebookEntry standardPB3 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod3.Id, UnitPrice = 1000, IsActive = true);
insert standardPB3;
PricebookEntry pb3 = new PricebookEntry(UnitPrice = 10, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod3.Id,isActive = true);
insert(pb3);
OpportunityLineItem Line3 = new OpportunityLineItem(PricebookEntryId=pb3.Id, OpportunityId=testOpp.Id, Quantity=1,TotalPrice=100);
insert(Line3);
Product2 prod4 = new Product2();
prod4.Product_Category__c = 'SaaS';
prod4.Family='Innovation SaaS';
prod4.Product_Sub_Family__c='Orbit Innovation';
prod4.Name='Product Test 3';
insert(prod4);
PricebookEntry standardPB4 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod4.Id, UnitPrice = 1000, IsActive = true);
insert standardPB4;
PricebookEntry pb4 = new PricebookEntry(UnitPrice = 10, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod4.Id,isActive = true);
insert(pb4);
OpportunityLineItem Line6 = new OpportunityLineItem(PricebookEntryId=pb4.Id, OpportunityId=testOpp3.Id, Quantity=1,TotalPrice=100);
insert(Line6);
Product2 prod5 = new Product2();
prod5.Product_Category__c = 'SaaS';
prod5.Family='Innovation SaaS';
prod5.Product_Sub_Family__c='Orbit Idea';
prod5.Name='Product Test 3';
insert(prod5);
PricebookEntry standardPB5 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod5.Id, UnitPrice = 1000, IsActive = true);
insert standardPB5;
PricebookEntry pb5 = new PricebookEntry(UnitPrice = 10, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod5.Id,isActive = true);
insert(pb5);
OpportunityLineItem Line5 = new OpportunityLineItem(PricebookEntryId=pb5.Id, OpportunityId=testOpp2.Id, Quantity=1,TotalPrice=100);
insert(Line5);
Product2 prod7 = new Product2();
prod7.Product_Category__c = 'SaaS';
prod7.Family='Innovation SaaS';
prod7.Product_Sub_Family__c='Orbit Invention';
prod7.Name='Product Test 7';
insert(prod7);
PricebookEntry standardPB7 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod7.Id, UnitPrice = 1000, IsActive = true);
insert standardPB7;
PricebookEntry pb7 = new PricebookEntry(UnitPrice = 10, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod7.Id,isActive = true);
insert(pb7);
OpportunityLineItem Line7 = new OpportunityLineItem(PricebookEntryId=pb7.Id, OpportunityId=testOpp.Id, Quantity=1,TotalPrice=100);
insert(Line7);
Product2 prod8 = new Product2();
prod8.Product_Category__c = 'SaaS';
prod8.Family='IPBI';
prod8.Product_Sub_Family__c='Orbit Express';
prod8.Name='Product Test 8';
insert(prod8);
PricebookEntry standardPB8 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod8.Id, UnitPrice = 1000, IsActive = true);
insert standardPB8;
PricebookEntry pb8 = new PricebookEntry(UnitPrice = 10, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod8.Id,isActive = true);
insert(pb8);
OpportunityLineItem Line8 = new OpportunityLineItem(PricebookEntryId=pb8.Id, OpportunityId=testOpp.Id, Quantity=1,TotalPrice=100);
insert(Line8);
Product2 prod9 = new Product2();
prod9.Product_Category__c = 'SaaS';
prod9.Family='Innovation SaaS';
prod9.Product_Sub_Family__c='Orbit Partnering';
prod9.Name='Product Test 9';
insert(prod9);
PricebookEntry standardPB9 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod9.Id, UnitPrice = 1000, IsActive = true);
insert standardPB9;
PricebookEntry pb9 = new PricebookEntry(UnitPrice = 10, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod9.Id,isActive = true);
insert(pb9);
OpportunityLineItem Line9 = new OpportunityLineItem(PricebookEntryId=pb9.Id, OpportunityId=testOpp.Id, Quantity=1,TotalPrice=100);
insert(Line9);
Product2 prod10 = new Product2();
prod10.Product_Category__c = 'Services';
prod10.Family='Annuity and renewals';
prod10.Product_Sub_Family__c='Annuity/renewals';
prod10.Name='Product Test 10';
insert(prod10);
PricebookEntry standardPB10 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod10.Id, UnitPrice = 1000, IsActive = true);
insert standardPB10;
PricebookEntry pb10 = new PricebookEntry(UnitPrice = 10, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod10.Id,isActive = true);
insert(pb10);
OpportunityLineItem Line10 = new OpportunityLineItem(PricebookEntryId=pb10.Id, OpportunityId=testOpp2.Id, Quantity=1,TotalPrice=100);
insert(Line10);
Product2 prod11 = new Product2();
prod11.Product_Category__c = 'Services';
prod11.Family='Consulting';
prod11.Product_Sub_Family__c='IP operational excellence services Consulting';
prod11.Name='Product Test 11';
insert(prod11);
PricebookEntry standardPB11 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod11.Id, UnitPrice = 1100, IsActive = true);
insert standardPB11;
PricebookEntry pb11 = new PricebookEntry(UnitPrice = 11, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod11.Id,isActive = true);
insert(pb11);
OpportunityLineItem Line11 = new OpportunityLineItem(PricebookEntryId=pb11.Id, OpportunityId=testOpp2.Id, Quantity=1,TotalPrice=110);
insert(Line11);
Product2 prod12 = new Product2();
prod12.Product_Category__c = 'Services';
prod12.Family='Preparation and Prosecution Services';
prod12.Product_Sub_Family__c='Translation';
prod12.Name='Product Test 12';
insert(prod12);
PricebookEntry standardPB12 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod12.Id, UnitPrice = 1100, IsActive = true);
insert standardPB12;
PricebookEntry pb12 = new PricebookEntry(UnitPrice = 11, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod12.Id,isActive = true);
insert(pb12);
OpportunityLineItem Line12 = new OpportunityLineItem(PricebookEntryId=pb12.Id, OpportunityId=testOpp.Id, Quantity=1,TotalPrice=110);
insert(Line12);
Product2 prod13 = new Product2();
prod13.Product_Category__c = 'Services';
prod13.Family='Preparation and Prosecution Services';
prod13.Product_Sub_Family__c='Drafting';
prod13.Name='Product Test 13';
insert(prod13);
PricebookEntry standardPB13 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod13.Id, UnitPrice = 1100, IsActive = true);
insert standardPB13;
PricebookEntry pb13 = new PricebookEntry(UnitPrice = 11, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod13.Id,isActive = true);
insert(pb13);
OpportunityLineItem Line13 = new OpportunityLineItem(PricebookEntryId=pb13.Id, OpportunityId=testOpp.Id, Quantity=1,TotalPrice=110);
insert(Line13);
Product2 prod14 = new Product2();
prod14.Product_Category__c = 'Services';
prod14.Family='Other services';
prod14.Product_Sub_Family__c='Prior-art search';
prod14.Name='Product Test 14';
insert(prod14);
PricebookEntry standardPB14 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod14.Id, UnitPrice = 1100, IsActive = true);
insert standardPB14;
PricebookEntry pb14 = new PricebookEntry(UnitPrice = 11, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod14.Id,isActive = true);
insert(pb14);
OpportunityLineItem Line14 = new OpportunityLineItem(PricebookEntryId=pb14.Id, OpportunityId=testOpp.Id, Quantity=1,TotalPrice=110);
insert(Line14);
Product2 prod15 = new Product2();
prod15.Product_Category__c = 'Services';
prod15.Family='Preparation and Prosecution Services';
prod15.Product_Sub_Family__c='Filing';
prod15.Name='Product Test 15';
insert(prod15);
PricebookEntry standardPB15 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod15.Id, UnitPrice = 1500, IsActive = true);
insert standardPB15;
PricebookEntry pb15 = new PricebookEntry(UnitPrice = 15, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod15.Id,isActive = true);
insert(pb15);
OpportunityLineItem Line15 = new OpportunityLineItem(PricebookEntryId=pb15.Id, OpportunityId=testOpp.Id, Quantity=1,TotalPrice=150);
insert(Line15);
Product2 prod16 = new Product2();
prod16.Product_Category__c = 'Services';
prod16.Family='Preparation and Prosecution Services';
prod16.Product_Sub_Family__c='EP Validation';
prod16.Name='Product Test 16';
insert(prod16);
PricebookEntry standardPB16 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod16.Id, UnitPrice = 2500, IsActive = true);
insert standardPB16;
PricebookEntry pb16 = new PricebookEntry(UnitPrice = 2500, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod16.Id,isActive = true);
insert(pb16);
OpportunityLineItem Line16 = new OpportunityLineItem(PricebookEntryId=pb16.Id, OpportunityId=testOpp.Id, Quantity=1,TotalPrice=2500);
insert(Line16);
Product2 prod17 = new Product2();
prod17.Product_Category__c = 'Services';
prod17.Family='Other services';
prod17.Product_Sub_Family__c='Recordals';
prod17.Name='Product Test 17';
insert(prod17);
PricebookEntry standardPB17 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod17.Id, UnitPrice = 2500, IsActive = true);
insert standardPB17;
PricebookEntry pb17 = new PricebookEntry(UnitPrice = 2500, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod17.Id,isActive = true);
insert(pb17);
OpportunityLineItem Line17 = new OpportunityLineItem(PricebookEntryId=pb17.Id, OpportunityId=testOpp.Id, Quantity=1,TotalPrice=2500);
insert(Line17);
Product2 prod18 = new Product2();
prod18.Product_Category__c = 'Saas';
prod18.Family='IAM';
prod18.Product_Sub_Family__c='Orbit Capture';
prod18.Name='Product Test 18';
insert(prod18);
PricebookEntry standardPB18 = new PricebookEntry(Pricebook2Id = '01s20000000HdFTAA0', Product2Id = prod18.Id, UnitPrice = 2500, IsActive = true);
insert standardPB18;
PricebookEntry pb18 = new PricebookEntry(UnitPrice = 2500, Pricebook2Id = '01sD0000000V1Zk', product2Id = prod18.Id,isActive = true);
insert(pb18);
OpportunityLineItem Line18 = new OpportunityLineItem(PricebookEntryId=pb18.Id, OpportunityId=testOpp.Id, Quantity=1,TotalPrice=2500);
insert(Line18);
Test.StartTest();
ApexPages.StandardController sc = new ApexPages.StandardController(testAccount);
SummaryAccountController testAccPlan = new SummaryAccountController(sc);
PageReference pageRef = Page.Test_Account_Summary; // Add your VF page Name here
pageRef.getParameters().put('id',String.valueOf(testAccount.Id));
Test.setCurrentPage(pageRef);
testAccPlan.createTaskRecord();
testAccPlan.returnToAccount();
testAccPlan.CreateTask();
testAccPlan.newTask();
testAccPlan.returnToPage();
Test.StopTest();
}
This is the part that is not covered
IF (Opwrap.Contract!=null){
If(opline.PricebookEntry.Product2.Product_Sub_Family__c=='Orbit Asset' && indexContractsAsset!= Opwrap.Contract)
{
if(Con.Status =='Activated'){
activeAsset ++;
Opwrap.numberActiveContract = String.valueOf(ActiveAsset) ;
}
if(Con.Status=='Expired')
{
For(Event e : Event_Asset_Card)
If (e.ActivityDate< con.EndDate )
{ShowExpiredContract = True;}
expiredAsset ++;
Opwrap.numberExpiredContract = String.valueOf(expiredAsset) ;
}
ContractsAsset.add(Opwrap);
indexContractsAsset =Opwrap.Contract;
}
If(opline.PricebookEntry.Product2.Product_Sub_Family__c=='Orbit Capture' && indexContractsCapture!= Opwrap.Contract)
{
if(Con.Status =='Activated'){
activeCapture ++;
Opwrap.numberActiveContract = String.valueOf(ActiveCapture) ;
}
if(Con.Status=='Expired')
{
For(Event e : Event_Capture_Card)
If (e.ActivityDate< con.EndDate )
{ShowExpiredContract = True;}
expiredCapture ++;
Opwrap.numberExpiredContract = String.valueOf(expiredCapture) ;
}
ContractsCapture.add(Opwrap);
indexContractsCapture =Opwrap.Contract;
}
If(opline.PricebookEntry.Product2.Product_Sub_Family__c=='Orbit Invention' && indexContractsInvention!= Opwrap.Contract)
{
if(Con.Status =='Activated'){
activeInvention ++;
Opwrap.numberActiveContract = String.valueOf(ActiveInvention) ;
}
if(Con.Status=='Expired')
{
For(Event e : Event_Invention_Card)
If (e.ActivityDate< con.EndDate )
{ShowExpiredContract = True;}
expiredInvention ++;
Opwrap.numberExpiredContract = String.valueOf(expiredInvention) ;
}
ContractsInvention.add(Opwrap);
indexContractsInvention =Opwrap.Contract;
}
If(opline.PricebookEntry.Product2.Product_Sub_Family__c=='Orbit Idea' && indexContractsIdea!=Opwrap.Contract)
{
if(Con.Status =='Activated'){
activeIdea ++;
Opwrap.numberActiveContract = String.valueOf(ActiveIdea) ;
}
ContractsIdea.add(Opwrap);
indexContractsIdea =Opwrap.Contract;
}
if(Con.Status=='Expired')
{
For(Event e : Event_Idea_Card)
If (e.ActivityDate< con.EndDate )
{ShowExpiredContract = True;}
expiredIdea ++;
Opwrap.numberExpiredContract = String.valueOf(expiredIdea) ;
}
If(opline.PricebookEntry.Product2.Product_Sub_Family__c=='Orbit Innovation' && indexContractsInnovation!=Opwrap.Contract)
{
if(Con.Status =='Activated'){
activeInnovation ++;
Opwrap.numberActiveContract = String.valueOf(ActiveInnovation) ;
}
if(Con.Status=='Expired')
{
For(Event e : Event_Innovation_Card)
If (e.ActivityDate< con.EndDate )
{ShowExpiredContract = True;}
expiredInnovation ++;
Opwrap.numberExpiredContract = String.valueOf(expiredInnovation) ;
}
ContractsInnovation.add(Opwrap);
indexContractsInnovation =Opwrap.Contract;
}
If(opline.PricebookEntry.Product2.Product_Sub_Family__c=='Orbit Partnering' && indexContractsPartnering!=Opwrap.Contract)
{
if(Con.Status =='Activated'){
activePartnering ++;
Opwrap.numberActiveContract = String.valueOf(ActivePartnering) ;
}
if(Con.Status=='Expired')
{
For(Event e : Event_Partnering_Card)
If (e.ActivityDate< con.EndDate )
{ShowExpiredContract = True;}
expiredPartnering ++;
Opwrap.numberExpiredContract = String.valueOf(expiredPartnering) ;
}
ContractsPartnering.add(Opwrap);
indexContractsPartnering =Opwrap.Contract;
}
If(opline.PricebookEntry.Product2.Product_Sub_Family__c=='Orbit Intelligence' && indexContractsIntelligence!=Opwrap.Contract)
{
if(Con.Status=='Activated')
{
activeIntelligence ++;
Opwrap.numberActiveContract = String.valueOf(ActiveIntelligence) ;
}
if(Con.Status=='Expired')
{
For(Event e : Event_Intelligence_Card)
If (e.ActivityDate< con.EndDate )
{ShowExpiredContract = True;}
expiredIntelligence ++;
Opwrap.numberExpiredContract = String.valueOf(expiredIntelligence) ;
}
ContractsIntelligence.add(Opwrap);
indexContractsIntelligence =Opwrap.Contract;
}
If(opline.PricebookEntry.Product2.Product_Sub_Family__c=='Orbit Express' && indexContractsExpress!=Opwrap.Contract)
{
if(Con.Status =='Activated'){
activeExpress ++;
Opwrap.numberActiveContract = String.valueOf(ActiveExpress) ;
}
if(Con.Status=='Expired')
{
IF(!Event_Express_Card.isEmpty()) {
For(Event e : Event_Express_Card)
If (e.ActivityDate< con.EndDate )
{ShowExpiredContract = True;} }
expiredExpress ++;
Opwrap.numberExpiredContract = String.valueOf(expiredExpress) ;
}
ContractsExpress.add(Opwrap);
indexContractsExpress =Opwrap.Contract;
}
Thanks
-
- ERP Team
- June 18, 2020
- Like
- 0
Class Test for Custom Controller Extension
I am new to Apex I managed to create a Visualforce Page and a custom controller extension but I am unable to create a Test Class for it
Can anyone help me create the Test class please?
Controller Code :
public class AccountSummaryController {
public List<OppProductWrapper> IAM {get;set;}
public List<OppProductWrapper> IPBI {get;set;}
public List<OppProductWrapper> Consulting {get;set;}
public List<OppProductWrapper> Annuity {get;set;}
public List<OppProductWrapper> Innovation {get;set;}
public List<OppProductWrapper> Other {get;set;}
public List<OppProductWrapper> Preparation {get;set;}
public List<OppProductWrapper> Opswrap {get;set;}
public List<OppProductWrapper> Priorart {get;set;}
public List<OppProductWrapper> ContractsIAM {get;set;}
public List<OppProductWrapper> ContractsIPBI {get;set;}
public List<OppProductWrapper> ContractsInnovation {get;set;}
public Contract Con {get;set;}
public Task NewTask {get;set;}
public Boolean ShowTask {get;set;}
public OppProductWrapper Opwrap {get;set;}
public List<opportunity> opportunities{get;set;}
public List<Task> Task_IAM {get;set;}
public List<Task> Task_IPBI {get;set;}
public List<Task> Task_Annuity {get;set;}
public List<Task> Task_Consulting {get;set;}
public List<Task> Task_Innovation {get;set;}
public List<Task> Task_Other {get;set;}
public List<Task> Task_Preparation {get;set;}
public Account accounts {get;set;}
public Account acc {get;set;}
public AccountSummaryController(ApexPages.StandardController controller) {
acc = (account)controller.getRecord();
accounts = [SELECT id FROM account WHERE id=: acc.id LIMIT 1];
createTaskRecord() ;
showTask = False;
/* Get all the opportunites and their products related to the Account */
opportunities = [SELECT id,Name,NextStep,Existing_Solution_Name__c,Other_Solutions_Evaluated__c, CloseDate,StageName,ContractId,(SELECT Id,PricebookEntry.Product2.Product_Category__c,PricebookEntry.Product2.Product_Sub_Family__c, PricebookEntry.Product2.Family,PricebookEntry.Product2.Name FROM OpportunityLineItems) FROM Opportunity WHERE accountid = :accounts.id AND HasOpportunityLineItem = TRUE ORDER BY CloseDate DESC];
/* Parse all the infos needed in the Opportunity Product Wrapper */
Annuity = new List<OppProductWrapper>();
Innovation = new List<OppProductWrapper>();
Other = new List<OppProductWrapper>();
IPBI = new List<OppProductWrapper>();
Consulting = new List<OppProductWrapper>();
IAM = new List<OppProductWrapper>();
Preparation = new List<OppProductWrapper>();
Priorart = new List<OppProductWrapper>();
ContractsIAM = new List<OppProductWrapper>();
ContractsIPBI = new List<OppProductWrapper>();
ContractsInnovation = new List<OppProductWrapper>();
Task_IAM = [Select Id,Owner.Name,Priority,ActivityDate ,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='IAM' ];
Task_IPBI = [Select Id,Owner.Name,Priority,ActivityDate ,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='IPBI'];
Task_Annuity = [Select Id,Owner.Name,Priority,ActivityDate ,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='Annuity and renewals'];
Task_Innovation = [Select Id,Owner.Name,Priority,ActivityDate ,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='Innovation SaaS'];
Task_Consulting = [Select Id,Owner.Name,Priority,ActivityDate ,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='Consulting'];
Task_Preparation = [Select Id,Owner.Name,Priority,ActivityDate ,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='Preparation and Prosecution Services' ];
Task_Other = [Select Id,Owner.Name,ActivityDate,Priority,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='Other Services' ];
Con = New Contract();
String indexAsset='';
String indexIdea='';
String indexData='';
for (Opportunity opp :opportunities ) {
Integer indexIAM=1;
Integer indexIPBI=1;
Integer indexInnovation=1;
Integer indexAnnuity=1;
Integer indexConsulting=1;
Integer indexPreparation=1;
Integer indexPriorart=1;
Integer indexOther=1;
for (OpportunityLineItem opline: opp.OpportunityLineItems)
{
Opwrap = new OppProductWrapper();
Opwrap.OppId = opp.Id;
if(opp.ContractId!=null){
Opwrap.Contract = opp.ContractId;
Con = [Select Name,StartDate,EndDate,Status from Contract Where Id =: opp.ContractId limit 1];
Opwrap.StartDate = Con.StartDate;
Opwrap.EndDate = Con.EndDate;
Opwrap.ContractStatus = Con.Status;
Opwrap.ContractName = Con.Name;
}
Opwrap.ProductName = opline.PricebookEntry.Product2.Name;
Opwrap.ProductFamily = opline.PricebookEntry.Product2.Family;
Opwrap.ProductSubFamily = opline.PricebookEntry.Product2.Product_Sub_Family__c;
Opwrap.ProductCategory = opline.PricebookEntry.Product2.Product_Category__c;
Opwrap.Stage = opp.StageName;
Opwrap.CloseDate = opp.CloseDate;
Opwrap.Competitor = opp.Other_Solutions_Evaluated__c;
Opwrap.Existing = opp.Existing_Solution_Name__c;
Opwrap.OppName = opp.Name;
Opwrap.NextStep=opp.NextStep;
IF (Opwrap.Contract!=null){
If(opline.PricebookEntry.Product2.Family=='IAM'&& indexAsset!= Opwrap.Contract)
{ ContractsIAM.add(Opwrap);
indexAsset =Opwrap.Contract;
}
If(opline.PricebookEntry.Product2.Family=='IPBI' && indexData!= Opwrap.Contract)
{ ContractsIPBI.add(Opwrap);
indexData =Opwrap.Contract;
}
If(opline.PricebookEntry.Product2.Family=='Innovation SaaS'&& indexIdea!= Opwrap.Contract)
{ ContractsInnovation.add(Opwrap);
indexIdea =Opwrap.Contract;
}
}
Else {
If(opline.PricebookEntry.Product2.Family=='IAM' && indexIAM<2)
{Opwrap.index = indexIAM;
IAM.add(Opwrap);
indexIAM ++;
}
If(opline.PricebookEntry.Product2.Family=='IPBI' && indexIPBI<2)
{
Opwrap.index = indexIPBI;
IPBI.add(Opwrap);
indexIPBI ++;
}
If(opline.PricebookEntry.Product2.Family=='Innovation SaaS' && indexInnovation<2)
{
Opwrap.index=indexInnovation;
Innovation.add(Opwrap);
indexInnovation ++;
}
If(opline.PricebookEntry.Product2.Family=='Annuity and renewals' && indexAnnuity<2)
{
Opwrap.index=indexAnnuity;
Annuity.add(Opwrap);
indexAnnuity ++;
}
If(opline.PricebookEntry.Product2.Family=='Consulting' && indexConsulting<2)
{
Opwrap.index=indexConsulting;
Consulting.add(Opwrap);
indexConsulting ++;
}
If(opline.PricebookEntry.Product2.Product_Sub_Family__c=='Prior-art search' && indexPriorart<2)
{
Opwrap.index= indexPriorart;
Priorart.add(Opwrap);
indexPriorart ++;
}
If(opline.PricebookEntry.Product2.Family=='Other Services' && indexOther<2 && opline.PricebookEntry.Product2.Product_Sub_Family__c!='Prior-art search' ) {
Opwrap.index= indexOther;
Other.add(Opwrap);
indexOther ++;
}
}
}
}
}
public void CreateTask(){
showTask=True;
}
public Pagereference newTask(){
try {
insert NewTask;
}
catch(DMLException e) {
NewTask.addError(e.getMessage());
return null;
}
PageReference pageRef = new PageReference(ApexPages.currentPage().getHeaders().get('referer'));
pageRef.setRedirect(True);
return PageRef;
}
public Pagereference returnToAccount(){
PageReference pageRef = new PageReference('/' + accounts.Id);
pageRef.setRedirect(True);
return PageRef;
}
public void createTaskRecord() {
NewTask = new Task();
NewTask.whatId = accounts.Id;
}
public class OppProductWrapper {
public String OppId {get;set;}
public String ContractName {get;set;}
public String Stage{get;set;}
public Date CloseDate{get;set;}
public String ProductName{get;set;}
public String ProductFamily {get;set;}
public String ProductSubFamily {get;set;}
public String ProductCategory {get;set;}
public String Existing {get;set;}
public String Competitor {get;set;}
public String Contract {get;set;}
public String OppName {get;set;}
public String NextStep {get;set;}
public Date StartDate {get;set;}
public Date EndDate {get;set;}
public String ContractStatus {get;set;}
public Integer index{get;set;}
public OppProductWrapper(){}
}
}
Thanks in Advance,
Hemdène.
-
- ERP Team
- May 08, 2020
- Like
- 0
Pre-populate WhatId in New Task button
I have a Visualforce page on the Account Object
I want to add a button to create a new task for the current account I want to pre-populate the what id field but it's not working
My code :
VF :
<apex:page standardController="Account" extensions="ContactRelatedListController" sidebar="true" showHeader="false" >
<apex:pageblock >
<apex:outputLabel value="{!Account.Name}" styleClass="Account">
</apex:outputLabel>
<apex:commandLink value="New Task" action="{!newTask}" target="_parent" styleClass="btn" style="text-decoration:none;padding:4px;"/></div>
</apex:pageblock>
</apex:page>
Controller :
public class ContactRelatedListController {
public Account accounts {get;set;}
public Account acc {get;set;}
public ContactRelatedListController(ApexPages.StandardController controller) {
acc = (account)controller.getRecord();
accounts = [SELECT id FROM account WHERE id=: acc.id LIMIT 1];
}
public Pagereference newTask(){
PageReference pageRef = new PageReference('/00T/e?&WhatId=' + accounts.Id+'&retURL='+accounts.Id);
pageRef.setRedirect(True);
return PageRef;
}
}
Thanks for your helpHemdene.
-
- ERP Team
- May 05, 2020
- Like
- 0
Class Test for Custom Controller Extension
I am new to Apex I managed to create a Visualforce Page and a custom controller extension but I am unable to create a Test Class for it
Can anyone help me create the Test class please?
Controller Code :
public class AccountSummaryController {
public List<OppProductWrapper> IAM {get;set;}
public List<OppProductWrapper> IPBI {get;set;}
public List<OppProductWrapper> Consulting {get;set;}
public List<OppProductWrapper> Annuity {get;set;}
public List<OppProductWrapper> Innovation {get;set;}
public List<OppProductWrapper> Other {get;set;}
public List<OppProductWrapper> Preparation {get;set;}
public List<OppProductWrapper> Opswrap {get;set;}
public List<OppProductWrapper> Priorart {get;set;}
public List<OppProductWrapper> ContractsIAM {get;set;}
public List<OppProductWrapper> ContractsIPBI {get;set;}
public List<OppProductWrapper> ContractsInnovation {get;set;}
public Contract Con {get;set;}
public Task NewTask {get;set;}
public Boolean ShowTask {get;set;}
public OppProductWrapper Opwrap {get;set;}
public List<opportunity> opportunities{get;set;}
public List<Task> Task_IAM {get;set;}
public List<Task> Task_IPBI {get;set;}
public List<Task> Task_Annuity {get;set;}
public List<Task> Task_Consulting {get;set;}
public List<Task> Task_Innovation {get;set;}
public List<Task> Task_Other {get;set;}
public List<Task> Task_Preparation {get;set;}
public Account accounts {get;set;}
public Account acc {get;set;}
public AccountSummaryController(ApexPages.StandardController controller) {
acc = (account)controller.getRecord();
accounts = [SELECT id FROM account WHERE id=: acc.id LIMIT 1];
createTaskRecord() ;
showTask = False;
/* Get all the opportunites and their products related to the Account */
opportunities = [SELECT id,Name,NextStep,Existing_Solution_Name__c,Other_Solutions_Evaluated__c, CloseDate,StageName,ContractId,(SELECT Id,PricebookEntry.Product2.Product_Category__c,PricebookEntry.Product2.Product_Sub_Family__c, PricebookEntry.Product2.Family,PricebookEntry.Product2.Name FROM OpportunityLineItems) FROM Opportunity WHERE accountid = :accounts.id AND HasOpportunityLineItem = TRUE ORDER BY CloseDate DESC];
/* Parse all the infos needed in the Opportunity Product Wrapper */
Annuity = new List<OppProductWrapper>();
Innovation = new List<OppProductWrapper>();
Other = new List<OppProductWrapper>();
IPBI = new List<OppProductWrapper>();
Consulting = new List<OppProductWrapper>();
IAM = new List<OppProductWrapper>();
Preparation = new List<OppProductWrapper>();
Priorart = new List<OppProductWrapper>();
ContractsIAM = new List<OppProductWrapper>();
ContractsIPBI = new List<OppProductWrapper>();
ContractsInnovation = new List<OppProductWrapper>();
Task_IAM = [Select Id,Owner.Name,Priority,ActivityDate ,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='IAM' ];
Task_IPBI = [Select Id,Owner.Name,Priority,ActivityDate ,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='IPBI'];
Task_Annuity = [Select Id,Owner.Name,Priority,ActivityDate ,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='Annuity and renewals'];
Task_Innovation = [Select Id,Owner.Name,Priority,ActivityDate ,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='Innovation SaaS'];
Task_Consulting = [Select Id,Owner.Name,Priority,ActivityDate ,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='Consulting'];
Task_Preparation = [Select Id,Owner.Name,Priority,ActivityDate ,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='Preparation and Prosecution Services' ];
Task_Other = [Select Id,Owner.Name,ActivityDate,Priority,Subject,Description,Product_Family__c FROM Task where WhatId =: accounts.id and Product_Family__c ='Other Services' ];
Con = New Contract();
String indexAsset='';
String indexIdea='';
String indexData='';
for (Opportunity opp :opportunities ) {
Integer indexIAM=1;
Integer indexIPBI=1;
Integer indexInnovation=1;
Integer indexAnnuity=1;
Integer indexConsulting=1;
Integer indexPreparation=1;
Integer indexPriorart=1;
Integer indexOther=1;
for (OpportunityLineItem opline: opp.OpportunityLineItems)
{
Opwrap = new OppProductWrapper();
Opwrap.OppId = opp.Id;
if(opp.ContractId!=null){
Opwrap.Contract = opp.ContractId;
Con = [Select Name,StartDate,EndDate,Status from Contract Where Id =: opp.ContractId limit 1];
Opwrap.StartDate = Con.StartDate;
Opwrap.EndDate = Con.EndDate;
Opwrap.ContractStatus = Con.Status;
Opwrap.ContractName = Con.Name;
}
Opwrap.ProductName = opline.PricebookEntry.Product2.Name;
Opwrap.ProductFamily = opline.PricebookEntry.Product2.Family;
Opwrap.ProductSubFamily = opline.PricebookEntry.Product2.Product_Sub_Family__c;
Opwrap.ProductCategory = opline.PricebookEntry.Product2.Product_Category__c;
Opwrap.Stage = opp.StageName;
Opwrap.CloseDate = opp.CloseDate;
Opwrap.Competitor = opp.Other_Solutions_Evaluated__c;
Opwrap.Existing = opp.Existing_Solution_Name__c;
Opwrap.OppName = opp.Name;
Opwrap.NextStep=opp.NextStep;
IF (Opwrap.Contract!=null){
If(opline.PricebookEntry.Product2.Family=='IAM'&& indexAsset!= Opwrap.Contract)
{ ContractsIAM.add(Opwrap);
indexAsset =Opwrap.Contract;
}
If(opline.PricebookEntry.Product2.Family=='IPBI' && indexData!= Opwrap.Contract)
{ ContractsIPBI.add(Opwrap);
indexData =Opwrap.Contract;
}
If(opline.PricebookEntry.Product2.Family=='Innovation SaaS'&& indexIdea!= Opwrap.Contract)
{ ContractsInnovation.add(Opwrap);
indexIdea =Opwrap.Contract;
}
}
Else {
If(opline.PricebookEntry.Product2.Family=='IAM' && indexIAM<2)
{Opwrap.index = indexIAM;
IAM.add(Opwrap);
indexIAM ++;
}
If(opline.PricebookEntry.Product2.Family=='IPBI' && indexIPBI<2)
{
Opwrap.index = indexIPBI;
IPBI.add(Opwrap);
indexIPBI ++;
}
If(opline.PricebookEntry.Product2.Family=='Innovation SaaS' && indexInnovation<2)
{
Opwrap.index=indexInnovation;
Innovation.add(Opwrap);
indexInnovation ++;
}
If(opline.PricebookEntry.Product2.Family=='Annuity and renewals' && indexAnnuity<2)
{
Opwrap.index=indexAnnuity;
Annuity.add(Opwrap);
indexAnnuity ++;
}
If(opline.PricebookEntry.Product2.Family=='Consulting' && indexConsulting<2)
{
Opwrap.index=indexConsulting;
Consulting.add(Opwrap);
indexConsulting ++;
}
If(opline.PricebookEntry.Product2.Product_Sub_Family__c=='Prior-art search' && indexPriorart<2)
{
Opwrap.index= indexPriorart;
Priorart.add(Opwrap);
indexPriorart ++;
}
If(opline.PricebookEntry.Product2.Family=='Other Services' && indexOther<2 && opline.PricebookEntry.Product2.Product_Sub_Family__c!='Prior-art search' ) {
Opwrap.index= indexOther;
Other.add(Opwrap);
indexOther ++;
}
}
}
}
}
public void CreateTask(){
showTask=True;
}
public Pagereference newTask(){
try {
insert NewTask;
}
catch(DMLException e) {
NewTask.addError(e.getMessage());
return null;
}
PageReference pageRef = new PageReference(ApexPages.currentPage().getHeaders().get('referer'));
pageRef.setRedirect(True);
return PageRef;
}
public Pagereference returnToAccount(){
PageReference pageRef = new PageReference('/' + accounts.Id);
pageRef.setRedirect(True);
return PageRef;
}
public void createTaskRecord() {
NewTask = new Task();
NewTask.whatId = accounts.Id;
}
public class OppProductWrapper {
public String OppId {get;set;}
public String ContractName {get;set;}
public String Stage{get;set;}
public Date CloseDate{get;set;}
public String ProductName{get;set;}
public String ProductFamily {get;set;}
public String ProductSubFamily {get;set;}
public String ProductCategory {get;set;}
public String Existing {get;set;}
public String Competitor {get;set;}
public String Contract {get;set;}
public String OppName {get;set;}
public String NextStep {get;set;}
public Date StartDate {get;set;}
public Date EndDate {get;set;}
public String ContractStatus {get;set;}
public Integer index{get;set;}
public OppProductWrapper(){}
}
}
Thanks in Advance,
Hemdène.

- ERP Team
- May 08, 2020
- Like
- 0
Pre-populate WhatId in New Task button
I have a Visualforce page on the Account Object
I want to add a button to create a new task for the current account I want to pre-populate the what id field but it's not working
My code :
VF :
<apex:page standardController="Account" extensions="ContactRelatedListController" sidebar="true" showHeader="false" >
<apex:pageblock >
<apex:outputLabel value="{!Account.Name}" styleClass="Account">
</apex:outputLabel>
<apex:commandLink value="New Task" action="{!newTask}" target="_parent" styleClass="btn" style="text-decoration:none;padding:4px;"/></div>
</apex:pageblock>
</apex:page>
Controller :
public class ContactRelatedListController {
public Account accounts {get;set;}
public Account acc {get;set;}
public ContactRelatedListController(ApexPages.StandardController controller) {
acc = (account)controller.getRecord();
accounts = [SELECT id FROM account WHERE id=: acc.id LIMIT 1];
}
public Pagereference newTask(){
PageReference pageRef = new PageReference('/00T/e?&WhatId=' + accounts.Id+'&retURL='+accounts.Id);
pageRef.setRedirect(True);
return PageRef;
}
}
Thanks for your helpHemdene.

- ERP Team
- May 05, 2020
- Like
- 0
Using Apex to count # of characters in a long text field
I have a business requirement to build a formula that calculate how complete the data is on a custom record and then return a corresponding image (green, yellow, red traffic lights).
As part of this requirement I need to count the # of characters in a long text field. Unfortunately, long text fields can not be used as part of a Formula, otherwise I would use len(long_text_field__c) < 100 as part of my equation.
Plan B is to use a trigger to count the # of characters in the long_text_field__c and insert into count_of_long_text_field__c. Only one issue here - apex is a mystery to me.
While I am not a programmer, I attempted to find some javascript code online and change it to work in a trigger. I didn't find anything simple enough that will allow me to make an honest attempt at buildling my first trigger.
Can someone help me get started here?

- Brian12345
- May 20, 2009
- Like
- 0