-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
6Questions
-
10Replies
- bittu myana
- September 12, 2017
- Like
- 0
- Continue reading or reply
How to write test class with asserts for the below code
public class OpportunityProductsFieldSetsCTRL {
Public Integer size{get;set;}
public product2 productSearch {set;get;}
public List<OppLinItemWrapper> OppLinItemWrapper;
public OpportunityLineItem lineItems{set;get;}
Public Integer index{get;set;}
public list<ProductwrapClass> ProductList ;
public boolean issampleListNull {get;set;}
Public Integer noOfRecords{get; set;}
//public String SearchProductCode{get;set;}
public Product2 product {get;set;}
public list<ProductwrapClass> selectedList{get; set;}
public string Query;
Public string OldQuery;
public boolean IsAdding {get;set;}
public list<OppLinItemWrapper> OpplineList{get;set;}
public string opportunityId;
//String whereClause;
public List<SelectOption> getPaginationSizeOptions()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('10','10'));
options.add(new SelectOption('25','25'));
options.add(new SelectOption('50','50'));
options.add(new SelectOption('100','100'));
return options;
}
//string opportunityId;
//Constarctor
public OpportunityProductsFieldSetsCTRL(ApexPages.StandardController controller){
productSearch=new product2();
lineItems = new OpportunityLineItem();
IsAdding=false;
opportunityId=ApexPages.currentPage().getParameters().get('id');
product = new Product2();
opportunityId=ApexPages.currentPage().getParameters().get('id');
ProductList = new list<ProductwrapClass>();
selectedList= new list<ProductwrapClass>();
if(index == null){
index = 10;
setCon.setPageSize(10);
}
}
//Standard set controller
public ApexPages.StandardSetController setCon {
get {
ProductList.clear();
if(setCon == null||OldQuery != Query) {
if(Query == null || Query == '') {
Query = 'select id';
for(Schema.FieldSetMember fld :SObjectType.Product2.FieldSets.Product_Field_Set1.getFields()) {
Query += ', ' + fld.getFieldPath();
}
query += ' FROM Product2 ';
}
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(Query));
//System.debug('Query'+Query);
noOfRecords = setCon.getResultSize();
OldQuery = query;
if(size != null){
setCon.setPageSize(size);
}
}
noOfRecords = setCon.getResultSize();
System.debug('setCon.getResultSize()'+setCon.getResultSize());
return setCon;
}
set;
}
public void SearchProduct(){
System.debug('Page size in fun'+size);
Query = 'select id';
for(Schema.FieldSetMember fld :SObjectType.Product2.FieldSets.Product_Field_Set1.getFields()) {
Query += ', ' + fld.getFieldPath();
}
query=query+' from Product2';
String whereClause=' where IsActive=true';
for(Schema.FieldSetMember fldset :SObjectType.Product2.FieldSets.Search_Field_Set.getFields())
{
if((String)productSearch.get(fldset.getFieldPath())!=null)
{
whereClause=whereclause+' and '+fldset.getFieldPath()+' Like \'%'+(string)productSearch.get(fldset.getFieldPath())+'%\' ';
}
}
query=query+whereClause;
System.debug('%%%%'+query);
//system.debug('query --'+query);
//setCon=Database.getQueryLocator(query);
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(Query));
//System.debug('setCon-------'+setCon.getResultSize());
index=size;
if(size!=null)
setCon.setPageSize(size);
}
public PageReference refreshPageSize() {
if(size != null){
index = size;
setCon.setPageSize(size);
}
return null;
}
public list<ProductwrapClass> getProductList() {
System.debug('start ---');
issampleListNull = false;
for (Product2 a : (list<Product2>)setCon.getRecords()) {
ProductList.add(new ProductwrapClass(a,issampleListNull));
}
if(ProductList.size() == 0) {
issampleListNull = true;
}
System.debug('ProductList '+ProductList.size());
return ProductList ;
}
list<Product2> listOfSelectedProducts=new list<Product2>();
public void selectedProducts(){
for(ProductwrapClass p : ProductList ){
if(p.aCheckBox == true) {
selectedList.add(p);
listOfSelectedProducts.add(p.aProduct);
IsAdding =true;
}
}
}
list<OppLinItemWrapper> listOfLineItems=new list<OppLinItemWrapper>();
public List<OppLinItemWrapper> getOppLinItemWrapper (){
OpplineList=new list<OppLinItemWrapper>();
listOfLineItems.clear();
for(Product2 p1:listOfSelectedProducts){
OpportunityLineItem opportunityLine=new OpportunityLineItem();
PricebookEntry pbEntry = [select id,UnitPrice from PricebookEntry where Product2Id=:p1.Id limit 1];
opportunityLine.PricebookEntryId=pbEntry.Id;
opportunityLine.UnitPrice=pbEntry.UnitPrice;
opportunityLine.OpportunityId=opportunityId;
listOfLineItems.add(new OppLinItemWrapper(p1,opportunityLine));
}
return listOfLineItems;
}
//Wrapper Class
public class ProductwrapClass {
public Boolean aCheckBox {get;set;}
public Product2 aProduct {get;set;}
public ProductwrapClass(Product2 a, Boolean chk){
aProduct = a;
aCheckBox = chk;
}
}
public PageReference onCancel(){
// If user hits cancel we commit no changes and return them to the Opportunity
return new PageReference('/' + ApexPages.currentPage().getParameters().get('Id'));
}
/*
public PageReference onSave(){
list<OpportunityLineItem> opplinesToInsert=new List<OpportunityLineItem>();
System.debug('Saveeeeeeee');
opplinesToInsert.clear();
System.debug('listOfLineItems--------'+listOfLineItems.size());
for(OppLinItemWrapper lineItemWrap:listOfLineItems){
if(lineItemWrap.oppLineItem.Quantity!=null)
opplinesToInsert.add(lineItemWrap.oppLineItem);
system.debug('lineItemWrap::'+lineItemWrap.oppLineItem);
}
if(opplinesToInsert.size()!=null){
try{
insert opplinesToInsert;
}
catch(Exception e){
System.debug('ERROR:' + e);
}
}
return new PageReference('/' + ApexPages.currentPage().getParameters().get('Id'));
}
}
public class OppLinItemWrapper {
public product2 productVar{get;set;}
public OpportunityLineItem oppLineItem{get;set;}
// sub-class initialization
public OppLinItemWrapper(product2 p,OpportunityLineItem o){
productVar=p;
oppLineItem=o;
}
}
- bittu myana
- May 05, 2017
- Like
- 0
- Continue reading or reply
Can you please explain how to solve the fallowing
a VF page that should fulfill the below functionalities. – Suman M
a. By defaults Products should display 25 records.
b. Should have good align and Pagination
c. Should have filter fields that should be configurable through FieldSets, Like if I add Name and Active fields on fieldsets that should display on VF page and If I add/remove that should be reflect on page including filter criteria.
d. The pageblocktable columns should be configurable through FieldsSets like if I add Name, Active, Description, Product Family, Product Type on FiledSets then that should reflect on VF page.
e. Add button functionality of Search.
f. Add custom links of Next, Prev, First and Last.
a. By defaults Products should display 25 records.
b. Should have good align and Pagination
c. Should have filter fields that should be configurable through FieldSets, Like if I add Name and Active fields on fieldsets that should display on VF page and If I add/remove that should be reflect on page including filter criteria.
d. The pageblocktable columns should be configurable through FieldsSets like if I add Name, Active, Description, Product Family, Product Type on FiledSets then that should reflect on VF page.
e. Add button functionality of Search.
f. Add custom links of Next, Prev, First and Last.
- bittu myana
- April 10, 2017
- Like
- 0
- Continue reading or reply
How to write test class with asserts for the below code
public class OpportunityProductsFieldSetsCTRL {
Public Integer size{get;set;}
public product2 productSearch {set;get;}
public List<OppLinItemWrapper> OppLinItemWrapper;
public OpportunityLineItem lineItems{set;get;}
Public Integer index{get;set;}
public list<ProductwrapClass> ProductList ;
public boolean issampleListNull {get;set;}
Public Integer noOfRecords{get; set;}
//public String SearchProductCode{get;set;}
public Product2 product {get;set;}
public list<ProductwrapClass> selectedList{get; set;}
public string Query;
Public string OldQuery;
public boolean IsAdding {get;set;}
public list<OppLinItemWrapper> OpplineList{get;set;}
public string opportunityId;
//String whereClause;
public List<SelectOption> getPaginationSizeOptions()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('10','10'));
options.add(new SelectOption('25','25'));
options.add(new SelectOption('50','50'));
options.add(new SelectOption('100','100'));
return options;
}
//string opportunityId;
//Constarctor
public OpportunityProductsFieldSetsCTRL(ApexPages.StandardController controller){
productSearch=new product2();
lineItems = new OpportunityLineItem();
IsAdding=false;
opportunityId=ApexPages.currentPage().getParameters().get('id');
product = new Product2();
opportunityId=ApexPages.currentPage().getParameters().get('id');
ProductList = new list<ProductwrapClass>();
selectedList= new list<ProductwrapClass>();
if(index == null){
index = 10;
setCon.setPageSize(10);
}
}
//Standard set controller
public ApexPages.StandardSetController setCon {
get {
ProductList.clear();
if(setCon == null||OldQuery != Query) {
if(Query == null || Query == '') {
Query = 'select id';
for(Schema.FieldSetMember fld :SObjectType.Product2.FieldSets.Product_Field_Set1.getFields()) {
Query += ', ' + fld.getFieldPath();
}
query += ' FROM Product2 ';
}
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(Query));
//System.debug('Query'+Query);
noOfRecords = setCon.getResultSize();
OldQuery = query;
if(size != null){
setCon.setPageSize(size);
}
}
noOfRecords = setCon.getResultSize();
System.debug('setCon.getResultSize()'+setCon.getResultSize());
return setCon;
}
set;
}
public void SearchProduct(){
System.debug('Page size in fun'+size);
Query = 'select id';
for(Schema.FieldSetMember fld :SObjectType.Product2.FieldSets.Product_Field_Set1.getFields()) {
Query += ', ' + fld.getFieldPath();
}
query=query+' from Product2';
String whereClause=' where IsActive=true';
for(Schema.FieldSetMember fldset :SObjectType.Product2.FieldSets.Search_Field_Set.getFields())
{
if((String)productSearch.get(fldset.getFieldPath())!=null)
{
whereClause=whereclause+' and '+fldset.getFieldPath()+' Like \'%'+(string)productSearch.get(fldset.getFieldPath())+'%\' ';
}
}
query=query+whereClause;
System.debug('%%%%'+query);
//system.debug('query --'+query);
//setCon=Database.getQueryLocator(query);
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(Query));
//System.debug('setCon-------'+setCon.getResultSize());
index=size;
if(size!=null)
setCon.setPageSize(size);
}
public PageReference refreshPageSize() {
if(size != null){
index = size;
setCon.setPageSize(size);
}
return null;
}
public list<ProductwrapClass> getProductList() {
System.debug('start ---');
issampleListNull = false;
for (Product2 a : (list<Product2>)setCon.getRecords()) {
ProductList.add(new ProductwrapClass(a,issampleListNull));
}
if(ProductList.size() == 0) {
issampleListNull = true;
}
System.debug('ProductList '+ProductList.size());
return ProductList ;
}
list<Product2> listOfSelectedProducts=new list<Product2>();
public void selectedProducts(){
for(ProductwrapClass p : ProductList ){
if(p.aCheckBox == true) {
selectedList.add(p);
listOfSelectedProducts.add(p.aProduct);
IsAdding =true;
}
}
}
list<OppLinItemWrapper> listOfLineItems=new list<OppLinItemWrapper>();
public List<OppLinItemWrapper> getOppLinItemWrapper (){
OpplineList=new list<OppLinItemWrapper>();
listOfLineItems.clear();
for(Product2 p1:listOfSelectedProducts){
OpportunityLineItem opportunityLine=new OpportunityLineItem();
PricebookEntry pbEntry = [select id,UnitPrice from PricebookEntry where Product2Id=:p1.Id limit 1];
opportunityLine.PricebookEntryId=pbEntry.Id;
opportunityLine.UnitPrice=pbEntry.UnitPrice;
opportunityLine.OpportunityId=opportunityId;
listOfLineItems.add(new OppLinItemWrapper(p1,opportunityLine));
}
return listOfLineItems;
}
//Wrapper Class
public class ProductwrapClass {
public Boolean aCheckBox {get;set;}
public Product2 aProduct {get;set;}
public ProductwrapClass(Product2 a, Boolean chk){
aProduct = a;
aCheckBox = chk;
}
}
public PageReference onCancel(){
// If user hits cancel we commit no changes and return them to the Opportunity
return new PageReference('/' + ApexPages.currentPage().getParameters().get('Id'));
}
/*
public PageReference onSave(){
list<OpportunityLineItem> opplinesToInsert=new List<OpportunityLineItem>();
System.debug('Saveeeeeeee');
opplinesToInsert.clear();
System.debug('listOfLineItems--------'+listOfLineItems.size());
for(OppLinItemWrapper lineItemWrap:listOfLineItems){
if(lineItemWrap.oppLineItem.Quantity!=null)
opplinesToInsert.add(lineItemWrap.oppLineItem);
system.debug('lineItemWrap::'+lineItemWrap.oppLineItem);
}
if(opplinesToInsert.size()!=null){
try{
insert opplinesToInsert;
}
catch(Exception e){
System.debug('ERROR:' + e);
}
}
return new PageReference('/' + ApexPages.currentPage().getParameters().get('Id'));
}
}
public class OppLinItemWrapper {
public product2 productVar{get;set;}
public OpportunityLineItem oppLineItem{get;set;}
// sub-class initialization
public OppLinItemWrapper(product2 p,OpportunityLineItem o){
productVar=p;
oppLineItem=o;
}
}
- bittu myana
- May 05, 2017
- Like
- 0
- Continue reading or reply
Need to access Campaign Influence related list records in Opportunity by SOQL
Hello,
I have a requirement where I need to access Campaign Influence records in the Opportunity related list by SOQL query. Basically, I need to access it because I have custom object looking up to CAMPAIGN. And I want to show all opportunities in that custom object related list "Opportunities" upon on adding the Campaign in the custom object.
Thanks,
GR
I have a requirement where I need to access Campaign Influence records in the Opportunity related list by SOQL query. Basically, I need to access it because I have custom object looking up to CAMPAIGN. And I want to show all opportunities in that custom object related list "Opportunities" upon on adding the Campaign in the custom object.
Thanks,
GR
- Jay reddy
- March 08, 2017
- Like
- 1
- Continue reading or reply
Steps to create test class in trigger
Hi,
I have a trigger and a helper class created need a suggestion on how to create a test class for below
Helper Class
Recurssive class
Thanks
Sudhir
I have a trigger and a helper class created need a suggestion on how to create a test class for below
trigger RenwalQuote on QuoteLineItem (After Insert, After Update, Before Delete) { public static Boolean bool = true; Set<Id> setid = new Set<id>(); List<QuoteLineItem> listoli = new List<QuoteLineItem> (); List< OpportunitylineItem> lisopt = new List< OpportunitylineItem > (); List< OpportunitylineItem> Dellisopt = new List< OpportunitylineItem > (); set<id> setoppid = new set<id>(); set<string> setprodcode = new set<string>(); set<string> setrecordtype = new set<string>(); Set<Id> setoldid = new Set<id>(); if(trigger.isafter){ If(preventRecursive.runOnce)return; if(bool){ bool = false; for (QuoteLineItem qtl : Trigger.new){ setid.add(qtl.id); } } List<QuoteLineItem> listem = [Select id,quoteid,Prior_Discount__c,product2.productcode,quote.opportunityid, quote.opportunity.recordtype.name from QuoteLineItem where id In : Setid]; for(QuoteLineItem qlt:listem){ if ( qlt.quote.opportunity.recordtype.name == 'Renewal Opportunity'){ qlt.Prior_Discount__c = RenewalUtils.OppLineDisc(qlt.quote.opportunityid,qlt.quoteid,qlt.product2.productcode); qlt.Opportunity_Line_Item_ID__c = RenewalUtils.OppLineID(qlt.quote.opportunityid,qlt.quoteid,qlt.product2.productcode); system.debug('Quote ID' + qlt.quoteid); system.debug('qlt.product2.productcode' + qlt.product2.productcode); system.debug('Discount Value' + RenewalUtils.OppLineDisc(qlt.quote.opportunityid,qlt.quoteid,qlt.product2.productcode)); listoli.add(qlt); setoppid.add(qlt.quote.opportunityid); setprodcode.add(qlt.product2.productcode); } } if (!listoli.isEmpty()){ preventRecursive.runOnce = true; update listoli; Opportunity Opp = [select id, Prior_Year_Opportunity__c from Opportunity where id = :setoppid]; List<OpportunityLineItem> PrilisOpp = [select id, Renewed__c, opportunity.Prior_Year_Opportunity__c from OpportunityLineItem where opportunityid = :Opp.Prior_Year_Opportunity__c and product2.productcode = :setprodcode ]; for(OpportunitylineItem Opln : PrilisOpp){ Opln.Renewed__c = true; lisopt.add(Opln); } if (!lisopt.isEmpty()){ update lisopt; } } } if(Trigger.isbefore){ for (QuoteLineItem qtl : Trigger.old){ setoldid.add(qtl.id); } QuoteLineItem oldQli = [select id, Opportunity_Line_Item_ID__c from QuoteLineItem where id = :setoldid]; List<OpportunityLineItem> LstOppline = [select id, Renewed__c from OpportunityLineItem where id = : oldQli.Opportunity_Line_Item_ID__c]; for(OpportunitylineItem DOpln : LstOppline){ DOpln.Renewed__c = false; Dellisopt.add(DOpln); } if (! Dellisopt.isEmpty()){ update Dellisopt; } } }
Helper Class
public with sharing class RenewalUtils { public static String OppLineDisc(String QOppID, String Quoteid, String ProdCode) { Decimal Disctot; Opportunity ropp = [select Prior_Year_Opportunity__c from opportunity where id = :QOppID and recordtype.name = 'Renewal Opportunity']; List<AggregateResult> Opplst = [select avg(Discount_Percent__c) totdisc from OpportunityLineItem where Opportunityid = :ropp.Prior_Year_Opportunity__c and product2.productcode = :ProdCode ]; for (AggregateResult arOpplst : Opplst) { Disctot = ((Decimal)arOpplst.get('totdisc')); } system.debug(Disctot); return string.valueof(Disctot); } public static String OppLineID(String QOppID, String Quoteid, String ProdCode) { Opportunity ropp = [select Prior_Year_Opportunity__c from opportunity where id = :QOppID and recordtype.name = 'Renewal Opportunity']; OpportunityLineItem Opplst = [select id from OpportunityLineItem where Opportunityid = :ropp.Prior_Year_Opportunity__c and product2.productcode = :ProdCode limit 1 ]; system.debug(Opplst.id); return string.valueof(Opplst.id); } }
Recurssive class
public class preventRecursive{ public static Boolean runOnce = false; }
Thanks
Sudhir
- GMASJ
- February 28, 2017
- Like
- 1
- Continue reading or reply