You need to sign in to do that
Don't have an account?
111
Boolean updateFlg = true;
Database.SaveResult[] SR = database.update(opportunityList,false);
can someone help me to test the Exception?
global class gg {
WebService static Boolean updateDB(OpportunityLineItem[] opportunityList) {
WebService static Boolean updateDB(OpportunityLineItem[] opportunityList) {
Boolean updateFlg = true;
Database.SaveResult[] SR = database.update(opportunityList,false);
for(Database.SaveResult lsr:SR){
if(!lsr.isSuccess()){
updateFlg = false;
break;
}
}
}
return updateFlg;
}
static testMethod void updateDB() {
OpportunityLineItem[] opportunityList = null;
opportunityList = [select mitosakuban__c from OpportunityLineItem];
for (OpportunityLineItem opportunity : opportunityList) {
opportunity.mitosakuban__c = '';
}
System.assertEquals(false, updateDB(opportunityList ));
}
}
break;
}
}
}
return updateFlg;
}
static testMethod void updateDB() {
OpportunityLineItem[] opportunityList = null;
opportunityList = [select mitosakuban__c from OpportunityLineItem];
for (OpportunityLineItem opportunity : opportunityList) {
opportunity.mitosakuban__c = '';
}
System.assertEquals(false, updateDB(opportunityList ));
}
}
how can i make the method (database.update(opportunityList,false)) to be error,how can i test it ?
now my coverage can't be 100%?can someone can give a testmethode?
Thankyou
now my coverage can't be 100%?can someone can give a testmethode?
Thankyou
pass that into your method under test, it should fail in the update statement and throw an error.
WebService static Boolean updateDB(OpportunityLineItem opportunityList) {
Boolean updateFlg = true;
try{
update opportunityList;
}catch (Exception e){
updateFlg = false;
}
return updateFlg;
}
static testMethod void updateDB() {
OpportunityLineItem oli = new OpportunityLineItem(opportunityid='fff',pricebookentryid='123', unitprice=1.5,quantity=2);
System.assertEquals(false, updateDB(oli ));
}
}
" error [System.StringException:Invalid id:fff] is appeared.