public pagereference savePassword()
{
if((objAccountTemp.Contact_Name_1__c != null && objAccountTemp.Contact_Name_1__c != '' && objAccountTemp.Affiliate_User_Name__c != null && objAccountTemp.Affiliate_User_Name__c != '')){
if(objAccountTemp.Affiliate_User_Name__c == objAccountTemp.Contact_Name_1__c){
If(LoginType == 'affiliate')
{
String s = objAccountTemp.Contact_Name_1__c;
Account acc = new Account();
acc=[select Affiliate_Password__c from Account where id=:Affid limit 1];
acc.Affiliate_Password__c = s;
try{
update acc;
changePasswordMsg = true;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Your password changed successfully!'));
IsEditMode = false;
IsSaveMode = true;
changePass = false;
lstAcc[0].Affiliate_Password__c = s;
changePassErrormsg = false;
return null;
}catch(exception e){
L4LConstants.InsertErrorLog(e);
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Error Found!'));
return null;
}
}
}
}
}
-
1try updating an Account record which doesn't exist. So it'll enter the catch block with DMLException– PoonamApr 13, 2015 at 6:06
-
Not sure why you have hardcoded zero for lstAcc. As a best practice, you would want to do a null and empty check on the list unless you are really sure that it would not be null and empty. We dont see how lstAcc is initialized in the code that you have shared. Try a scenario where lstAcc does not get any records and you code will definitely break and enter the catch block.– Rajiv BhattApr 13, 2015 at 6:20
-
Can we see the test code you've already written ? You haven't really explained why you have a hard time covering this in your test code, which sort of means you haven't really asked a question.– Samuel De RyckeApr 13, 2015 at 7:46