You need to sign in to do that
Don't have an account?
Dorian Kane 5
problem on test to pass and fix apex for deploy
hello i need help to fix this code to pass it on deploy
This is the apex clas i need to deploy MyProfilePage Controller
test Save
System.QueryException: List has no rows for assignment to SObject
Stack Trace: Class.MyProfilePage Controller.test Save: line 78, column 1 this thow a erron on : line 78, column 1
i have open dhe dev console and the problem shows
/** * An apex class that keeps updates of a portal user in sync with its corresponding contact. Guest users are never able to access this page. */ public class MyProfilePageController { private User user; private boolean isEdit = false; public User getUser() { return user; } public MyProfilePageController() { user = [SELECT id, email, username, usertype, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title, street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, contact.email FROM User WHERE id = :UserInfo.getUserId()]; // guest users should never be able to access this page if (user.usertype == 'GUEST') { throw new NoAccessException(); } } public Boolean getIsEdit() { return isEdit; } public void edit() { isEdit=true; } public void save() { if (user.contact != null) { setContactFields(user.contact); } try { update user; if (user.contact != null) { update user.contact; } isEdit=false; } catch(DmlException e) { ApexPages.addMessages(e); } } public PageReference changePassword() { return Page.ChangePassword; } public void cancel() { isEdit=false; user = [SELECT id, email, username, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title, street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, contact.email FROM User WHERE id = :UserInfo.getUserId()]; } private void setContactFields(Contact c) { c.title = user.title; c.firstname = user.firstname; c.lastname = user.lastname; c.email = user.email; c.phone = user.phone; c.mobilephone = user.mobilephone; c.fax = user.fax; c.mailingstreet = user.street; c.mailingcity = user.city; c.mailingstate = user.state; c.mailingpostalcode = user.postalcode; c.mailingcountry = user.country; } static testMethod void testSave() { // Modify the test to query for a portal user that exists in your org User existingPortalUser = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess' LIMIT 1]; System.assert(existingPortalUser != null, 'This test depends on an existing test portal user to run'); String randFax = Math.rint(Math.random() * 1000) + '5551234'; System.runAs(existingPortalUser) { MyProfilePageController controller = new MyProfilePageController(); System.assertEquals(existingPortalUser.Id, controller.getUser().Id, 'Did not successfully load the current user'); System.assert(controller.isEdit == false, 'isEdit should default to false'); controller.edit(); System.assert(controller.isEdit == true); controller.cancel(); System.assert(controller.isEdit == false); controller.getUser().Fax = randFax; controller.save(); System.assert(controller.isEdit == false); } // verify that the user and contact were updated existingPortalUser = [Select id, fax, Contact.Fax from User where id =: existingPortalUser.Id]; System.assert(existingPortalUser.fax == randFax); System.assert(existingPortalUser.Contact.fax == randFax); } }
:Defining type for testMethod methods must be declared as IsTest
I dont have experient in apex and i need help
Thanks
You need to wrap your test method in the class like below and you cannot use method directly .. Every method must be inside the test class
Past this code
All Answers
hello there
Raj Vakati
im reciving some erron on the tes class :Unexpected token 'void'. at Line 1
do you have any idea about this that can help me
You need to wrap your test method in the class like below and you cannot use method directly .. Every method must be inside the test class
Past this code