• James Gordon 10
  • NEWBIE
  • 55 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 6
    Replies
I would like to know what is happening with the Module Introduction to Catter... I hope you can help me!

Thanks
We have an existing org with person accounts enabled.  Recently, several unit tests have started failing with this error: 
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Can not select a person account: [AccountId] 
Stack Trace: Class.ContactTriggerTest.testContactLeadMerge_Success: line 18, column 1

Based on other threads, it seems that manipulating contacts is no longer allowed for person accounts.  We'll have to rework quite a bit of code.

My issue is that this error does not occur in sandboxes.  Is that expected?  We have created a brand-new dev sandbox, and the failing tests run fine.

Here's the unit test that works fine in the sandboxes, but not in production:
 
@isTest
private class ContactTriggerTest{
                 
    private static testMethod void testContactLeadMerge_Success() {
        Lead lead = new Lead(Lastname = 'testdata', Firstname = 'testdata1', Email = 'test@test.com');
        insert lead;
    
        //Inserting a person acct creates a contact. But it wouldn't fire the contact trigger
        //We'll leave this here as a general test that other triggers are firing fine.
        Account person = new Account(LastName = 'person', PersonEmail = 'test@test.com', OwnerId = Userinfo.getUserid());
        insert person;
        
        //Not sure of the purpose of below line?
        //update [SELECT Id FROM Contact];
    
        //Inserting a generic contact solely to fire the trigger
        Contact contact = new Contact(Lastname = 'testdata', Firstname = 'testdata1', Email = 'test@test.com', OwnerId = Userinfo.getUserid());
        insert contact;
        
        //System.assertEquals(2, [SELECT Id FROM Contact].size());
        System.assertEquals(0, [SELECT Id FROM Lead WHERE IsConverted = false].size());
    }
}

And here's the error:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Can not select a person account: [AccountId] 
Stack Trace: Class.ContactTriggerTest.testContactLeadMerge_Success: line 18, column 1



Needless to say, it's very frustrating to adjust a class and upload for deployment, only to find that production has a specific error that the sandboxes don't.  Any advice on how to get this error to show in the sandbox, or why they are different?

Lastly, is there some way to get production working again by sidestepping this issue?  I've tried downgrading the API version of the class to 35, but no luck.  Thoughts?
In the session last night, there was a live demo of customizing the hoem page components.  But in TrailHead there's this disclaimer...  "You can’t customize the layout of the Home page, add custom components, or move related lists.", with no follow up about when it will be available like I've seen for other disclaimers.

So what's the real story with customizing the home page?
I would like to know what is happening with the Module Introduction to Catter... I hope you can help me!

Thanks
I'm working on Trailhead Challenge to Create a flow to streamline entry of new accounts, contacts, and opportunities.

I've got a screen with:
  • First Name
  • Last Name
  • Company Name
  • Opportunity Amount
  • Opportunity Stage

Then Record Create to Create Account:
  • Name = Company Name
  • Variable AccountId

Then Record Create to Create Contact:
  • FirstName = First Name
  • LastName = Last Name
  • AccountId = AccountID

Then Record Create to Create Opp:
  • Name = Company Name (Can i use formula for Company_Name + "-" + Last_Name?)
  • CloseDate = Flow.CurrentDate (can I use Flow.CurrentDate + 30?)
  • AccountId = AccountID
  • StageName = Prospecting
  • Amount = Opportunity_Amount

The flow saves. But when I run it and enter info, I get error:
"An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information."


At first, I thought it was because my formula weren't working to concatanate company name and last name, or to add 30 days to date for close date. But even when I remove the formulas and just use the screen fields, I get the same error.

What am I doing wrong?
 

Hi ,

 

Can any once face this problem when we executin some code using developer console the log will not open.

 

Any one face this problem.

 

Thank you

  • November 15, 2013
  • Like
  • 0

Thinking of enabling #Communities for your customer? Then be aware of the current #Gotcha that the default Apex Classes that are created when you enable your first Community do not ALL have code coverage >75%.

What this means:
You can enable Communities in Production, however as soon as you attempt to migrate anything from a sandbox into Production that triggers all tests to be run (doesn't have to be just code), your migration will fail as three of the classes only have 33%, 20% and 21%.

Let me repeat that, you might only be migrating a bunch of new custom fields and page layouts and the Change Set (or Eclipse/ANT) will fail.

I hit this problem this week in a go-live deployment so had to update Apex Classes to achieve average total code coverage >75% in order to proceed with our deployment.

The PM of Communities knows about the problem and advises he is looking at a fix, but in the meantime here are the four Apex Classes that need to be updated.

 

CommunitiesLandingControllerTest.cls

Just a one liner for this test class

/**
 * An apex page controller that takes the user to the right start page based on credentials or lack thereof
 */
@IsTest public with sharing class CommunitiesLandingControllerTest {
  @IsTest(SeeAllData=true) public static void testCommunitiesLandingController() {
    // Instantiate a new controller with all parameters in the page
    CommunitiesLandingController controller = new CommunitiesLandingController();

    // 25-Jun-2013 Manu Erwin - Fixing insufficient code coverage for default Communities Apex Tests
    PageReference pageRef = controller.forwardToStartPage();
  }
}

 

CommunitiesLoginControllerTest.cls

Just a one liner for this test class

/**
 * An apex page controller that exposes the site login functionality
 */
@IsTest global with sharing class CommunitiesLoginControllerTest {
  @IsTest(SeeAllData=true) 
  global static void testCommunitiesLoginController () {
    CommunitiesLoginController controller = new CommunitiesLoginController ();

    // 25-Jun-2013 Manu Erwin - Fixing insufficient code coverage for default Communities Apex Tests
    PageReference pageRef = controller.forwardToAuthPage();
  }  
}

 

CommunitiesSelfRegControllerTest.cls

A few controller variables to set prior to calling the controller method for the original test method, followed by a couple of additional test methods for further coverage.

/**
 * An apex page controller that supports self registration of users in communities that allow self registration
 */
@IsTest public with sharing class CommunitiesSelfRegControllerTest {
  @IsTest(SeeAllData=true) 
  public static void testCommunitiesSelfRegController() {
    CommunitiesSelfRegController controller = new CommunitiesSelfRegController();

    // 25-Jun-2013 Manu Erwin - Fixing insufficient code coverage for default Communities Apex Tests
    controller.firstName = 'Bob';
    controller.lastName = 'Jones';
    controller.email = 'bob@jones.com';
    controller.password = '8yhMsHDN&ituQgO$WO';
    controller.confirmPassword = '8yhMsHDN&ituQgO$WO';
    controller.communityNickname = 'bob-jones-testing';

    PageReference pageRef = controller.registerUser();
  }
  // 25-Jun-2013 Manu Erwin - Fixing insufficient code coverage for default Communities Apex Tests
  @IsTest(SeeAllData=true) 
  public static void testInvalidPassword() {
    CommunitiesSelfRegController controller = new CommunitiesSelfRegController();
    controller.firstName = 'Bob';
    controller.lastName = 'Jones';
    controller.email = 'bob@jones.com';
    controller.password = '8yhMsHDN&ituQgO$WO';
    controller.confirmPassword = 'not the same';
    controller.communityNickname = 'bob-jones-testing';

    PageReference pageRef = controller.registerUser();
    System.assert(pageRef == null, 'The returned page reference should be null');
  }
  // 25-Jun-2013 Manu Erwin - Fixing insufficient code coverage for default Communities Apex Tests
  @IsTest(SeeAllData=true) 
  public static void testNullPassword() {
    CommunitiesSelfRegController controller = new CommunitiesSelfRegController();
    controller.firstName = 'Bob';
    controller.lastName = 'Jones';
    controller.email = 'bob@jones.com';
    controller.communityNickname = 'bob-jones-testing';

    PageReference pageRef = controller.registerUser();
    System.assert(pageRef == null, 'The returned page reference should be null');
  }
}

 

CommunitiesSelfRegController.cls

A few additions to this class to set the Profile and Account Ids for portal user creation. Update the ProfileId value based on the "portal" license(s) (e.g., Customer Portal, Customer Community, etc) and set the AccountId to that of the Account you wish to use for self-registration. Note: this needs to be set even if you're not using self-registration so the class can be tested.

Plus some debug statements so I could see what was happening and needed to be tested.

/**
 * An apex page controller that supports self registration of users in communities that allow self registration
 */
public with sharing class CommunitiesSelfRegController {

  public String firstName {get; set;}
  public String lastName {get; set;}
  public String email {get; set;}
  public String password {get; set {password = value == null ? value : value.trim(); } }
  public String confirmPassword {get; set { confirmPassword = value == null ? value : value.trim(); } }
  public String communityNickname {get; set { communityNickname = value == null ? value : value.trim(); } }
  
  public CommunitiesSelfRegController() {}
  
  private boolean isValidPassword() {
    return password == confirmPassword;
  }

  public PageReference registerUser() {
  
    // it's okay if password is null - we'll send the user a random password in that case
    if (!isValidPassword()) {
      System.debug(System.LoggingLevel.DEBUG, '## DEBUG: Password is invalid - returning null');
      ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.site.passwords_dont_match);
      ApexPages.addMessage(msg);
      return null;
    }  

    // 25-Jun-2013 Manu Erwin - Fixing insufficient code coverage for default Communities Apex Tests
    //String profileId = ''; // To be filled in by customer.
    //String roleEnum = ''; // To be filled in by customer.
    //String accountId = ''; // To be filled in by customer.

    // Set this to your main Communities Profile API Name
    String profileApiName = 'PowerCustomerSuccess';
    String profileId = [SELECT Id FROM Profile WHERE UserType = :profileApiName LIMIT 1].Id;
    List<Account> accounts = [SELECT Id FROM Account LIMIT 1];
    System.assert(!accounts.isEmpty(), 'There must be at least one account in this environment!');
    String accountId = accounts[0].Id;
    
    String userName = email;

    User u = new User();
    u.Username = userName;
    u.Email = email;
    u.FirstName = firstName;
    u.LastName = lastName;
    u.CommunityNickname = communityNickname;
    u.ProfileId = profileId;
    
    String userId = Site.createPortalUser(u, accountId, password);
   
    if (userId != null) { 
      if (password != null && password.length() > 1) {
        System.debug(System.LoggingLevel.DEBUG, '## DEBUG: User creation successful and password ok - returning site.login');
        return Site.login(userName, password, null);
      }
      else {
        System.debug(System.LoggingLevel.DEBUG, '## DEBUG: User creation successful but password not ok - redirecting to self reg confirmation');
        PageReference page = System.Page.CommunitiesSelfRegConfirm;
        page.setRedirect(true);
        return page;
      }
    }
    System.debug(System.LoggingLevel.DEBUG, '## DEBUG: User creation not successful - returning null');
    return null;
  }
}

 

 

Hello,

 

what am I doing wrong here on line 12  

     for(RecordType rt: AccrTypes(

I get the following error

 

    Error: Compile Error: expecting right curly bracket, found 'for' at line 12 column 3

public with sharing class CreateSampleData{

   //Query for the Account record types
     List<RecordType> AccrTypes = [Select Name, Id From RecordType
                  where sObjectType='Account' and isActive=true];

   //Query for the Contact record types
     List<RecordType> Cntrtypes = [Select Name, Id From RecordType
                  where sObjectType='Contact' and isActive=true];  
                  
   //Create recors
   for(RecordType rt: AccrTypes){}

}

 I have written code before this one I cannot tell what the problem is...