-
ChatterFeed
-
0Best Answers
-
1Likes Received
-
0Likes Given
-
16Questions
-
9Replies
how to call the list as a parameter in method in test class?
i have created two classes.one is main class and sub class
sub class:
global class Rfleet_AdvensysResponseSchema_CLS {
global class VIN {
webservice string vin;
webservice string flockcom;
webservice string immat;
webservice string order;
webservice string keycode1;
webservice string energie;
webservice string co2;
webservice string carradiocode;
}
}
Main class:
public static Date getMUTypeMaxDate(list<Rfleet_AdvensysResponseSchema_CLS.VIN> VinObject) {
List<String> lstVinMax = new List<String>();
for(Rfleet_AdvensysResponseSchema_CLS.VIN MuMaxDate:VinObject){
system.debug('### inside vins'+MuMaxDate.vin);
lstVinMax.add(MuMaxDate.vin);
}
}
test class:I am calling the method with parameters but how to initiate the data into this list in test class
List<Rfleet_AdvensysResponseSchema_CLS.VIN> lstVin=new List<Rfleet_AdvensysResponseSchema_CLS.VIN>();
Rfleet_AdvensysMappingDetails_CLS.getMUTypeMaxDate(lstVin);
but i got error.how to resolve this.please anybody help me
sub class:
global class Rfleet_AdvensysResponseSchema_CLS {
global class VIN {
webservice string vin;
webservice string flockcom;
webservice string immat;
webservice string order;
webservice string keycode1;
webservice string energie;
webservice string co2;
webservice string carradiocode;
}
}
Main class:
public static Date getMUTypeMaxDate(list<Rfleet_AdvensysResponseSchema_CLS.VIN> VinObject) {
List<String> lstVinMax = new List<String>();
for(Rfleet_AdvensysResponseSchema_CLS.VIN MuMaxDate:VinObject){
system.debug('### inside vins'+MuMaxDate.vin);
lstVinMax.add(MuMaxDate.vin);
}
}
test class:I am calling the method with parameters but how to initiate the data into this list in test class
List<Rfleet_AdvensysResponseSchema_CLS.VIN> lstVin=new List<Rfleet_AdvensysResponseSchema_CLS.VIN>();
Rfleet_AdvensysMappingDetails_CLS.getMUTypeMaxDate(lstVin);
but i got error.how to resolve this.please anybody help me
- kiran k 12
- December 01, 2016
- Like
- 0
How to avoid soql query inside for loop in apex?
I have written a trigger is workin fine for small size number of records.but during bulk processing records is not working.i know the problem is soql is placed inside for loop because hitting the governor limits.how to resolve this issue?
here my code is ::
here my code is ::
public static void setAccountingLookup(List<SRV_Service__c> newServices,Map<Id,SRV_Service__c> mservices) { string strCustclassification; // to store the customer classification values string strProdclassification;// to store product classification values string strAcccustclassification; // to store accounting customer classification values string strAccprodclassification; // to store accounting product classification values string strServiceId; // to store the serviceid List<SRV_Service__c>lstservices = new List<SRV_Service__c>(); List<SRV_Service__c> lstservicesUpdate =new List<SRV_Service__c>(); List<ACT_Accounting__c> lstaccounting = new List<ACT_Accounting__c>(); List<SRV_Service__c>lstservices1 = new List<SRV_Service__c>(); lstservicesUpdate =[select Id,ServiceType__c,SimpleProduct__r.ProductTax__c,Accounting__c,CarSet__r.Order__r.Account.CustomerVATType__c,CarSet__r.Order__r.Account.RecordType.Name,CBServicesRepository__r.ProductClassification__c from SRV_Service__c where id =:mservices.keySet()]; system.debug('## lstservicesUpdate is..::'+ lstservicesUpdate); SRV_Service__c service = new SRV_Service__c(); for(SRV_Service__c serviceObj : lstservicesUpdate ){ service=serviceObj; if(service.ServiceType__c == Label.SRV_lblOption){ //custclass to store the customer classification values from account object strCustclassification = service.CarSet__r.Order__r.Account.CustomerVATType__c; //prodclass to store the product classification values dynamically set the value strProdclassification = Label.OPT_lblProdclassvalue; }else if(service.ServiceType__c == Label.SRV_lblCoachBuildertype){ //custclass to store the customer classification values from account object strCustclassification = service.CarSet__r.Order__r.Account.CustomerVATType__c; //prodclass to store the product classification values from CBService repostory object strProdclassification =service.CBServicesRepository__r.ProductClassification__c; }else if(service.ServiceType__c == Label.SRV_lblsimpleproduct){ //custclass to store the customer classification values from account object strCustclassification = service.CarSet__r.Order__r.Account.CustomerVATType__c; //prodclass to store the product classification values from simple product object strProdclassification = service.SimpleProduct__r.ProductTax__c; } system.debug('## prodclass is..::'+ strProdclassification); lstaccounting = [select id,CustomerTax__c,ProductTax__c from ACT_Accounting__c where CustomerTax__c=:strCustclassification AND ProductTax__c =:strProdclassification LIMIT 1]; if(!lstaccounting.isEmpty()){ service.Accounting__c= lstaccounting[0].Id; system.debug('&&&&&&&&&&&&&&&'+service.Accounting__c); } } try { system.debug('## lstservicesUpdate is..::'+ service); update service; }catch (Exception ex) { system.debug('## Exception occured while updating Service Object:: ##'+ ex); } } //end of method }
- kiran k 12
- August 07, 2016
- Like
- 0
How to cover the formulae field in test class?
I have written a test class for trigger.the formulae fields is there in if condition.the problem is "Opsconca__c "formulae field in Opportunity_car_set__c.the Opsconca__c = Opsconca__c = (Model__r.Name) & (Rfleet_Country_Code__c) & TEXT(Opportunity__r.Total_Fleet_Size__c) ,the Rfleet_Country_Code__c is formulae field in Account object,the Total_Fleet_Size__c is formulae field in opportunity object related to account formulae field.how to cover the formulae field in IF condition of test class?
Test class: @isTest public class Rfleet_CheckDiscount_Test { static testMethod void Discountceck(){ Account acc = new Account(Name='something',Montant__c=0.2); acc.Fleet_Size_Cars__c = 10; acc.Fleet_Size_LCV__c = 10; acc.RecordTypeId = '012m00000000QSU'; insert acc; acc.Name = 'something2'; update acc; Opportunity opp = new Opportunity(); opp.Name = 'restful'; opp.StageName = 'Draft'; opp.CloseDate = system.today(); opp.AccountId = acc.Id; //opp.Total_Fleet_Size__c = 20; insert opp; opp.Name = 'restfulll'; update opp; Product2 pro = new Product2(); pro.Name = 'Kiran prod1'; pro.Country_code__c = 'DZ'; pro.Brand__c = 'Dacia'; pro.IsActive = true; pro.Family = 'X44'; insert pro; Opportunity_car_set__c ocs = new Opportunity_car_set__c(); ocs.Name = 'Discount Test12'; ocs.Model__c = pro.id; //ocs.Rfleet_Country_Code__c ='DZ'; ocs.Opportunity__c = opp.id; ocs.Discount__c = 11; ocs.Quantity__c = 4; insert ocs; Discount_Grid__c dgc = new Discount_Grid__c(); dgc.Rfleet_Country_Code__c = 'DZ'; dgc.Rfleet_AOC_Model_Code__c = pro.id; dgc.Rfleet_Threshold_Max__c = 10; dgc.Rfleet_Discount__c = 10; insert dgc; Rfleet_CheckDiscount.CheckDiscountobject(); } static testMethod void Discountceck1(){ Account acc = new Account(Name='something',Montant__c=0.2); acc.Fleet_Size_Cars__c = 10; acc.Fleet_Size_LCV__c = 10; acc.RecordTypeId = '012m00000000QSU'; insert acc; acc.Name = 'something2'; update acc; Opportunity opp = new Opportunity(); opp.Name = 'restful'; opp.StageName = 'Draft'; opp.CloseDate = system.today(); opp.AccountId = acc.Id; //opp.Total_Fleet_Size__c = 20; insert opp; opp.Name = 'restfulll'; update opp; Product2 pro = new Product2(); pro.Name = 'Kiran prod1'; pro.Country_code__c = 'DZ'; pro.Brand__c = 'Dacia'; pro.IsActive = true; pro.Family = 'X44'; insert pro; Opportunity_car_set__c ocs = new Opportunity_car_set__c(); ocs.Name = 'Discount Test12'; ocs.Model__c = pro.id; //ocs.Rfleet_Country_Code__c ='DZ'; ocs.Opportunity__c = opp.id; ocs.Discount__c = 10; ocs.Quantity__c = 4; insert ocs; Discount_Grid__c dgc = new Discount_Grid__c(); dgc.Rfleet_Country_Code__c = 'DZ'; dgc.Rfleet_AOC_Model_Code__c = pro.id; dgc.Rfleet_Threshold_Max__c = 10; dgc.Rfleet_Discount__c = 20; insert dgc; Rfleet_CheckDiscount.CheckDiscountobject(); } }
Trigger: global with sharing class Rfleet_CheckDiscount{ webservice static void CheckDiscountobject() { list<Opportunity_car_set__c>lsupdateKo=new list<Opportunity_car_set__c>(); list<Opportunity>lsupdatoppko=new list<Opportunity>(); list<Discount_Grid__c> listDisGrid=[select Rfleet_Status__c,Rfleet_Discountconca__c,Rfleet_Discount__c from Discount_Grid__c where SystemModstamp =LAST_N_DAYS:31 and Rfleet_Status__c = 'Enabled' Limit 50000]; system.debug('Discount_Grid list:::'+listDisGrid); list<Opportunity> lsoppty=[Select StageName,name,Rfleet_Granted_discount_KO__c,RFLEET_Status__c, Id,(Select id,Opsconca__c,Rfleet_Granted_discount_KO__c,Discount__c From Opportunity_car_sets__r) From Opportunity where StageName IN('Draft','Internal Approbation')order by SystemModstamp desc limit 100]; system.debug('Opportunity list:::'+lsoppty); for(Opportunity opp:lsoppty){ for(Opportunity_car_set__c ocs:opp.Opportunity_car_sets__r){ for(Discount_Grid__c disGrid:listDisGrid){ system.debug('dis con:::'+disGrid.Rfleet_Discountconca__c); system.debug('Opportunity OCS con:::'+ocs.Opsconca__c); if(disGrid.Rfleet_Discountconca__c==ocs.Opsconca__c) { system.debug(' OCS con:::'+ocs.Discount__c); system.debug('Discount grid con:::'+disGrid.Rfleet_Discount__c); if(ocs.Discount__c>disGrid.Rfleet_Discount__c){ ocs.Rfleet_Granted_discount_KO__c = true; opp.Rfleet_Granted_discount_KO__c = true; lsupdateKo.add(ocs); lsupdatoppko.add(opp); }else{ ocs.Rfleet_Granted_discount_KO__c = false; opp.Rfleet_Granted_discount_KO__c = false; lsupdateKo.add(ocs); lsupdatoppko.add(opp); } } } } } update lsupdateKo; update lsupdatoppko; } }
- kiran k 12
- February 11, 2016
- Like
- 0
How can i move the trigger to apex class?
How can i move the trigger to apex class?
Trigger: trigger validDiscountpercent on Opportunity_car_set__c (before insert,before update) { decimal d; set<id>oppids=new set<id>(); string conca; list<Opportunity> lsupdateopp=new list<Opportunity>(); for(Opportunity_car_set__c oppcarset:[select Model__r.Name, Discount__c,Opportunity__r.Total_Fleet_Size__c,Model__c,Rfleet_Country_Code__c,CreatedDate from Opportunity_car_set__c where id in:trigger.new]){ integer dt=oppcarset.CreatedDate.Year(); conca = oppcarset.Model__r.Name +oppcarset.Rfleet_Country_Code__c + string.valueof(oppcarset.Opportunity__r.Total_Fleet_Size__c)+string.valueof(dt); system.debug('conca----->'+conca); } list<Discount_Grid__c> listDisGrid=[select Rfleet_Status__c,Rfleet_Discountconca__c,Rfleet_Discount__c from Discount_Grid__c where Rfleet_Status__c = 'Enabled' Limit 1]; system.debug('>>>>>>>>>>>>>>:'+listDisGrid); for(Discount_Grid__c disGrid:listDisGrid){ for(Opportunity_car_set__c opp:trigger.new){ if(opp.Discount__c >disGrid.Rfleet_Discount__c){ opp.Rfleet_Granted_discount_KO__c = true; oppids.add(opp.Opportunity__c); }else{ opp.Rfleet_Granted_discount_KO__c = false; oppids.add(opp.Opportunity__c); } } } list<Opportunity>opplistupdate=[select Rfleet_Granted_discount_KO__c from Opportunity where id=:oppids]; system.debug('>>>>>>>>>>>>>>:'+opplistupdate); for(Opportunity_car_set__c oppCar:trigger.new){ for(Opportunity updateopp:opplistupdate){ if(oppCar.Rfleet_Granted_discount_KO__c==true && opplistupdate.size()>0){ updateopp.Rfleet_Granted_discount_KO__c =true; lsupdateopp.add(updateopp); }else if(oppCar.Rfleet_Granted_discount_KO__c==false && opplistupdate.size()>0){ updateopp.Rfleet_Granted_discount_KO__c =false; lsupdateopp.add(updateopp); } } update lsupdateopp; } } apex class for trigger: global class MyClass { decimal d; set<id>oppids=new set<id>(); string conca; webservice static void myMethod() { for(Opportunity opp :[select Stage,Rfleet_Granted_discount_KO__c from opportunity where Stage='Draft'] ){ for(Opportunity_car_set__c ocs:[select Model__r.Name, Discount__c,Opportunity__r.Total_Fleet_Size__c,Model__c,Rfleet_Country_Code__c,CreatedDate from Opportunity_car_set__c ]){ for(Discount_Grid__c disGrid:[select Rfleet_Status__c,Rfleet_Discountconca__c,Rfleet_Discount__c from Discount_Grid__c where Rfleet_Status__c = 'Enabled' Limit 1]){ integer dt=opp.CreatedDate.Year(); //conca = opp.Model__r.Name +opp.Rfleet_Country_Code__c + string.valueof(opp.Opportunity__r.Total_Fleet_Size__c)+string.valueof(dt); //system.debug('conca----->'+conca); if(ocs.Discount__c >disGrid.Rfleet_Discount__c){ ocs.Rfleet_Granted_discount_KO__c = true; opp.Rfleet_Granted_discount_KO__c=true; }else{ ocs.Rfleet_Granted_discount_KO__c = false; opp.Rfleet_Granted_discount_KO__c=false; } } } } } }
- kiran k 12
- February 08, 2016
- Like
- 0
Trigger problem is during inserting a new record
I have written a trigger.that logic is working fine for me . when i inserting a new record ,the trigger is not firing.but updating a same record trigger is working fine.the trigger logic is the discount is exceeded morethan fixed discount the checkbox 'Granted discount KO' is checked.i have tried tigger.isinsert and trigger.isnew context variables but same result.can you anybody help me.
Trigger: trigger Rfleet_validDiscountpercent on Opportunity_car_set__c (before insert,before update) { decimal d; set<id>oppids=new set<id>(); string conca; list<Opportunity> lsupdateopp=new list<Opportunity>(); for(Opportunity_car_set__c oppcarset:[select Model__r.Name, Discount__c,Opportunity__r.Total_Fleet_Size__c,Model__c,Rfleet_Country_Code__c,CreatedDate from Opportunity_car_set__c where id in:trigger.new]){ integer dt=oppcarset.CreatedDate.Year(); conca = oppcarset.Model__r.Name +oppcarset.Rfleet_Country_Code__c + string.valueof(oppcarset.Opportunity__r.Total_Fleet_Size__c)+string.valueof(dt); system.debug('conca----->'+conca); } list<Discount_Grid__c> listDisGrid=[select Rfleet_Status__c,Rfleet_Discountconca__c,Rfleet_Discount__c from Discount_Grid__c where Rfleet_Status__c = 'Enabled' and Rfleet_Discountconca__c=:conca order by CreatedDate desc limit 1]; system.debug('>>>>>>>>>>>>>>:'+listDisGrid); for(Opportunity_car_set__c opp:trigger.new){ for(Discount_Grid__c disGrid:listDisGrid){ if(opp.Discount__c >disGrid.Rfleet_Discount__c){ opp.Rfleet_Granted_discount_KO__c = true; oppids.add(opp.Opportunity__c); }else{ oppids.add(opp.Opportunity__c); } } } list<Opportunity>opplistupdate=[select Rfleet_Granted_discount_KO__c from Opportunity where id=:oppids]; system.debug('>>>>>>>>>>>>>>:'+opplistupdate); for(Opportunity_car_set__c oppCar:trigger.new){ for(Opportunity updateopp:opplistupdate){ if(oppCar.Rfleet_Granted_discount_KO__c==true && opplistupdate.size()>0){ updateopp.Rfleet_Granted_discount_KO__c =true; lsupdateopp.add(updateopp); }else if(oppCar.Rfleet_Granted_discount_KO__c==false && opplistupdate.size()>0){ updateopp.Rfleet_Granted_discount_KO__c =false; lsupdateopp.add(updateopp); } } update lsupdateopp; } }
- kiran k 12
- February 03, 2016
- Like
- 0
inside for loop not covered
I have wriiten a test class for trigger.i got 42% code coverage.the coverage is not entering in for loop.i have instantiate the fields based on for loop,but not covered.how to cover FOR LOOP in test class?please can you anybody help me.
Trigger: trigger Rfleet_DisableAttachements on Attachment(before insert,before delete,after update) { Id devRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('RFLEET-OPP-DCVF-RT').getRecordTypeId(); Id devRecordTypeId1 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('DC-VF Read only RT').getRecordTypeId(); if(trigger.isinsert && trigger.isbefore){ for (Attachment att:Trigger.new){ String parentObjId = att.ParentId; //It will get profitability obj id. list<opportunity> pid= [select Rfleet_locked__c,recordtypeid from Opportunity where Rfleet_locked__c=true ];// it get list of opp locked records. list<Rfleet_Profitability__c> ids=[Select Rfleet_opportunity__c from Rfleet_Profitability__c where id=:att.ParentId]; for(Rfleet_Profitability__c pro:ids){ for(opportunity opp:pid){ if(parentObjId.startsWith('a3r') && opp.Rfleet_locked__c==true && opp.id==pro.Rfleet_opportunity__c && opp.recordtypeid==devRecordTypeId )//a3r is the starting sting in ID for all Profitability { att.addError('Since this opportunity was submitted for approval, you are not allowed to add a new attachment.'); } else if(parentObjId.startsWith('a3r') && opp.Rfleet_locked__c==true && opp.id==pro.Rfleet_opportunity__c && opp.recordtypeid==devRecordTypeId1) { att.addError('Since this opportunity was closed, you are not allowed to add a new attachment.'); } } } } } if(trigger.isdelete && trigger.isbefore){ for (Attachment att:Trigger.old){ String parentObjId = att.ParentId; list<opportunity> pid= [select Rfleet_locked__c,recordtypeid from Opportunity where Rfleet_locked__c=true ];// it get list of opp locked records. list<Rfleet_Profitability__c> ids=[Select Rfleet_opportunity__c from Rfleet_Profitability__c where id=:att.ParentId]; for(Rfleet_Profitability__c pro:ids){ for(opportunity opp:pid){ if(parentObjId.startsWith('a3r') && opp.Rfleet_locked__c==true && opp.id==pro.Rfleet_opportunity__c && opp.recordtypeid==devRecordTypeId)//a3r is the starting sting in ID for all Profitability { att.addError('Since this opportunity was submitted for approval, you are not allowed to delete the attachment.'); } else if(parentObjId.startsWith('a3r') && opp.Rfleet_locked__c==true && opp.id==pro.Rfleet_opportunity__c && opp.recordtypeid==devRecordTypeId1) { att.addError('Since this opportunity was closed, you are not allowed to delete the attachment.'); } } } } } if(trigger.isupdate && trigger.isafter){ for (Attachment att:Trigger.new){ String parentObjId = att.ParentId; list<opportunity> pid= [select Rfleet_locked__c,recordtypeid from Opportunity where Rfleet_locked__c=true ];// it get list of opp locked records. list<Rfleet_Profitability__c> ids=[Select Rfleet_opportunity__c from Rfleet_Profitability__c where id=:att.ParentId]; for(Rfleet_Profitability__c pro:ids){ for(opportunity opp:pid){ if(parentObjId.startsWith('a3r') && opp.Rfleet_locked__c==true && opp.id==pro.Rfleet_opportunity__c && opp.recordtypeid==devRecordTypeId)//a3r is the starting sting in ID for all Profitability { att.addError('Since this opportunity was submitted for approval, you are not allowed to update the attachment.'); } else if(parentObjId.startsWith('a3r') && opp.Rfleet_locked__c==true && opp.id==pro.Rfleet_opportunity__c && opp.recordtypeid==devRecordTypeId1) { att.addError('Since this opportunity was closed, you are not allowed to update the attachment.'); } } } } } }
test class: @isTest public class Rfleet_DisableAttachements_Test { static testMethod void Rfleet_DisableAttachements(){ Account acc = new Account(Name='vfvh',montant__c=0.3); insert acc; acc.name='hjghg'; update acc; Opportunity opp=new Opportunity(); RecordType rt = [select Id from RecordType where Name = 'RFLEET-OPP-DCVF-RT' and SobjectType = 'opportunity' LIMIT 1]; opp.RecordTypeId = rt.id; opp.Rfleet_locked__c = false; opp.name='fdf'; opp.stagename='Draft'; opp.closedate=System.Today(); insert opp; opp.name='save'; update opp; Rfleet_Profitability__c Pro=new Rfleet_Profitability__c(); Pro.name='Testpro'; Pro.Rfleet_opportunity__c=opp.id; Attachment attach=new Attachment(); attach.Name='TestAtt'; Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body'); attach.body=bodyBlob; attach.parentId=opp.Id; insert attach; List<Attachment> attachments=[select id, name from Attachment where parent.id=:opp.id]; System.assertEquals(1, attachments.size()); attach = [SELECT Id, name from Attachment where parent.id=:opp.id]; delete attach; } }
- kiran k 12
- January 31, 2016
- Like
- 0
need help for trigger?
I have two objects opportunitycarset and discountgrid.in opportunitycarset object discount% and in discountgrid object model,year,totalfleetsize fields is there.the totalfleetsize is lookupto opportunity object.i want update the discount% field in opportunitycarset based on model,year,totalfleetsize fields present in discountgrid.there is no relationship between these two objects.I am new to apex trigger .
how to achieve this?
trigger: trigger Discountupdate on Opportunity_car_set__c(before insert, before update){ List<ID> OppIds = New List<ID>(); for(Opportunity_car_set__c o : Trigger.new){ if(opportunity__r.totalfleetsize!= null){ OppIds.add(o.Opportunity__c); } } }
how to achieve this?
- kiran k 12
- January 25, 2016
- Like
- 0
Test class for "for loop"
I have written a test class for trigger.the result is pass,but 0% coverage.how to achieve more than 85%?
Trigger: trigger Rfleet_DeleteRecords_Draft on Opportunity_car_set__c(before delete) { set < id > BId = new set < id > (); set < id > OpId= new set <id>(); if (Trigger.isDelete && Trigger.isBefore) { Id devRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('RFLEET-OPP-Algeria-RT').getRecordTypeId(); for (Opportunity_car_set__c rec: trigger.old) { BId.add(rec.Opportunity__c); OpId.add(rec.id); List < Opportunity > ListOpp = [select StageName, RecordTypeId from Opportunity where id = : BId]; for (Opportunity opp: ListOpp) { if (opp.RecordTypeId == devRecordTypeId) { if (opp.StageName == 'Qualification' || opp.StageName == 'Prospecting') { rec.adderror('You cannot delete this record!'); } } } } } delete [SELECT id FROM Service__c where Opportunity_car_set__c =:OpId]; } Test class: @isTest private class Rfleet_DeleteRecords_Draft_Test{ static testMethod void Rfleet_DeleteRecords_Draft(){ test.startTest(); Opportunity opp= new Opportunity(); opp.name='Prabu'; opp.stagename='Qualification'; opp.CloseDate=system.Today(); insert opp; opp.name='kiran'; //opp.StageName = 'Prospecting'; update opp; system.assertEquals('kiran',opp.name); Opportunity_car_set__c oppCarSet = new Opportunity_car_set__c(); oppCarSet.name='Opp'; oppCarSet.Opportunity__c =opp.id; oppCarSet.Quantity__c =2; insert oppCarSet; oppCarSet.Quantity__c =3; update oppCarSet; system.assertEquals(3,oppCarSet.Quantity__c); Service__c ser = new Service__c(); ser.Opportunity_car_set__c = oppCarSet.id; ser.Quantity__c = 1; ser.Price_HT__c = 10; insert ser; ser.Price_HT__c = 20; delete ser; system.assertEquals(20,ser.Price_HT__c); test.stopTest(); } }
- kiran k 12
- January 19, 2016
- Like
- 0
how to cover the for loop in test class?
I have written a test class for apex class.i got 89% but 'for loop' is not covered represented as below screenshot.how to achieve morethan 90%?can you anybody help me where iam missing exactly.
apex class:
public with sharing class Rfleet_Financial_Informations {
//Variable Declaration Parts
public List < RFLEET_Account_Protocol__c > contt {get;set;}
public List < EditableContact > myAssociatedContact {get;set;}
public Integer editableContactNumber {get;set;}
public Boolean refreshPage {get;set;}
public String protocolname {get;set;}
public String id;
//Constructor for invoking the Records from AccountProrocol Object
public Rfleet_Financial_Informations(ApexPages.StandardController stdCtrl) {
id = ApexPages.currentPage().getParameters().get('id');
myAssociatedContact = new List < EditableContact > ();
Integer counter = 0;
RFLEET_Protocol__c conn = [select name from RFLEET_Protocol__c where id = : id];
protocolname = conn.name;
contt = [select Name,Rfleet_Billing_Account__r.Name, Rfleet_Id_Alcor__c, Rfleet_Billing_Account_Type__c, Rfleet_Billing_Account__r.Rfleet_Street_Number__c, Rfleet_Billing_Account__r.Rfleet_Country__c, Rfleet_Billing_Account__r.Rfleet_Zip_Code__c, Rfleet_Billing_Account__r.Rfleet_State_Province__c, Rfleet_Billing_Account__r.Rfleet_City__c, Rfleet_Billing_Account__r.Rfleet_Street_Name__c from RFLEET_Account_Protocol__c where Rfleet_Protocol__c = : id];
for (RFLEET_Account_Protocol__c myContact: contt) {
myAssociatedContact.add(new EditableContact(myContact, false, counter));
counter++;
}
}
// This method is used for deleting the Row
public void deleteRowEditAction() {
try {
myAssociatedContact.get(editableContactNumber).editable = false;
delete(myAssociatedContact.get(editableContactNumber).myContact);
} catch (Exception e) {}
refreshPage = true;
}
public class EditableContact {
public RFLEET_Account_Protocol__c myContact {get;set;}
public Boolean editable {get;set;}
public Integer counterNumber {get;set;}
public EditableContact(RFLEET_Account_Protocol__c myContact, Boolean editable, Integer counterNumber) {
this.myContact = myContact;
this.editable = editable;
this.counterNumber = counterNumber;
}
}
}
test class:
@isTest
public class Rfleet_Financial_Informations_Test {
static testMethod void financialtest() {
Billing_Repository__c brc = new Billing_Repository__c(Name='frest',Rfleet_City__c='cger',Rfleet_Country__c='japan',Rfleet_Zip_Code__c='7854',CurrencyIsoCode='EUR');
Account acc = new Account(Name = 'cooluma',montant__c=0.2);
acc.Rfleet_Id_Alcor__c=brc.id;
acc.Rfleet_Street_Name__c ='gff';
acc.Rfleet_Street_Number__c ='232';
acc.Rfleet_Country__c ='fdffd';
acc.Rfleet_City__c ='cdfdf';
acc.Rfleet_State_Province__c ='dfdf';
acc.Rfleet_Zip_Code__c ='dfdfnhj';
insert acc;
acc.Name = 'vfggf';
update acc;
RFLEET_Protocol__c test = new RFLEET_Protocol__c(Name = 'prabu');
insert test;
test.Name = 'prabu';
update test;
RFLEET_Account_Protocol__c myContact = new RFLEET_Account_Protocol__c(Rfleet_Billing_Account__c = acc.Id, Rfleet_Billing_Account_Type__c = 'Vehicle', Rfleet_City__c =acc.Rfleet_City__c,Rfleet_Country__c =acc.Rfleet_Country__c, Rfleet_Id_Alcor__c = acc.Rfleet_Id_Alcor__c,
Rfleet_Protocol__c = acc.Id, Rfleet_State_Province__c =acc.Rfleet_State_Province__c , Rfleet_Street_name__c =acc.Rfleet_Street_Name__c, Rfleet_Street_number__c = acc.Rfleet_Street_Number__c, Rfleet_Zip_code__c =acc.Rfleet_Zip_Code__c);
string name = 'ListConditionCheck';
Boolean editable;
Integer counternumber;
Rfleet_Financial_Informations.editableContact wra = new Rfleet_Financial_Informations.EditableContact(mycontact, editable, counterNumber);
test = [select id, Name from RFLEET_Protocol__c LIMIT 1];
PageReference vfpage = Page.Rfleet_Financial_Informations;
System.test.SetCurrentpage(vfpage);
Apexpages.currentPage().getparameters().put('id',test.id);
Apexpages.StandardController sc = new Apexpages.StandardController(test);
Rfleet_Financial_Informations fintest = new Rfleet_Financial_Informations(sc);
fintest.deleteRowEditAction();
fintest.id = acc.Id;
}
}
screenshot:
apex class:
public with sharing class Rfleet_Financial_Informations {
//Variable Declaration Parts
public List < RFLEET_Account_Protocol__c > contt {get;set;}
public List < EditableContact > myAssociatedContact {get;set;}
public Integer editableContactNumber {get;set;}
public Boolean refreshPage {get;set;}
public String protocolname {get;set;}
public String id;
//Constructor for invoking the Records from AccountProrocol Object
public Rfleet_Financial_Informations(ApexPages.StandardController stdCtrl) {
id = ApexPages.currentPage().getParameters().get('id');
myAssociatedContact = new List < EditableContact > ();
Integer counter = 0;
RFLEET_Protocol__c conn = [select name from RFLEET_Protocol__c where id = : id];
protocolname = conn.name;
contt = [select Name,Rfleet_Billing_Account__r.Name, Rfleet_Id_Alcor__c, Rfleet_Billing_Account_Type__c, Rfleet_Billing_Account__r.Rfleet_Street_Number__c, Rfleet_Billing_Account__r.Rfleet_Country__c, Rfleet_Billing_Account__r.Rfleet_Zip_Code__c, Rfleet_Billing_Account__r.Rfleet_State_Province__c, Rfleet_Billing_Account__r.Rfleet_City__c, Rfleet_Billing_Account__r.Rfleet_Street_Name__c from RFLEET_Account_Protocol__c where Rfleet_Protocol__c = : id];
for (RFLEET_Account_Protocol__c myContact: contt) {
myAssociatedContact.add(new EditableContact(myContact, false, counter));
counter++;
}
}
// This method is used for deleting the Row
public void deleteRowEditAction() {
try {
myAssociatedContact.get(editableContactNumber).editable = false;
delete(myAssociatedContact.get(editableContactNumber).myContact);
} catch (Exception e) {}
refreshPage = true;
}
public class EditableContact {
public RFLEET_Account_Protocol__c myContact {get;set;}
public Boolean editable {get;set;}
public Integer counterNumber {get;set;}
public EditableContact(RFLEET_Account_Protocol__c myContact, Boolean editable, Integer counterNumber) {
this.myContact = myContact;
this.editable = editable;
this.counterNumber = counterNumber;
}
}
}
test class:
@isTest
public class Rfleet_Financial_Informations_Test {
static testMethod void financialtest() {
Billing_Repository__c brc = new Billing_Repository__c(Name='frest',Rfleet_City__c='cger',Rfleet_Country__c='japan',Rfleet_Zip_Code__c='7854',CurrencyIsoCode='EUR');
Account acc = new Account(Name = 'cooluma',montant__c=0.2);
acc.Rfleet_Id_Alcor__c=brc.id;
acc.Rfleet_Street_Name__c ='gff';
acc.Rfleet_Street_Number__c ='232';
acc.Rfleet_Country__c ='fdffd';
acc.Rfleet_City__c ='cdfdf';
acc.Rfleet_State_Province__c ='dfdf';
acc.Rfleet_Zip_Code__c ='dfdfnhj';
insert acc;
acc.Name = 'vfggf';
update acc;
RFLEET_Protocol__c test = new RFLEET_Protocol__c(Name = 'prabu');
insert test;
test.Name = 'prabu';
update test;
RFLEET_Account_Protocol__c myContact = new RFLEET_Account_Protocol__c(Rfleet_Billing_Account__c = acc.Id, Rfleet_Billing_Account_Type__c = 'Vehicle', Rfleet_City__c =acc.Rfleet_City__c,Rfleet_Country__c =acc.Rfleet_Country__c, Rfleet_Id_Alcor__c = acc.Rfleet_Id_Alcor__c,
Rfleet_Protocol__c = acc.Id, Rfleet_State_Province__c =acc.Rfleet_State_Province__c , Rfleet_Street_name__c =acc.Rfleet_Street_Name__c, Rfleet_Street_number__c = acc.Rfleet_Street_Number__c, Rfleet_Zip_code__c =acc.Rfleet_Zip_Code__c);
string name = 'ListConditionCheck';
Boolean editable;
Integer counternumber;
Rfleet_Financial_Informations.editableContact wra = new Rfleet_Financial_Informations.EditableContact(mycontact, editable, counterNumber);
test = [select id, Name from RFLEET_Protocol__c LIMIT 1];
PageReference vfpage = Page.Rfleet_Financial_Informations;
System.test.SetCurrentpage(vfpage);
Apexpages.currentPage().getparameters().put('id',test.id);
Apexpages.StandardController sc = new Apexpages.StandardController(test);
Rfleet_Financial_Informations fintest = new Rfleet_Financial_Informations(sc);
fintest.deleteRowEditAction();
fintest.id = acc.Id;
}
}
screenshot:
- kiran k 12
- December 23, 2015
- Like
- 0
How to test for loop in test class?
I have wriiten a test class for apex class.i got 89% but for loop is not covered.please see the screenshot for clarification.how to cover' for loop' and improve code coverage?
apex class:
apex class:
public with sharing class Rfleet_Commericialcondition { //Variable Declaration Parts public List < RFLEET_Protocol_Grid__c > contt {get;set;} public List < EditableContact > myAssociatedContact {get;set;} public Integer editableContactNumber {get;set;} public Boolean refreshPage {get;set;} public String protocolname {get;set;} String id; //Constructor for invoking the Records from Protocol Grid Object public Rfleet_Commericialcondition(ApexPages.StandardController stdCtrl) { id = ApexPages.currentPage().getParameters().get('id'); myAssociatedContact = new List < EditableContact > (); Integer counter = 0; RFLEET_Protocol__c conn = [select name from RFLEET_Protocol__c where id = : id]; protocolname = conn.name; contt = [select id, Name, Rfleet_Type_of_Grid__c, Rfleet_Type_of_Sales__c, Rfleet_Protocol__c from RFLEET_Protocol_Grid__c where Rfleet_Protocol__r.name = : protocolname]; for (RFLEET_Protocol_Grid__c myContact: contt) { myAssociatedContact.add(new EditableContact(myContact, false, counter)); counter++; } } // This method is used for deleting the Row public void deleteRowEditAction() { try { myAssociatedContact.get(editableContactNumber).editable = false; delete(myAssociatedContact.get(editableContactNumber).myContact); } catch (Exception e) {} refreshPage = true; } public class EditableContact { public RFLEET_Protocol_Grid__c myContact {get;set;} public Boolean editable {get;set;} public Integer counterNumber {get;set;} public EditableContact(RFLEET_Protocol_Grid__c myContact, Boolean editable, Integer counterNumber) { this.myContact = myContact; this.editable = editable; this.counterNumber = counterNumber; } } }test class:
@isTest public class Rfleet_Commercialcondition_Test { @isTest Static void Testcommercial(){ RFLEET_Protocol_Grid__c myContact = new RFLEET_Protocol_Grid__c (Name='testing'); insert myContact; myContact.Rfleet_Input_Mode__c = 'manually'; update myContact; String Name = 'ListConditionCheck'; Boolean editable; Integer counterNumber; Boolean refreshPage; Integer editableContactNumber; Rfleet_Commericialcondition.EditableContact wra= new Rfleet_Commericialcondition.EditableContact(myContact, editable, counterNumber); RFLEET_Protocol__c test = new RFLEET_Protocol__c(Name='prabu'); insert test; test.Name = 'prabu'; update test; System.debug('Before Query'); RFLEET_Protocol__c myCondtest = new RFLEET_Protocol__c(); myCondtest = [select id,Name from RFLEET_Protocol__c LIMIT 1]; PageReference vfpage = Page.Rfleet_Commericialcondition; System.test.SetCurrentpage(vfpage); Apexpages.currentPage().getparameters().put('id',myCondtest.id); System.assertEquals(myCondtest.id,ApexPages.currentPage().getParameters().get('id')); Apexpages.StandardController sc = new Apexpages.StandardController(myCondtest); Rfleet_Commericialcondition commtest = new Rfleet_Commericialcondition(sc); commtest.deleteRowEditAction(); System.assertEquals('prabu',test.Name); } }
- kiran k 12
- December 22, 2015
- Like
- 1
Test class for @remoteaction
Recently i have written a test class for @remoteaction.i got 79% with error.how to resolve this error and improve code coverage?
apex class:
mockgenerator test class:
apex class:
global class Rfleet_Searchaddress { public String StNumber {get;set;} public String Bcity {get;set;} public String BPostalcode {get;set;} public String BCountry {get;set;} public String Snumber {get;set;} public String street {get;set;} public Boolean refreshPage {get;set;} string Id; list < Account > updateAdd = new list < Account > (); //This method is constructor public Rfleet_Searchaddress(ApexPages.StandardController controller) { id = ApexPages.currentPage().getParameters().get('id'); refreshPage = false; } //This method is autosave the addresses public void autosave() { for (Account updatelist: [SELECT id, Rfleet_Main_Address_Number__c, Rfleet_Main_address_Street__c, BillingAddress, BillingCity, BillingCountry, BillingPostalCode, BillingState, BillingStreet FROM Account where id = : id]) { updatelist.BillingStreet = Snumber + ' ' + street; //StNumber; updatelist.BillingCity = Bcity; updatelist.BillingPostalCode = BPostalcode; updatelist.BillingState = ''; updatelist.BillingCountry = BCountry; updatelist.Rfleet_Main_Address_Number__c = Snumber; updatelist.Rfleet_Main_address_Street__c = street; updateAdd.add(updatelist); } try{ update updateAdd; }catch(DmlException e) { system.debug('update--->' + updateAdd); } refreshPage = true; } //This method is remote action @RemoteAction global static list < String > restapi(string accName) { string jsonStr; Http h = new Http(); HttpRequest req = new HttpRequest(); req.setHeader('Accept', 'application/JSON'); req.setEndpoint('http://api-adresse.data.gouv.fr/search/?q=' + EncodingUtil.urlEncode(accName, 'UTF-8')); //+'&'+'limit'+'='+'10');// req.setMethod('GET'); HttpResponse res = h.send(req); system.debug('res1===>' + res.getBody()); List < String > calOut1 = new List < String > (); JSON2Apex parsed = JSON2Apex.parse(res.getBody()); for (JSON2Apex.Features f: parsed.Features) { JSON2Apex.Properties p = f.Properties; calOut1.add(p.label + ' ' + 'FRANCE'); } return calOut1; } }json2apex class:
public class JSON2Apex { public String query; public String version; public String licence; public List<Features> features; public String type; public String attribution; public class Geometry { public List<Double> coordinates; public String type; } public class Features { public Geometry geometry; public String type; public Properties properties; } public class Properties { public String city; public String label; public String id; public String postcode; public String name; public String citycode; public String context; public Double score; public String type; } public static JSON2Apex parse(String json) { return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class); } static testMethod void testParse() { String json = '{\"query\": \"8\", \"version\": \"draft\", \"licence\": \"ODbL 1.0\", \"features\": [{\"geometry\": {\"coordinates\": [5.600741, 43.28252], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"Aubagne\", \"label\": \"Route Nationale 8 13400 Aubagne\", \"id\": \"13005_XXXX_b0c6c8\", \"postcode\": \"13400\", \"name\": \"Route Nationale 8\", \"citycode\": \"13005\", \"context\": \"13, Bouches-du-Rh\\u00f4ne, Provence-Alpes-C\\u00f4te d\'Azur\", \"score\": 0.6540636363636363, \"type\": \"street\"}}, {\"geometry\": {\"coordinates\": [5.864773, 43.132774], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"Ollioules\", \"label\": \"Route Nationale 8 83190 Ollioules\", \"id\": \"83090_XXXX_a33650\", \"postcode\": \"83190\", \"name\": \"Route Nationale 8\", \"citycode\": \"83090\", \"context\": \"83, Var, Provence-Alpes-C\\u00f4te d\'Azur\", \"score\": 0.6526818181818181, \"type\": \"street\"}}, {\"geometry\": {\"coordinates\": [45.136426, -12.845884], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"Ouangani\", \"label\": \"Route D\\u00e9partementale 8 97670 Ouangani\", \"id\": \"97614_XXXX_704587\", \"postcode\": \"97670\", \"name\": \"Route D\\u00e9partementale 8\", \"citycode\": \"97614\", \"context\": \"976, Mayotte\", \"score\": 0.6507545454545454, \"type\": \"street\"}}, {\"geometry\": {\"coordinates\": [5.86687, 43.132284], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"Ollioules\", \"label\": \"Route Nationale 8 83190 Ollioules\", \"id\": \"83090_XXXX_9346fc\", \"postcode\": \"83190\", \"name\": \"Route Nationale 8\", \"citycode\": \"83090\", \"context\": \"83, Var, Provence-Alpes-C\\u00f4te d\'Azur\", \"score\": 0.6481181818181817, \"type\": \"street\"}}, {\"geometry\": {\"coordinates\": [3.242916, 43.379135], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"B\\u00e9ziers\", \"label\": \"Chemin Rural 8 34500 B\\u00e9ziers\", \"id\": \"34032_XXXX_ddb1db\", \"postcode\": \"34500\", \"name\": \"Chemin Rural 8\", \"citycode\": \"34032\", \"context\": \"34, H\\u00e9rault, Languedoc-Roussillon\", \"score\": 0.6467545454545454, \"type\": \"locality\"}}], \"type\": \"FeatureCollection\", \"attribution\": \"BAN\"}'; JSON2Apex obj = parse(json); System.assert(obj != null); } }
mockgenerator test class:
@isTest global class Rfleet_MockHttpResponseGenerator_Test implements HttpCalloutMock { global HTTPResponse respond(HTTPRequest req) { // Optionally, only send a mock response for a specific endpoint // and method. System.assertEquals('http://api-adresse.data.gouv.fr/search/?q='+'france', req.getEndpoint()); System.assertEquals('GET', req.getMethod()); // Create a fake response HttpResponse res = new HttpResponse(); res.setHeader('Content-Type', 'application/json'); res.setBody('{"foo":"bar"}'); res.setStatusCode(200); return res; } }Test class:
@isTest public class Rfleet_Searchaddress_test { @isTest static void Testsearchaddress() { Account testAccount = new Account(Name='chinna',Montant__c=5); insert testAccount; testAccount.BillingStreet='chengalpattu'; update testAccount; Account myTestTrainee = [SELECT id From Account LIMIT 1]; PageReference myVfPage = Page.RFLEET_Searchaddress; system.test.setCurrentPage(myVfPage); ApexPages.currentPage().getParameters().put('id', myTestTrainee.id);//Pass Id to page ApexPAges.StandardController sc = new ApexPages.StandardController(myTestTrainee); Rfleet_Searchaddress apextestclass=new Rfleet_Searchaddress(sc); apextestclass.autosave(); String param ='Base Product'; RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); req.requestURI = 'http://api-adresse.data.gouv.fr/search/?q='; req.httpMethod = 'GET'; RestContext.request = req; RestContext.response = res; Rfleet_Searchaddress.restapi('jso'); Test.startTest(); Test.setMock(HttpCalloutMock.class, new Rfleet_MockHttpResponseGenerator_Test()); Test.stopTest(); } }
- kiran k 12
- December 21, 2015
- Like
- 0
test class for remoteaction method
Need test class for @remoteaction.i wrote a test class it gives 45%,but it cannot cover remoteaction method.can anybody help me how to cover remoteaction method in test class?
this is my class
this is my class
global class RFLEET_ProtocolLineController { //declartion part public Boolean refreshPage { get; set; } public string volumeJSON {get;set;} public string newlineinsertlist{get;set;} List<String> v1= new List<String>(); List<List<String>> v2= new List<List<String>>(); List<String> v3= new List<String>(); List<List<String>> v4= new List<List<String>>(); string Id; public String gridtype{get;set;} public String gridname{get;set;} public boolean hideExcel{get;set;} public boolean hidetable2{get;set;} public RFLEET_ProtocolLineController(ApexPages.StandardController controller) { hideExcel=true; hidetable2=false; id=ApexPages.currentPage().getParameters().get('id'); RFLEET_Protocol_Grid__c grid=[select id,name,Rfleet_Type_of_Grid__c from RFLEET_Protocol_Grid__c where id=:id]; gridtype=grid.Rfleet_Type_of_Grid__c; gridname=grid.id; Rfleet_ProtocolLineList(); } //copy-paste solution existing values fetching from protocol lines public void Rfleet_ProtocolLineList(){ v2= new List<List<String>>(); for(RFLEET_Protocol_Line__c oli: [select id,Rfleet_Discount__c,Rfleet_Model__c,Rfleet_Option__c,Rfleet_Price__c,Rfleet_PricePercent__c ,Rfleet_Protocol_grid_name__c,Rfleet_Version__c ,Rfleet_Volume__c from RFLEET_Protocol_Line__c where Rfleet_Protocol_grid_name__c=:gridname ]) { v1= new List<String>(); v1.add(oli.id); v1.add(oli.Rfleet_Model__c); v1.add(oli.Rfleet_Option__c); v1.add(string.valueOf(oli.Rfleet_Price__c)); v1.add(String.valueOf(oli.Rfleet_Discount__c)); v1.add(String.valueOf(oli.Rfleet_PricePercent__c)); v1.add(oli.Rfleet_Version__c); v1.add(String.valueOf(oli.Rfleet_Volume__c)); v1.add(oli.Rfleet_Protocol_grid_name__c); v2.add(v1); } volumeJSON= JSON.serialize(v2); } //Rfresh table and redirect to home page protocol grids public void cancel(){ hideExcel=true; hidetable2=false; refreshPage =true; } //copy-paste solution new line insert function empty values passing here public void RfleetnewlineExcel(){ hideExcel=false; hidetable2=true; RFLEET_Protocol_Line__c ww=new RFLEET_Protocol_Line__c(); for(integer i=1; i<=20;i++){ String model=ww.Rfleet_Model__c; String Option=ww.Rfleet_Option__c; String Price=(string.valueOf(ww.Rfleet_Price__c)); String Discount=(String.valueOf(ww.Rfleet_Discount__c)); String Version=ww.Rfleet_Version__c; String Volume=(String.valueOf(ww.Rfleet_Volume__c)); String PricePercent=(String.valueOf(ww.Rfleet_PricePercent__c)); String masterid=ww.Rfleet_Protocol_grid_name__c; v3= new List<String>(); v3.add(model); v3.add(Option); v3.add(Price); v3.add(Discount); v3.add(Version); v3.add(Volume); v3.add(PricePercent); v4.add(v3); } newlineinsertlist= JSON.serialize(v4); } //copy-paste solution update function starts here @RemoteAction global static pagereference AccSave(List<List<String>> valuefromJS){ List<RFLEET_Protocol_Line__c> volSave = new List<RFLEET_Protocol_Line__c>(); for(Integer i=0; i<valuefromJS.size(); i++){ RFLEET_Protocol_Line__c v=new RFLEET_Protocol_Line__c(); List<String> l1 = valuefromJS[i]; v.id=l1[0]; v.Rfleet_Model__c=l1[1]; if(l1[2] != null ){ v.Rfleet_Option__c= string.valueof(l1[2]); } if(!string.isBlank(l1[3])){ v.Rfleet_Price__c= Decimal.valueof(l1[3]); } else{ v.Rfleet_Price__c=null; } if(!string.isBlank(l1[4])){ v.Rfleet_Discount__c=Decimal.valueof(l1[4]); }else{ v.Rfleet_Discount__c=null; } if(!string.isBlank(l1[5])){ v.Rfleet_PricePercent__c=Decimal.valueof(l1[5]); }else{ v.Rfleet_PricePercent__c=null; } if(l1[6] != null ){ v.Rfleet_Version__c=string.valueof(l1[6]); } if(!string.isBlank(l1[7])){ v.Rfleet_Volume__c=Decimal.valueof(l1[7]); }else{ v.Rfleet_Volume__c=null; } v.Rfleet_Protocol_grid_name__c=l1[8]; volSave.add(v); } update volSave; return null; } // copy-paste solution action stared for newline insertion @RemoteAction global static pagereference newlineSave(List<List<String>> valuefromJSNewdata,string Masterid,string gtype ){ List<RFLEET_Protocol_Line__c> volSave1 = new List<RFLEET_Protocol_Line__c>(); for(Integer i=0; i<valuefromJSNewdata.size(); i++){ RFLEET_Protocol_Line__c proline=new RFLEET_Protocol_Line__c(); List<String> l2 = valuefromJSNewdata[i]; system.debug('<<<<<'+l2[0]); system.debug('<<<<<'+l2[1]); if(l2[0]==null && l2[1]==null && l2[2]==null && l2[3]==null && l2[4]==null && l2[5]==null && l2[6]==null) { system.debug('<<<<inside if null values'); } else{ system.debug('<<<<inside else with values'); proline.Rfleet_Model__c=l2[0]; if(l2[1] != null ){ proline.Rfleet_Option__c= string.valueof(l2[1]); } if(l2[2] != null ){ proline.Rfleet_Price__c= Decimal.valueof(l2[2]); } if(l2[3] != null ){ proline.Rfleet_Discount__c=Decimal.valueof(l2[3]); } if(l2[6] != null ){ proline.Rfleet_PricePercent__c=Decimal.valueof(l2[6]); } if(l2[4] != null ){ proline.Rfleet_Version__c=string.valueof(l2[4]); } if(l2[5] != null ){ proline.Rfleet_Volume__c=Decimal.valueof(l2[5]); } proline.Rfleet_Protocol_grid_name__c=Masterid; volSave1.add(proline); } } insert volSave1; return null; } }test class for above class:
@isTest public class RFLEET_ProtocolLineController_Test{ public static testMethod void copy(){ RFLEET_Protocol_Grid__c din = new RFLEET_Protocol_Grid__c(Name='sand'); insert din; din.Name = 'sanc'; update din; system.debug('din.id'+din.id); ApexPages.currentPage().getParameters().put('id',din.id); ApexPages.StandardController sc = new ApexPages.standardController(din); RFLEET_ProtocolLineController rp = new RFLEET_ProtocolLineController(sc); string selcontactid; selcontactid = System.currentPagereference().getParameters().get('conid'); Account Acc= New Account(Name='A1',Montant__c=1.4); insert Acc; RFLEET_Protocol__c Rpro=new RFLEET_Protocol__c(Name='Aggre',Rfleet_Agreement_Client__c=Acc.id,Rfleet_Status__c='Actif',Rfleet_Billing_Type__c='Dossier'); insert Rpro; RFLEET_Protocol_Grid__c pg=new RFLEET_Protocol_Grid__c(Name='t1',Rfleet_Type_of_Grid__c='Model - Discount %',Rfleet_Type_of_Sales__c='VD'); insert pg; RFLEET_Protocol_Line__c record = new RFLEET_Protocol_Line__c(Rfleet_Model__c='model',Rfleet_Discount__c=1.2,Rfleet_Version__c='test',Rfleet_Option__c='test',Rfleet_Volume__c=1,Rfleet_Price__c=12,Rfleet_Protocol_grid_name__c=pg.id); insert record; record.Rfleet_Model__c='test'; update record; rp.cancel(); rp.Rfleet_ProtocolLineList(); rp.RfleetnewlineExcel(); list<string> str=new list<string>();
- kiran k 12
- October 06, 2015
- Like
- 0
auto complete and fill the addresses automatically
give me example of auto complete and when i am enter the postal code,automatically executed the street,state fields?
- kiran k 12
- July 28, 2015
- Like
- 0
outlook integration
when i syncing contacts between salesforce and outlook,i got a error.please rectify my error
- kiran k 12
- July 17, 2015
- Like
- 0
Integration
hello
I have one requirement is there.how to integrate salesforce with sap?anybody know this answer,please reply to me.
I have one requirement is there.how to integrate salesforce with sap?anybody know this answer,please reply to me.
- kiran k 12
- June 17, 2015
- Like
- 0
How to test for loop in test class?
I have wriiten a test class for apex class.i got 89% but for loop is not covered.please see the screenshot for clarification.how to cover' for loop' and improve code coverage?
apex class:
apex class:
public with sharing class Rfleet_Commericialcondition { //Variable Declaration Parts public List < RFLEET_Protocol_Grid__c > contt {get;set;} public List < EditableContact > myAssociatedContact {get;set;} public Integer editableContactNumber {get;set;} public Boolean refreshPage {get;set;} public String protocolname {get;set;} String id; //Constructor for invoking the Records from Protocol Grid Object public Rfleet_Commericialcondition(ApexPages.StandardController stdCtrl) { id = ApexPages.currentPage().getParameters().get('id'); myAssociatedContact = new List < EditableContact > (); Integer counter = 0; RFLEET_Protocol__c conn = [select name from RFLEET_Protocol__c where id = : id]; protocolname = conn.name; contt = [select id, Name, Rfleet_Type_of_Grid__c, Rfleet_Type_of_Sales__c, Rfleet_Protocol__c from RFLEET_Protocol_Grid__c where Rfleet_Protocol__r.name = : protocolname]; for (RFLEET_Protocol_Grid__c myContact: contt) { myAssociatedContact.add(new EditableContact(myContact, false, counter)); counter++; } } // This method is used for deleting the Row public void deleteRowEditAction() { try { myAssociatedContact.get(editableContactNumber).editable = false; delete(myAssociatedContact.get(editableContactNumber).myContact); } catch (Exception e) {} refreshPage = true; } public class EditableContact { public RFLEET_Protocol_Grid__c myContact {get;set;} public Boolean editable {get;set;} public Integer counterNumber {get;set;} public EditableContact(RFLEET_Protocol_Grid__c myContact, Boolean editable, Integer counterNumber) { this.myContact = myContact; this.editable = editable; this.counterNumber = counterNumber; } } }test class:
@isTest public class Rfleet_Commercialcondition_Test { @isTest Static void Testcommercial(){ RFLEET_Protocol_Grid__c myContact = new RFLEET_Protocol_Grid__c (Name='testing'); insert myContact; myContact.Rfleet_Input_Mode__c = 'manually'; update myContact; String Name = 'ListConditionCheck'; Boolean editable; Integer counterNumber; Boolean refreshPage; Integer editableContactNumber; Rfleet_Commericialcondition.EditableContact wra= new Rfleet_Commericialcondition.EditableContact(myContact, editable, counterNumber); RFLEET_Protocol__c test = new RFLEET_Protocol__c(Name='prabu'); insert test; test.Name = 'prabu'; update test; System.debug('Before Query'); RFLEET_Protocol__c myCondtest = new RFLEET_Protocol__c(); myCondtest = [select id,Name from RFLEET_Protocol__c LIMIT 1]; PageReference vfpage = Page.Rfleet_Commericialcondition; System.test.SetCurrentpage(vfpage); Apexpages.currentPage().getparameters().put('id',myCondtest.id); System.assertEquals(myCondtest.id,ApexPages.currentPage().getParameters().get('id')); Apexpages.StandardController sc = new Apexpages.StandardController(myCondtest); Rfleet_Commericialcondition commtest = new Rfleet_Commericialcondition(sc); commtest.deleteRowEditAction(); System.assertEquals('prabu',test.Name); } }
- kiran k 12
- December 22, 2015
- Like
- 1
Trigger problem is during inserting a new record
I have written a trigger.that logic is working fine for me . when i inserting a new record ,the trigger is not firing.but updating a same record trigger is working fine.the trigger logic is the discount is exceeded morethan fixed discount the checkbox 'Granted discount KO' is checked.i have tried tigger.isinsert and trigger.isnew context variables but same result.can you anybody help me.
Trigger: trigger Rfleet_validDiscountpercent on Opportunity_car_set__c (before insert,before update) { decimal d; set<id>oppids=new set<id>(); string conca; list<Opportunity> lsupdateopp=new list<Opportunity>(); for(Opportunity_car_set__c oppcarset:[select Model__r.Name, Discount__c,Opportunity__r.Total_Fleet_Size__c,Model__c,Rfleet_Country_Code__c,CreatedDate from Opportunity_car_set__c where id in:trigger.new]){ integer dt=oppcarset.CreatedDate.Year(); conca = oppcarset.Model__r.Name +oppcarset.Rfleet_Country_Code__c + string.valueof(oppcarset.Opportunity__r.Total_Fleet_Size__c)+string.valueof(dt); system.debug('conca----->'+conca); } list<Discount_Grid__c> listDisGrid=[select Rfleet_Status__c,Rfleet_Discountconca__c,Rfleet_Discount__c from Discount_Grid__c where Rfleet_Status__c = 'Enabled' and Rfleet_Discountconca__c=:conca order by CreatedDate desc limit 1]; system.debug('>>>>>>>>>>>>>>:'+listDisGrid); for(Opportunity_car_set__c opp:trigger.new){ for(Discount_Grid__c disGrid:listDisGrid){ if(opp.Discount__c >disGrid.Rfleet_Discount__c){ opp.Rfleet_Granted_discount_KO__c = true; oppids.add(opp.Opportunity__c); }else{ oppids.add(opp.Opportunity__c); } } } list<Opportunity>opplistupdate=[select Rfleet_Granted_discount_KO__c from Opportunity where id=:oppids]; system.debug('>>>>>>>>>>>>>>:'+opplistupdate); for(Opportunity_car_set__c oppCar:trigger.new){ for(Opportunity updateopp:opplistupdate){ if(oppCar.Rfleet_Granted_discount_KO__c==true && opplistupdate.size()>0){ updateopp.Rfleet_Granted_discount_KO__c =true; lsupdateopp.add(updateopp); }else if(oppCar.Rfleet_Granted_discount_KO__c==false && opplistupdate.size()>0){ updateopp.Rfleet_Granted_discount_KO__c =false; lsupdateopp.add(updateopp); } } update lsupdateopp; } }
- kiran k 12
- February 03, 2016
- Like
- 0
Test class for "for loop"
I have written a test class for trigger.the result is pass,but 0% coverage.how to achieve more than 85%?
Trigger: trigger Rfleet_DeleteRecords_Draft on Opportunity_car_set__c(before delete) { set < id > BId = new set < id > (); set < id > OpId= new set <id>(); if (Trigger.isDelete && Trigger.isBefore) { Id devRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('RFLEET-OPP-Algeria-RT').getRecordTypeId(); for (Opportunity_car_set__c rec: trigger.old) { BId.add(rec.Opportunity__c); OpId.add(rec.id); List < Opportunity > ListOpp = [select StageName, RecordTypeId from Opportunity where id = : BId]; for (Opportunity opp: ListOpp) { if (opp.RecordTypeId == devRecordTypeId) { if (opp.StageName == 'Qualification' || opp.StageName == 'Prospecting') { rec.adderror('You cannot delete this record!'); } } } } } delete [SELECT id FROM Service__c where Opportunity_car_set__c =:OpId]; } Test class: @isTest private class Rfleet_DeleteRecords_Draft_Test{ static testMethod void Rfleet_DeleteRecords_Draft(){ test.startTest(); Opportunity opp= new Opportunity(); opp.name='Prabu'; opp.stagename='Qualification'; opp.CloseDate=system.Today(); insert opp; opp.name='kiran'; //opp.StageName = 'Prospecting'; update opp; system.assertEquals('kiran',opp.name); Opportunity_car_set__c oppCarSet = new Opportunity_car_set__c(); oppCarSet.name='Opp'; oppCarSet.Opportunity__c =opp.id; oppCarSet.Quantity__c =2; insert oppCarSet; oppCarSet.Quantity__c =3; update oppCarSet; system.assertEquals(3,oppCarSet.Quantity__c); Service__c ser = new Service__c(); ser.Opportunity_car_set__c = oppCarSet.id; ser.Quantity__c = 1; ser.Price_HT__c = 10; insert ser; ser.Price_HT__c = 20; delete ser; system.assertEquals(20,ser.Price_HT__c); test.stopTest(); } }
- kiran k 12
- January 19, 2016
- Like
- 0
how to cover the for loop in test class?
I have written a test class for apex class.i got 89% but 'for loop' is not covered represented as below screenshot.how to achieve morethan 90%?can you anybody help me where iam missing exactly.
apex class:
public with sharing class Rfleet_Financial_Informations {
//Variable Declaration Parts
public List < RFLEET_Account_Protocol__c > contt {get;set;}
public List < EditableContact > myAssociatedContact {get;set;}
public Integer editableContactNumber {get;set;}
public Boolean refreshPage {get;set;}
public String protocolname {get;set;}
public String id;
//Constructor for invoking the Records from AccountProrocol Object
public Rfleet_Financial_Informations(ApexPages.StandardController stdCtrl) {
id = ApexPages.currentPage().getParameters().get('id');
myAssociatedContact = new List < EditableContact > ();
Integer counter = 0;
RFLEET_Protocol__c conn = [select name from RFLEET_Protocol__c where id = : id];
protocolname = conn.name;
contt = [select Name,Rfleet_Billing_Account__r.Name, Rfleet_Id_Alcor__c, Rfleet_Billing_Account_Type__c, Rfleet_Billing_Account__r.Rfleet_Street_Number__c, Rfleet_Billing_Account__r.Rfleet_Country__c, Rfleet_Billing_Account__r.Rfleet_Zip_Code__c, Rfleet_Billing_Account__r.Rfleet_State_Province__c, Rfleet_Billing_Account__r.Rfleet_City__c, Rfleet_Billing_Account__r.Rfleet_Street_Name__c from RFLEET_Account_Protocol__c where Rfleet_Protocol__c = : id];
for (RFLEET_Account_Protocol__c myContact: contt) {
myAssociatedContact.add(new EditableContact(myContact, false, counter));
counter++;
}
}
// This method is used for deleting the Row
public void deleteRowEditAction() {
try {
myAssociatedContact.get(editableContactNumber).editable = false;
delete(myAssociatedContact.get(editableContactNumber).myContact);
} catch (Exception e) {}
refreshPage = true;
}
public class EditableContact {
public RFLEET_Account_Protocol__c myContact {get;set;}
public Boolean editable {get;set;}
public Integer counterNumber {get;set;}
public EditableContact(RFLEET_Account_Protocol__c myContact, Boolean editable, Integer counterNumber) {
this.myContact = myContact;
this.editable = editable;
this.counterNumber = counterNumber;
}
}
}
test class:
@isTest
public class Rfleet_Financial_Informations_Test {
static testMethod void financialtest() {
Billing_Repository__c brc = new Billing_Repository__c(Name='frest',Rfleet_City__c='cger',Rfleet_Country__c='japan',Rfleet_Zip_Code__c='7854',CurrencyIsoCode='EUR');
Account acc = new Account(Name = 'cooluma',montant__c=0.2);
acc.Rfleet_Id_Alcor__c=brc.id;
acc.Rfleet_Street_Name__c ='gff';
acc.Rfleet_Street_Number__c ='232';
acc.Rfleet_Country__c ='fdffd';
acc.Rfleet_City__c ='cdfdf';
acc.Rfleet_State_Province__c ='dfdf';
acc.Rfleet_Zip_Code__c ='dfdfnhj';
insert acc;
acc.Name = 'vfggf';
update acc;
RFLEET_Protocol__c test = new RFLEET_Protocol__c(Name = 'prabu');
insert test;
test.Name = 'prabu';
update test;
RFLEET_Account_Protocol__c myContact = new RFLEET_Account_Protocol__c(Rfleet_Billing_Account__c = acc.Id, Rfleet_Billing_Account_Type__c = 'Vehicle', Rfleet_City__c =acc.Rfleet_City__c,Rfleet_Country__c =acc.Rfleet_Country__c, Rfleet_Id_Alcor__c = acc.Rfleet_Id_Alcor__c,
Rfleet_Protocol__c = acc.Id, Rfleet_State_Province__c =acc.Rfleet_State_Province__c , Rfleet_Street_name__c =acc.Rfleet_Street_Name__c, Rfleet_Street_number__c = acc.Rfleet_Street_Number__c, Rfleet_Zip_code__c =acc.Rfleet_Zip_Code__c);
string name = 'ListConditionCheck';
Boolean editable;
Integer counternumber;
Rfleet_Financial_Informations.editableContact wra = new Rfleet_Financial_Informations.EditableContact(mycontact, editable, counterNumber);
test = [select id, Name from RFLEET_Protocol__c LIMIT 1];
PageReference vfpage = Page.Rfleet_Financial_Informations;
System.test.SetCurrentpage(vfpage);
Apexpages.currentPage().getparameters().put('id',test.id);
Apexpages.StandardController sc = new Apexpages.StandardController(test);
Rfleet_Financial_Informations fintest = new Rfleet_Financial_Informations(sc);
fintest.deleteRowEditAction();
fintest.id = acc.Id;
}
}
screenshot:
apex class:
public with sharing class Rfleet_Financial_Informations {
//Variable Declaration Parts
public List < RFLEET_Account_Protocol__c > contt {get;set;}
public List < EditableContact > myAssociatedContact {get;set;}
public Integer editableContactNumber {get;set;}
public Boolean refreshPage {get;set;}
public String protocolname {get;set;}
public String id;
//Constructor for invoking the Records from AccountProrocol Object
public Rfleet_Financial_Informations(ApexPages.StandardController stdCtrl) {
id = ApexPages.currentPage().getParameters().get('id');
myAssociatedContact = new List < EditableContact > ();
Integer counter = 0;
RFLEET_Protocol__c conn = [select name from RFLEET_Protocol__c where id = : id];
protocolname = conn.name;
contt = [select Name,Rfleet_Billing_Account__r.Name, Rfleet_Id_Alcor__c, Rfleet_Billing_Account_Type__c, Rfleet_Billing_Account__r.Rfleet_Street_Number__c, Rfleet_Billing_Account__r.Rfleet_Country__c, Rfleet_Billing_Account__r.Rfleet_Zip_Code__c, Rfleet_Billing_Account__r.Rfleet_State_Province__c, Rfleet_Billing_Account__r.Rfleet_City__c, Rfleet_Billing_Account__r.Rfleet_Street_Name__c from RFLEET_Account_Protocol__c where Rfleet_Protocol__c = : id];
for (RFLEET_Account_Protocol__c myContact: contt) {
myAssociatedContact.add(new EditableContact(myContact, false, counter));
counter++;
}
}
// This method is used for deleting the Row
public void deleteRowEditAction() {
try {
myAssociatedContact.get(editableContactNumber).editable = false;
delete(myAssociatedContact.get(editableContactNumber).myContact);
} catch (Exception e) {}
refreshPage = true;
}
public class EditableContact {
public RFLEET_Account_Protocol__c myContact {get;set;}
public Boolean editable {get;set;}
public Integer counterNumber {get;set;}
public EditableContact(RFLEET_Account_Protocol__c myContact, Boolean editable, Integer counterNumber) {
this.myContact = myContact;
this.editable = editable;
this.counterNumber = counterNumber;
}
}
}
test class:
@isTest
public class Rfleet_Financial_Informations_Test {
static testMethod void financialtest() {
Billing_Repository__c brc = new Billing_Repository__c(Name='frest',Rfleet_City__c='cger',Rfleet_Country__c='japan',Rfleet_Zip_Code__c='7854',CurrencyIsoCode='EUR');
Account acc = new Account(Name = 'cooluma',montant__c=0.2);
acc.Rfleet_Id_Alcor__c=brc.id;
acc.Rfleet_Street_Name__c ='gff';
acc.Rfleet_Street_Number__c ='232';
acc.Rfleet_Country__c ='fdffd';
acc.Rfleet_City__c ='cdfdf';
acc.Rfleet_State_Province__c ='dfdf';
acc.Rfleet_Zip_Code__c ='dfdfnhj';
insert acc;
acc.Name = 'vfggf';
update acc;
RFLEET_Protocol__c test = new RFLEET_Protocol__c(Name = 'prabu');
insert test;
test.Name = 'prabu';
update test;
RFLEET_Account_Protocol__c myContact = new RFLEET_Account_Protocol__c(Rfleet_Billing_Account__c = acc.Id, Rfleet_Billing_Account_Type__c = 'Vehicle', Rfleet_City__c =acc.Rfleet_City__c,Rfleet_Country__c =acc.Rfleet_Country__c, Rfleet_Id_Alcor__c = acc.Rfleet_Id_Alcor__c,
Rfleet_Protocol__c = acc.Id, Rfleet_State_Province__c =acc.Rfleet_State_Province__c , Rfleet_Street_name__c =acc.Rfleet_Street_Name__c, Rfleet_Street_number__c = acc.Rfleet_Street_Number__c, Rfleet_Zip_code__c =acc.Rfleet_Zip_Code__c);
string name = 'ListConditionCheck';
Boolean editable;
Integer counternumber;
Rfleet_Financial_Informations.editableContact wra = new Rfleet_Financial_Informations.EditableContact(mycontact, editable, counterNumber);
test = [select id, Name from RFLEET_Protocol__c LIMIT 1];
PageReference vfpage = Page.Rfleet_Financial_Informations;
System.test.SetCurrentpage(vfpage);
Apexpages.currentPage().getparameters().put('id',test.id);
Apexpages.StandardController sc = new Apexpages.StandardController(test);
Rfleet_Financial_Informations fintest = new Rfleet_Financial_Informations(sc);
fintest.deleteRowEditAction();
fintest.id = acc.Id;
}
}
screenshot:
- kiran k 12
- December 23, 2015
- Like
- 0
How to test for loop in test class?
I have wriiten a test class for apex class.i got 89% but for loop is not covered.please see the screenshot for clarification.how to cover' for loop' and improve code coverage?
apex class:
apex class:
public with sharing class Rfleet_Commericialcondition { //Variable Declaration Parts public List < RFLEET_Protocol_Grid__c > contt {get;set;} public List < EditableContact > myAssociatedContact {get;set;} public Integer editableContactNumber {get;set;} public Boolean refreshPage {get;set;} public String protocolname {get;set;} String id; //Constructor for invoking the Records from Protocol Grid Object public Rfleet_Commericialcondition(ApexPages.StandardController stdCtrl) { id = ApexPages.currentPage().getParameters().get('id'); myAssociatedContact = new List < EditableContact > (); Integer counter = 0; RFLEET_Protocol__c conn = [select name from RFLEET_Protocol__c where id = : id]; protocolname = conn.name; contt = [select id, Name, Rfleet_Type_of_Grid__c, Rfleet_Type_of_Sales__c, Rfleet_Protocol__c from RFLEET_Protocol_Grid__c where Rfleet_Protocol__r.name = : protocolname]; for (RFLEET_Protocol_Grid__c myContact: contt) { myAssociatedContact.add(new EditableContact(myContact, false, counter)); counter++; } } // This method is used for deleting the Row public void deleteRowEditAction() { try { myAssociatedContact.get(editableContactNumber).editable = false; delete(myAssociatedContact.get(editableContactNumber).myContact); } catch (Exception e) {} refreshPage = true; } public class EditableContact { public RFLEET_Protocol_Grid__c myContact {get;set;} public Boolean editable {get;set;} public Integer counterNumber {get;set;} public EditableContact(RFLEET_Protocol_Grid__c myContact, Boolean editable, Integer counterNumber) { this.myContact = myContact; this.editable = editable; this.counterNumber = counterNumber; } } }test class:
@isTest public class Rfleet_Commercialcondition_Test { @isTest Static void Testcommercial(){ RFLEET_Protocol_Grid__c myContact = new RFLEET_Protocol_Grid__c (Name='testing'); insert myContact; myContact.Rfleet_Input_Mode__c = 'manually'; update myContact; String Name = 'ListConditionCheck'; Boolean editable; Integer counterNumber; Boolean refreshPage; Integer editableContactNumber; Rfleet_Commericialcondition.EditableContact wra= new Rfleet_Commericialcondition.EditableContact(myContact, editable, counterNumber); RFLEET_Protocol__c test = new RFLEET_Protocol__c(Name='prabu'); insert test; test.Name = 'prabu'; update test; System.debug('Before Query'); RFLEET_Protocol__c myCondtest = new RFLEET_Protocol__c(); myCondtest = [select id,Name from RFLEET_Protocol__c LIMIT 1]; PageReference vfpage = Page.Rfleet_Commericialcondition; System.test.SetCurrentpage(vfpage); Apexpages.currentPage().getparameters().put('id',myCondtest.id); System.assertEquals(myCondtest.id,ApexPages.currentPage().getParameters().get('id')); Apexpages.StandardController sc = new Apexpages.StandardController(myCondtest); Rfleet_Commericialcondition commtest = new Rfleet_Commericialcondition(sc); commtest.deleteRowEditAction(); System.assertEquals('prabu',test.Name); } }
- kiran k 12
- December 22, 2015
- Like
- 1
Test class for @remoteaction
Recently i have written a test class for @remoteaction.i got 79% with error.how to resolve this error and improve code coverage?
apex class:
mockgenerator test class:
apex class:
global class Rfleet_Searchaddress { public String StNumber {get;set;} public String Bcity {get;set;} public String BPostalcode {get;set;} public String BCountry {get;set;} public String Snumber {get;set;} public String street {get;set;} public Boolean refreshPage {get;set;} string Id; list < Account > updateAdd = new list < Account > (); //This method is constructor public Rfleet_Searchaddress(ApexPages.StandardController controller) { id = ApexPages.currentPage().getParameters().get('id'); refreshPage = false; } //This method is autosave the addresses public void autosave() { for (Account updatelist: [SELECT id, Rfleet_Main_Address_Number__c, Rfleet_Main_address_Street__c, BillingAddress, BillingCity, BillingCountry, BillingPostalCode, BillingState, BillingStreet FROM Account where id = : id]) { updatelist.BillingStreet = Snumber + ' ' + street; //StNumber; updatelist.BillingCity = Bcity; updatelist.BillingPostalCode = BPostalcode; updatelist.BillingState = ''; updatelist.BillingCountry = BCountry; updatelist.Rfleet_Main_Address_Number__c = Snumber; updatelist.Rfleet_Main_address_Street__c = street; updateAdd.add(updatelist); } try{ update updateAdd; }catch(DmlException e) { system.debug('update--->' + updateAdd); } refreshPage = true; } //This method is remote action @RemoteAction global static list < String > restapi(string accName) { string jsonStr; Http h = new Http(); HttpRequest req = new HttpRequest(); req.setHeader('Accept', 'application/JSON'); req.setEndpoint('http://api-adresse.data.gouv.fr/search/?q=' + EncodingUtil.urlEncode(accName, 'UTF-8')); //+'&'+'limit'+'='+'10');// req.setMethod('GET'); HttpResponse res = h.send(req); system.debug('res1===>' + res.getBody()); List < String > calOut1 = new List < String > (); JSON2Apex parsed = JSON2Apex.parse(res.getBody()); for (JSON2Apex.Features f: parsed.Features) { JSON2Apex.Properties p = f.Properties; calOut1.add(p.label + ' ' + 'FRANCE'); } return calOut1; } }json2apex class:
public class JSON2Apex { public String query; public String version; public String licence; public List<Features> features; public String type; public String attribution; public class Geometry { public List<Double> coordinates; public String type; } public class Features { public Geometry geometry; public String type; public Properties properties; } public class Properties { public String city; public String label; public String id; public String postcode; public String name; public String citycode; public String context; public Double score; public String type; } public static JSON2Apex parse(String json) { return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class); } static testMethod void testParse() { String json = '{\"query\": \"8\", \"version\": \"draft\", \"licence\": \"ODbL 1.0\", \"features\": [{\"geometry\": {\"coordinates\": [5.600741, 43.28252], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"Aubagne\", \"label\": \"Route Nationale 8 13400 Aubagne\", \"id\": \"13005_XXXX_b0c6c8\", \"postcode\": \"13400\", \"name\": \"Route Nationale 8\", \"citycode\": \"13005\", \"context\": \"13, Bouches-du-Rh\\u00f4ne, Provence-Alpes-C\\u00f4te d\'Azur\", \"score\": 0.6540636363636363, \"type\": \"street\"}}, {\"geometry\": {\"coordinates\": [5.864773, 43.132774], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"Ollioules\", \"label\": \"Route Nationale 8 83190 Ollioules\", \"id\": \"83090_XXXX_a33650\", \"postcode\": \"83190\", \"name\": \"Route Nationale 8\", \"citycode\": \"83090\", \"context\": \"83, Var, Provence-Alpes-C\\u00f4te d\'Azur\", \"score\": 0.6526818181818181, \"type\": \"street\"}}, {\"geometry\": {\"coordinates\": [45.136426, -12.845884], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"Ouangani\", \"label\": \"Route D\\u00e9partementale 8 97670 Ouangani\", \"id\": \"97614_XXXX_704587\", \"postcode\": \"97670\", \"name\": \"Route D\\u00e9partementale 8\", \"citycode\": \"97614\", \"context\": \"976, Mayotte\", \"score\": 0.6507545454545454, \"type\": \"street\"}}, {\"geometry\": {\"coordinates\": [5.86687, 43.132284], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"Ollioules\", \"label\": \"Route Nationale 8 83190 Ollioules\", \"id\": \"83090_XXXX_9346fc\", \"postcode\": \"83190\", \"name\": \"Route Nationale 8\", \"citycode\": \"83090\", \"context\": \"83, Var, Provence-Alpes-C\\u00f4te d\'Azur\", \"score\": 0.6481181818181817, \"type\": \"street\"}}, {\"geometry\": {\"coordinates\": [3.242916, 43.379135], \"type\": \"Point\"}, \"type\": \"Feature\", \"properties\": {\"city\": \"B\\u00e9ziers\", \"label\": \"Chemin Rural 8 34500 B\\u00e9ziers\", \"id\": \"34032_XXXX_ddb1db\", \"postcode\": \"34500\", \"name\": \"Chemin Rural 8\", \"citycode\": \"34032\", \"context\": \"34, H\\u00e9rault, Languedoc-Roussillon\", \"score\": 0.6467545454545454, \"type\": \"locality\"}}], \"type\": \"FeatureCollection\", \"attribution\": \"BAN\"}'; JSON2Apex obj = parse(json); System.assert(obj != null); } }
mockgenerator test class:
@isTest global class Rfleet_MockHttpResponseGenerator_Test implements HttpCalloutMock { global HTTPResponse respond(HTTPRequest req) { // Optionally, only send a mock response for a specific endpoint // and method. System.assertEquals('http://api-adresse.data.gouv.fr/search/?q='+'france', req.getEndpoint()); System.assertEquals('GET', req.getMethod()); // Create a fake response HttpResponse res = new HttpResponse(); res.setHeader('Content-Type', 'application/json'); res.setBody('{"foo":"bar"}'); res.setStatusCode(200); return res; } }Test class:
@isTest public class Rfleet_Searchaddress_test { @isTest static void Testsearchaddress() { Account testAccount = new Account(Name='chinna',Montant__c=5); insert testAccount; testAccount.BillingStreet='chengalpattu'; update testAccount; Account myTestTrainee = [SELECT id From Account LIMIT 1]; PageReference myVfPage = Page.RFLEET_Searchaddress; system.test.setCurrentPage(myVfPage); ApexPages.currentPage().getParameters().put('id', myTestTrainee.id);//Pass Id to page ApexPAges.StandardController sc = new ApexPages.StandardController(myTestTrainee); Rfleet_Searchaddress apextestclass=new Rfleet_Searchaddress(sc); apextestclass.autosave(); String param ='Base Product'; RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); req.requestURI = 'http://api-adresse.data.gouv.fr/search/?q='; req.httpMethod = 'GET'; RestContext.request = req; RestContext.response = res; Rfleet_Searchaddress.restapi('jso'); Test.startTest(); Test.setMock(HttpCalloutMock.class, new Rfleet_MockHttpResponseGenerator_Test()); Test.stopTest(); } }
- kiran k 12
- December 21, 2015
- Like
- 0
outlook integration
when i syncing contacts between salesforce and outlook,i got a error.please rectify my error
- kiran k 12
- July 17, 2015
- Like
- 0
Integration
hello
I have one requirement is there.how to integrate salesforce with sap?anybody know this answer,please reply to me.
I have one requirement is there.how to integrate salesforce with sap?anybody know this answer,please reply to me.
- kiran k 12
- June 17, 2015
- Like
- 0