• jhittleman
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 6
    Replies

With Winter '11, if you create a Site, a new Salesforce-provided class gets deployed to your org: MyProfilePageController.cls

 

There is test code in this class that fails if you don't have a portal user installed. This prevents you from doing anything in that org that requires running all tests.

 

Here is the error:

 

System.QueryException: List has no rows for assignment to SObject

Class.MyProfilePageController.testSave: line 78, column 35 External entry point

 

and the line in question:

 

 

User existingPortalUser = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess' LIMIT 1];

 

This failure prevents doing any save from Eclipse. You can't deploy new code, edit object metadata files, etc. Complete showstopper.

 

Can anyone:

 * confirm this (we think reproducing will require that you create a new Site, perhaps the first Site in the org, after Winter 11)

 * think of a work-around (tried enabling self-service portal, but it doesn't create the required user type)

 

Anyone from Salesforce confirm that this is a bug and not something we're doing wrong?

 

Thanks!

 

Here is the entire class:

 

/**
 * 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);
    }

}

 

 

 

  • October 15, 2010
  • Like
  • 0

Hey ho,

 

I am striving problems while trying to install Smart Follow. I enabled chatter and then tried to install the app via the AppExchange.

 

The installer fails with this error:

 

 

Problem:

1. Apex Classes(01p20000000TZcU) chatterfollowrules.testFollowDepartment();
chatterfollowrules.testFollowEveryone();
chatterfollowrules.testFollowManagerHierarchy();
chatterfollowrules.testFollowProfile();
chatterfollowrules.testFollowRole();
chatterfollowrules.testTeamfollowRule()
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowRules.testFollowDepartment: line 819, column 13 External entry point;
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowRules.testFollowEveryone: line 627, column 13 External entry point;
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowRules.testFollowManagerHierarchy: line 474, column 13 External entry point;
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowRules.testFollowProfile: line 759, column 13 External entry point;
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowRules.testFollowRole: line 667, column 13 External entry point;
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowRules.testTeamfollowRule: line 403, column 13 External entry point

2. Apex Classes(01p20000000TZcO) chatterfollowbatchcaller.testchatterFollowBatchCaller()
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowBatchCaller.updateSettings: line 58, column 4
Class.chatterFollowBatchCaller.testchatterFollowBatchCaller: line 128, column 3 External entry point



Validation Errors While Saving Record(s)

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "00D200000000NNy: APEX_TEST_FAILED [01p20000000TZcU: chatterfollowrules.testFollowDepartment();
chatterfollowrules.testFollowEveryone();
chatterfollowrules.testFollowManagerHierarchy();
chatterfollowrules.testFollowProfile();
chatterfollowrules.testFollowRole();
chatterfollowrules.testTeamfollowRule(): System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowRules.testFollowDepartment: line 819, column 13 External entry point;
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowRules.testFollowEveryone: line 627, column 13 External entry point;
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowRules.testFollowManagerHierarchy: line 474, column 13 External entry point;
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowRules.testFollowProfile: line 759, column 13 External entry point;
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowRules.testFollowRole: line 667, column 13 External entry point;
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowRules.testTeamfollowRule: line 403, column 13 External entry point, 01p20000000TZcO: chatterfollowbatchcaller.testchatterFollowBatchCaller(): System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []
Class.chatterFollowBatchCaller.updateSettings: line 58, column 4
Class.chatterFollowBatchCaller.testchatterFollowBatchCaller: line 128, column 3 External entry point]".

 

 

 

And when I choose to install the app with "Ignore Tests" I cannot create follow rules;

 

 

Visualforce Page: /apex/chatterFollow



caused by: System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D200000000NNy: []

Class.chatterFollowBatchCaller.updateSettings: line 58, column 4 External entry point

 

We are on EMEA. I can send my org. ID via PM if needed.

 

 

So, looks like I am not taking Chatter live today :(

 

Cheers,

Hannes

Hi All,

 

I have a requirement to insert Account Team member when there is an update on account. While inserting the Account Team member I am not able to specify access level for Account. I am getting the below error -

Field is not writeable: AccountTeamMember.AccountAccessLevel.

 

Below is my code:

 

 

trigger AccountTeam on Account (after update) { for(Account a:trigger.new) { AccountTeamMember Teammemberad=new AccountTeamMember(); Teammemberad.AccountId=a.id; Teammemberad.UserId='00580000001nhJT'; Teammemberad.TeamMemberRole = 'Account Manager'; Teammemberad.AccountAccessLevel= 'Read'; insert Teammemberad; } }

 

Also I need to specify access levels for Contact, Opportunity and Cases for which I am not able to find out.

Any suggestion on this will be of great help!!!

 

Thanks in advance!!

 

 

 

 

 

  • December 03, 2009
  • Like
  • 0