You need to sign in to do that
Don't have an account?
kumar7
Test class failed
Hi All,
For this peace of apex class code i have written
newPortalUser.UserName = newPortalUser.Email + '.portal';
string acctnum=[select accountnumber from account where id =:currentUser.Contact.Accountid].accountnumber;
if(acctnum == null){
newPortalUser.CommunityNickname = currentUser.Contact.AccountID +'_' + newPortalUser.FirstName + newPortalUser.LastName;
}else {
newPortalUser.CommunityNickname = acctnum +'_' + newPortalUser.FirstName + newPortalUser.LastName;
}
For this i have written test class
========================
Account acc = new Account (AccountNumber = '123', Name = 'Testing');
insert acc;
But i am getting error while execution of test class
Error:-
System.QueryException: List has no rows for assignment to SObject
Thanks in adv
For this peace of apex class code i have written
newPortalUser.UserName = newPortalUser.Email + '.portal';
string acctnum=[select accountnumber from account where id =:currentUser.Contact.Accountid].accountnumber;
if(acctnum == null){
newPortalUser.CommunityNickname = currentUser.Contact.AccountID +'_' + newPortalUser.FirstName + newPortalUser.LastName;
}else {
newPortalUser.CommunityNickname = acctnum +'_' + newPortalUser.FirstName + newPortalUser.LastName;
}
For this i have written test class
========================
Account acc = new Account (AccountNumber = '123', Name = 'Testing');
insert acc;
But i am getting error while execution of test class
Error:-
System.QueryException: List has no rows for assignment to SObject
Thanks in adv
Thanks for your update. But i am getting different error
Error MessageSystem.QueryException: List has no rows for assignment to SObject
Logic i have written like this:
User portalUser;
portalUser.UserName = portalUser.Email + '.portal';
list<Account> accs =[select accountnumber from account where id =:portalUser.Contact.Accountid limit 1];
if( Accs.Size()== 0){
portalUser.CommunityNickname = portalUser.Contact.AccountID +'_' + portalUser.FirstName + portalUser.LastName;
}else {
portalUser.CommunityNickname = accs[0].accountnumber +'_' + portalUser.FirstName + portalUser.LastName;
}
Thanks