• Manu Erwin
  • NEWBIE
  • 55 Points
  • Member since 2005

  • Chatter
    Feed
  • 2
    Best Answers
  • 7
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 45
    Replies
Is it possible to add an animation (gif) to the actionStatus attribute as I haven't been able to figure this one out. Text is okay but an animation would be much more ideal as it gives the user visual feedback that something is happening.

If a controller is performing heavy logic there may be a delay before something happens and if there is only static text that says "Retriving data..." the user doesn't know if the page is frozen or if it is actually doing something. An animation at least gives the user the perception that something is happening and therefore user is less likely to assume some this wrong and is more likely to wait rather than hit the back button, call me, and say, "Hey, its not working!"

If this is possible great! But please point me in the right direction. If not, I think the easiest way would to have an attribute in the actionStaus component that pointed to a static resource that is an image.

<apex:actionStatus image="{!$Resource.SpinnerImage}" id="status"/>

Ideally the page would also precache this image so that when displayed it would be all loaded up, no stuttering.
  • February 20, 2008
  • 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;
  }
}

 

 

Anyone know why setting Case.Status inside a loop using format() works, while attempting to set EmailMessage.Status inside a loop using format() fails?

 

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OPERATION, operation is not allowed: []

 

public class testingForLoopProblem {
    public testingForLoopProblem() {}

    @isTest static void Case_ForLoop_Success_Test() {
        Account acc01 = new Account(Name = 'success');
        insert acc01;

        Integer NUM_RECORDS = 6;
        List<Case> cases = new List<Case>();
        for (Integer counter = 0; counter < NUM_RECORDS; counter++){
            Case caseTemp = new Case();
            caseTemp.AccountId = acc01.Id;
            caseTemp.Subject = 'Test: : ' + counter;

            // Why does this work?
            caseTemp.Status = counter.format();

            cases.add(caseTemp);
        }
        insert cases;
    }

    @isTest static void EmailMessage_ForLoop_Fail_Test() {
        Account acc01 = new Account(Name = 'fail');
        insert acc01;
        Case case01 = new Case(AccountId = acc01.Id);
        insert case01;
        Integer NUM_RECORDS = 6;
        List<EmailMessage> emails = new List<EmailMessage>();
        for (Integer counter = 0; counter < NUM_RECORDS; counter++){
            EmailMessage email = new EmailMessage();
            email.ParentId = case01.Id;

            // Why does this NOT work?
            email.Status = counter.format();

            emails.add(email);
        }
        insert emails;
    }
}

 API Version 27.

I have a VF page that displays a result set of "ObjectA" records based on various filter criteria.

I need to associate these records to an "ObjectB" record however the "ObjectB" record does NOT have any other object referencing it within my org (i.e., there are no 'Lookup' fields to ObjectB anywhere).

 

I do NOT want to pollute my real objects (i.e., ones that contain data) with a Lookup to ObjectB just to get my VF page to work so my workaround has been to create a 'Utility Object' which does have a Lookup to ObjectB.  Then all I need to do is instantiate a Utility__c record and make use of the lookup to bind my apex:inputField to.

 

It would be great however if there was a way to create this on the fly in my controller to be bound to.

 

I know I 'could' rebuild the lookup functionality OR I 'could' make the selection of the ObjectB record be part of a multistep wizard however I'd prefer to make use of the standard Lookup functionality as bound to the apex:inputField tag AND not need a Utility Object.

 

Suggestions?

 

Before I go reinventing the wheel has anyone ever built a Visualforce page that shows a list of Accounts with list of Opportunities with list of Opportunity Lines?
I'm thinking of nested datatables and realise I'll likely have to do some heavy lifting in code to achieve due to the 1 level limitation with SOQL queries.
Sample code would be appreciated.
thanks,
Manu

 

I need to pre-default the Related To field in tasks and events to the Contact's Account Id.

It's working when I've overridden 'New Task' and 'New Event', however when I try much the same thing with the 'Log a call' and 'Send an Email' functions my s-control has an error.

Successful s-control for overriding 'New Task' making use of URLFOR functionality.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/13.0/connection.js"></script>
<script type="text/javascript" >
function redirectToRecord() {
var newURL = "{!URLFOR($Action.Task.NewTask, null, [who_id=Contact.Id, what_id=Account.Id, retURL=URLFOR($Action.Contact.View, Contact.Id)], true)}";
parent.frames.location.replace(newURL);
}
</script>
</head>
<body onload="redirectToRecord();">
</body>
</html>

Unsuccessful s-control for overriding 'Log a Call' making use of URLFOR functionality.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/13.0/connection.js"></script>
<script type="text/javascript" >
function redirectToRecord() {
var newURL = "{!URLFOR($Action.Activity.LogCall, null, [who_id=Contact.Id, what_id=Account.Id, retURL=URLFOR($Action.Contact.View, Contact.Id)], true)}";
parent.frames.location.replace(newURL);
}
</script>
</head>
<body onload="redirectToRecord();">
</body>
</html>

This causes the s-control to run twice? and the browser URL ends up with an error: https://cs2.salesforce.com/servlet/servlet.Integration?lid=01NR00000004SFO&ic=1#Error! that seems to thankfully prevent it from looping infinitely.

Any suggestions about what I should try?

Note: the Send an Email s-control is almost the same as above but with the different action of course.


Message Edited by manu on 08-13-2008 04:05 PM

Message Edited by manu on 08-13-2008 04:05 PM
I am able to apply styles to a number of elements in my visualforce page however I am unable to get the headerClass or headerClassActive attributes working properly. The contentClass works fine but the others don't.

Does anyone have suggestions on what I'm missing? Apologies in advance for the terrible colours - I'm using them for easier identification of what's working/failing.
Code:
/* generic html selectors */
body
{
 font: 75% tahoma, sans-serif;
 color: white;
 background-color: grey
}
p
{
 background-color: orange;
 color: yellow;
}
/* specific salesforce class selectors */
.header
{
 background-color: grey;
 color: black
}
.active
{
 background-color: white;
 color: pink
}

 
Code:
<apex:page id="styleClassProblem" label="styleClassProblem" name="styleClassProblem" showHeader="false" sidebar="false" standardStylesheets="false">
 <apex:stylesheet id="theStylesheet" value="{!$Resource.styleSheet}"/>
 This text correctly inherits the body style
 <apex:panelGrid id="thePanelGrid" columns="2" width="100%">
  <apex:panelGroup id="thePanelGroup">
   <apex:panelBar id="thePanelBar" height="200px" width="350px" headerClass="header" headerClassActive="active">
    <apex:panelBarItem id="firstPanelBarItem" label="first" name="first" contentClass="header">
     The panelbar above should inherit the 'active' style
     <p></p>
     This text correctly inherits the header style for content
     <p>This paragraph correctly inherits the p style</p>
     <apex:outputText value="This outputText apex tag correctly inherits the 'active' style class" styleClass="active"/>
    </apex:panelBarItem>
    <apex:panelBarItem id="secondPanelBarItem" label="second" name="second">
     The panelbar above should initially inherit the 'header' style and then when viewed the 'active' style
     <p></p>
     This text does not inherit the body style
     <p></p>
     <apex:outputText value="This outputText apex tag correctly inherits the 'header' style class" styleClass="header"/>
    </apex:panelBarItem>
   </apex:panelBar>
  </apex:panelGroup>
 </apex:panelGrid>
</apex:page>

EDIT: Added picture


thanks in advance,
manu



Message Edited by manu on 02-07-2008 11:20 AM
I'm wanting to embed an iframe in a visualforce page that will display content from another system by passing a salesforce external id. Is it possible to dynamically alter the 'src' attribute for an iframe?

OR do I have to do this another way e.g., use javascript to alter the object

onclick="document.getElementById('myFrame').src='new url';"

thanks,
manu


Message Edited by manu on 02-01-2008 12:35 PM

Message Edited by manu on 02-01-2008 12:35 PM
The Apex Pages component reference for 'scontrol' states for the 'Width' Integer attribute:
The width of the inline frame that should display the s-control, expressed either as a percentage of the total available horizontal space (for example width="80%"), or as the number of pixels (for example, width="600px").
When I attempt to set width="100%" I recieve the following error:
Error: Cannot coerce '100%' to class java.lang.Integer
Either the documentation is wrong or the conversion behind the scenes is not taking into account percentages.

For the moment I'm setting my width attribute to px but a percentage for width would be ideal.
I have a large number of IP ranges that need to be associated with a large number of profiles and I am searching for a way to automate this vs the tedious (and possibly wrist injury producing) manual method.
 
I have not seen any references to this within the application, the help OR this board. Nor have I seen anything within the API (viewed from Eclipse).
 
Any suggestions?
 
manu
I can locate the "Start of Day" and "End of Day" fields on the User object in both my Developer and Enterprise editions, and they are visible in my Developer "Manage Users" view however they are NOT visible in the "Manage Users" view in the Enterprise Edition.

I have not been able to find a way to alter the layout for "Manage Users" so am puzzled.

Is this the case for all Enterprise Editions? or just mine?

Help.

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;
  }
}

 

 

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;
  }
}

 

 

Anyone know why setting Case.Status inside a loop using format() works, while attempting to set EmailMessage.Status inside a loop using format() fails?

 

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OPERATION, operation is not allowed: []

 

public class testingForLoopProblem {
    public testingForLoopProblem() {}

    @isTest static void Case_ForLoop_Success_Test() {
        Account acc01 = new Account(Name = 'success');
        insert acc01;

        Integer NUM_RECORDS = 6;
        List<Case> cases = new List<Case>();
        for (Integer counter = 0; counter < NUM_RECORDS; counter++){
            Case caseTemp = new Case();
            caseTemp.AccountId = acc01.Id;
            caseTemp.Subject = 'Test: : ' + counter;

            // Why does this work?
            caseTemp.Status = counter.format();

            cases.add(caseTemp);
        }
        insert cases;
    }

    @isTest static void EmailMessage_ForLoop_Fail_Test() {
        Account acc01 = new Account(Name = 'fail');
        insert acc01;
        Case case01 = new Case(AccountId = acc01.Id);
        insert case01;
        Integer NUM_RECORDS = 6;
        List<EmailMessage> emails = new List<EmailMessage>();
        for (Integer counter = 0; counter < NUM_RECORDS; counter++){
            EmailMessage email = new EmailMessage();
            email.ParentId = case01.Id;

            // Why does this NOT work?
            email.Status = counter.format();

            emails.add(email);
        }
        insert emails;
    }
}

 API Version 27.

I have a VF page that displays a result set of "ObjectA" records based on various filter criteria.

I need to associate these records to an "ObjectB" record however the "ObjectB" record does NOT have any other object referencing it within my org (i.e., there are no 'Lookup' fields to ObjectB anywhere).

 

I do NOT want to pollute my real objects (i.e., ones that contain data) with a Lookup to ObjectB just to get my VF page to work so my workaround has been to create a 'Utility Object' which does have a Lookup to ObjectB.  Then all I need to do is instantiate a Utility__c record and make use of the lookup to bind my apex:inputField to.

 

It would be great however if there was a way to create this on the fly in my controller to be bound to.

 

I know I 'could' rebuild the lookup functionality OR I 'could' make the selection of the ObjectB record be part of a multistep wizard however I'd prefer to make use of the standard Lookup functionality as bound to the apex:inputField tag AND not need a Utility Object.

 

Suggestions?

 

Before I go reinventing the wheel has anyone ever built a Visualforce page that shows a list of Accounts with list of Opportunities with list of Opportunity Lines?
I'm thinking of nested datatables and realise I'll likely have to do some heavy lifting in code to achieve due to the 1 level limitation with SOQL queries.
Sample code would be appreciated.
thanks,
Manu

 

Hi,

 

might be simple but I'm trying to reference this new contact with the test account created, this is a test for a controller.

on the NEW contact "con", I need it to be related to the account acc that I've just created. I'm trying account.name='xxxx" but doesn;' work.

 

@isTest
private class TestKeyLeadership
{
   static testMethod void testGetLeaders()
   {
      // insert a test account
      Account acc=new Account(Name='Test123');
      insert acc;
      // insert a test Contact
      Contact con=new Contact(FirstName='Lester', Lastname='DbigTester', account=acc.id, email='123123123@888555.com');
      insert con;
      // insert a test Leadership Code
      List<leadership_position_code__c> LDS=new List<leadership_position_code__c>{new leadership_position_code__c(Contact__C='Lester DbigTester', position_type__C='Clergy', Position__C='Cantor', Start_Date__C='01/01/2011', Thru_date__C='01/02/2011' ),
       new leadership_position_code__c(Contact__C='Lester DbigTester', position_type__C='Officer', Position__C='President', Start_Date__C='01/01/2011' ), 
       new leadership_position_code__c(Contact__C='Lester DbigTester', position_type__C='Clergy', Position__C='Senior (or only) Rabbi', Start_Date__C='01/01/2011' )};
      insert LDS;
     
      // add the id to the current page
      ApexPages.currentPage.getParameters().put('id', acc.id);

      // instantiate the class under test
      KeyLeadership kl=new KeyLeadership();
     
      List<Leadership_Position_code__c> leaders=kl.getLeaders();

      System.assertEquals(2, leaders.size());
 
   }

 

Thanks!

B

Hi,

 

I am trying to display dates of current week. How can i do it? What i am trying to do is display the timesheet for the week.

So if i view the page today then it should display me the current week dates. Any pointers to approach this problem would be very helpful

 

Thanks

Prady

  • February 01, 2011
  • Like
  • 0

HI i am trying to write an trigger in case ,if region is chennai i have an autonumber field it should be ch-000

for pune pun-000,i want the each region to autonumber separately.

I am writting a trigger that will take the name of the Product Specialist on the Opportunity Sales Team and placing the name on the custom object that is related to the opportunity. I am recieving the following error:

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ProductSpecialists: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 0 Trigger.ProductSpecialists: line 17, column 37: []

 

 

Here is the trigger:

 

trigger ProductSpecialists on Custom_Layout_Object__c(before insert, before update) {

    Set<Id> layoutid = new Set<Id>();
     for(Custom_Layout_Object__c o : trigger.new){ 
        System.debug('**** 0 opp id : '+ o.id); 
        LayoutId.add(o.id); 

    List<Custom_Layout_Object__c> clo = [Select id, Opportunity__c, Product_Specialist__c from
        Custom_Layout_Object__c WHERE id in:LayoutID limit 1]; 

    List<Opportunity> opp = [Select id from Opportunity limit 1];
    
    List<OpportunityTeamMember> Otms = [Select id, opportunityid, 
    TeamMemberRole, UserId, user.name from OpportunityTeamMember where
    TeamMemberRole = 'Product Specialist' and opportunityid in:opp limit 1];  

     o.Product_Specialist__c = otms[0].User.name;
     
     }
}

 

 

The error is on the last line.

 

o.Product_Specialist__c = otms[0].User.name;

 

I believe that I need to put this inside a for statement but am not sure. Any Suggestions of what I can do?

 

Thank you

I'm posting this in the hopes of helping "the next guy" that hits this.  

 

Our ant-based deployments, which had been going flawlessly for months, suddenly started failing, with lots of UNABLE_TO_LOCK_ROW errors in the logs from our various Apex test methods.  The same exact test methods passed when executed from "Run All Tests" in the UI.  We tried deploying with Eclipse and Change Sets, but got the same UNABLE_TO_LOCK_ROW errors.

 

The lines of code that were failing were all record inserts for certain objects.  We realized that if we removed those objects from our package.xml, we could complete the deployment without the errors.  However, we are making lots of object-level changes (new fields, etc), so this was a bad long-term solution.

 

After much troubleshooting, SFDC Tech Support finally found the root cause.  It turns out that if you modify the format of an auto-number field - say, change the name from "C-{0000}" to "CDM-{0000}" - subsequent deployment of that object will fail if any test methods insert records of that object.

 

Ouch.  Ugly, bad bug.  But once we knew the cause, we matched up all auto-number field formats in our source & destination orgs, and then re-ran the full ant script (with all objects) again, and the deployment was successful.

 

Hopefully SFDC will fix this odd bug quickly.  But in the meantime, if you get UNABLE_TO_LOCK_ROW" errors during deployment, check your auto-number field formats!

Hi,

 

We have enabled Chatter in our org. and the number of records in Feed Track Changes increased our storage space so we were not able to load any more data.

 

When I tried to delete each feed from the Standard Object feeds like Accountfeed, Contactfeeds etc. there  were no data available in those objects. But the number of records in the Feed Track Change object still remained the same.

 

I tried to delete the feeds of Custom Objects as well but I did not find any records in them as well.

 

Can anyone provide me a solution of where can i search for these feeds in order to delete them??

 

Is there an easy way to delete all the feeds together rather than deleting each Objects feeds individually???

 

Thanks in advance.

 

Regards,

prak

  • July 19, 2010
  • Like
  • 0

This doesn't work:

 

trigger cdAssignment on Case bulk (before insert) {
...snip...
for (case c : trigger.new){
if (c.RecordTypeId == rtRequest)
{
// c.OwnerId = requests.get(c.Request__c).OwnerId;
}
else if (c.RecordTypeId == rtPaymentR)
{
// c.OwnerId = paymentRequests.get(c.Related_Payment_Request__c).OwnerId;

system.debug(c);
// below is a valid id that i used to test and it still fails
c.OwnerId = '005700000014h0xAAA';
system.debug(c);
}
}

}

This works:

 

trigger cdAssignment on Case bulk (before insert) {
...snip...
for (case c : trigger.new){
if (c.RecordTypeId == rtRequest)
{
c.custom__c = 'blah blah...';
}
else if (c.RecordTypeId == rtPaymentR)
{
c.custom__c = 'blah blah...';
}
system.debug(c);
}

}

 

Here's a snipplet of my code, the initial user creating the case is a portal user and once they click submit it should change the owner to an internal user of my choosing. But right now it is giving me an error:

 

Insufficient Privileges You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.

 

I can save and make changes to any field on the case object besides OwnerId. Here are some things I tried:

- Giving the profile create/read/write permissions to that object

- Double check that the field accessibility was set to Editable for that recordtype

 

I don't know where else to look, does anybody have any suggestions?

i have downloaded from the app exchange the contact required app and like it except that it produces a warning only for the user and forces them to back out and re-enter that data that is required. What I would like it to do is rather than create an error message is to open a new window with the contact role related list where the user can enter the required data and save. this would allow users to work without having to backout of the record.

 

It seems the code does what I want up until I get to the area highlighted in red text.

 

Apart of our business requirement is to capture contact and partner roles for each and every opportunity as it closes. I cant make a related list a requirement today so this seems to be the best work-around i have found. If anyone has any other solution please share :)

 

Any assistance is welcome.

 

 

 

 //This is provided as a sample to require a contact on opportunities it is provided without warranty and support.

trigger opportunity_contact_required on Opportunity (before insert, before update) {

//map to keep track of the contact_required = 1

Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>();

//Trigger.new is an array of opportunities
//and adds any that have Contact_Required = 1 to the oppy_contact Map

for (Integer i = 0; i < Trigger.new.size(); i++) {

    if  (Trigger.new[i].contact_required__c == 1)
            {
            oppy_contact.put(Trigger.new[i].id,
            Trigger.new[i]);

            //system.debug('This is the trigger.new.id - '+Trigger.new[i].id);

    }
}

//map to keep track of the opportunity contact roles

map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>();


//select OpportunityContactRoles for the opportunities with contact role required

for (OpportunityContactRole ocr : [select OpportunityId, IsPrimary
from OpportunityContactRole
where (OpportunityContactRole.IsPrimary = True and OpportunityContactRole.OpportunityId
in :oppy_contact.keySet())])
  {


//puts the contact roles in the map with the Opportunity ID as the key
    
        oppycontactroles.put(ocr.OpportunityId,ocr);
}

// Loop through the opportunities and check if they exists in the contact roles map or contact role isn't required
        
for (Opportunity oppy : system.trigger.new) {

    //system.debug('List oppy Id - '+oppy.id);
    
    if  (oppycontactroles.containsKey(oppy.id) || oppy.contact_required__c ==0)
        {
            
        }
    
    else
        {
            oppy.addError('No Primary Contact Exists. Please go to the Opportunity Contact Roles Related List and add a primary contact.  Insure that all contacts related to this Opportunity are properly added in the Contact Roles with respective roles assigned.');

                
        }
    

} //for

    
    
 }

Hi, i am new to using visualforce and i am trying to create a detail page to overright the current detail page for a custom object. The custom object contains a picklist field containing 3 values. I have created a custom formula field using Image and Case to display the values in the picklist as images in the detail view. the formula in the field is:

 

IMAGE(
CASE( Status__c ,
"Not Received","https://emea.salesforce.com/resource/1242640894000/RedFlagStatus",
"Received", "https://emea.salesforce.com/resource/1242641297000/YellowFlagStatus",
"Checked","https://emea.salesforce.com/resource/1242641338000/GreenFlagStatus",
"Status"),
"Status") 

 

 In my visualforce page i am using <apex:outputField value="{!CustomObject__c.Status__c"/> to display the custom formula field. However the imgae is not displaying, instead it has, <img src="https://emea.salesforce.com/resource/1242641297000/YellowFlagStatus" alt="Status" border="0"/> in the field output. If anyone can help with how i should display the picklist values as images on the detail page of a record then that would be great.

 

Matt.

Following is the sample code which i am using to save maximum of 10 attachments at a time.

But whenever the size of the attachments gets larger the page displays the view state error message

For smaller size attachments the code works perfectly but whenever the size of any attachment increases

, the salesforce internal limit error occurs for viewstate.(128K) 

 

VF Page 

-------------------------------------------------------------

<apex:page controller="ReAttachmentController">

<apex:form >
<apex:pageMessages />
 <apex:repeat value="{!aList}" var="a">
   <apex:inputFile style="width:500px" value="{!a.body}" filesize="{!a.BodyLength}" filename="{!a.name}"/>
 </apex:repeat>
 

 <apex:commandButton value="Attach" action="{!doAttach}"/>
</apex:form>
</apex:page>

 

 

 

APEX CODE

--------------------------------

 

public class ReAttachmentController {
  public List<Attachment> aList{get;set;} 
  private String caseId = '50040000007GIsV'; 
  public ReAttachmentController(){
       aList = new List<Attachment>();
       for(Integer attachmentNos = 0 ; attachmentNos < 10; attachmentNos++){
             Attachment attach = new Attachment();
             aList.add(attach);
       }
  } 
  public boolean validateAttachments(){
        boolean returnValue = true;
        for(Attachment ab : aList){
              if(ab.body == null){
                   returnValue = false;
              }
        }       
        return returnValue;
  }
   
  public PageReference doAttach(){
      List<Attachment> lstToAttach = new List<Attachment>();
      boolean returnValue = validateAttachments();
         if(returnValue){
               for(Attachment ab : aList){
                    ab.parentId = caseId;
                    lstToAttach.add(ab);
               }
               insert lstToAttach;
               for(Attachment ab : aList){
                    ab.body = null;
               }
              
               return null;
         }else{
              return null;
         }             
  }
}

This makes absolutely no sense to me. I am trying to insert two OpportunityLineItems that are exactly the same but I get this exception. What good reason is there to stop the insertion of two Records that are the same?

I understand if this was an upsert operation as you can't insert and update and the same time but I am inserting two brand new OpportuntiyLineItem records.

Thanks,
Jason


Message Edited by TehNrd on 09-24-2008 04:48 PM
  • September 24, 2008
  • Like
  • 0