• MaddyConnect
  • NEWBIE
  • 20 Points
  • Member since 2010
  • Software Engineer
  • Allscripts India Pvt. Ltd.


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 4
    Likes Given
  • 11
    Questions
  • 32
    Replies
Hi Guys,

Does anyone know the way to cover cod in 'Fianlly' block using test class? Currently I am getting 70% coverage, however lines not covered are in 'Fianlly' block. To reach 75% I have to cover code in 'Fianlly' block.

Thanks,
Mahadev
Hi,

I have below class defination and it has no method:

public class ExampleClass
{
        public String name {get; set;}
        public String Week_Ending{get; set;}
        public String Depot {get; set;}
        public String Type_Of_Work{get; set;}
}

I tried various ways to cover this class with no luck. Please help to resolve test class to cover such type of class.

Thanks,
Maddy
Hi,
 
We have chatter feed tracking in place in object 'Case' for 7-fields. There is a group of users who do not want feed tracking appear in chatter feed for SPECIFIC FIELD in case chatter feed section at top of the page. e.g. Out of 7-fields, they want chatter feed for 6 fields in Case record page. If I disable field in feed tracking in setup, it will stop feed to whole organization. How can I achieve the this using visualforce?
 
Thanks,
Mahadev

Hi,

 

I have List variable exceeding SF limit of viewstate so that I use keyword 'Transient' and it is working to display data from that variable on webpage but if I render same page as PDF, it is not rendering data from transient variable List.

 

Please help if any alternate to overcome this issue.

 

Thanks!

Mahadev

Hi,

 

Please let me know how to generate PDF and send via email using custom controller.

 

Appriciate your help!

 

Thanks!

Maddy

Hi,

I have VF page which display case history, but sometime due to large number of case history records, page exceeds limit of ViewState. Then I use k/w "Transient" for list I used to collect CaseHistory records and it's working. On same page I have button called "Preview PDF", which fails to render PDF of CaseHistory displayed on this VF due to k/w transiet. Any alternate to handle data exceeding viewstate limit in my scenario so that I can render PDF too.

 

Any help will be appriciated.


Thanks!
Maddy

 

Dear Friends,

 

                   i have a trgger on Lead object to check uniquness of employee ID across Lead and contact. So that I write a trigger on Lead for the same. Im getting 100% test coverage but trigger failed to deploy on production.

 

Thanks & Regards,

Maddy

Hi Friends,

 

                 In Lead object, there is Standard Field called 'Company' having datatype 'String'. I unable to remove it from page layout of Lead as well as It is compulsory on Page Layout. I puzzled why this filed is so restricted and force user to add value to this filed. I checked with its attributes in Data Explorer, it is missing 'Nillable' attribute. I'm not getting way arount to add attribute to this field as 'Nillable'. Please reply if you have solution to edit and add attribute of standard field of standard object.

 

Thanks & Regards,

Maddy

Dear Friends,

 

                 I am trying to test triggers in the Sandbox, I deployed Test Class but when I activate trigger to be tested by that Test Class, my test class fails. It is trowing error as per mentioned in trigger. 

E.g. My trigger checks wheather e-mail entered in Lead is already exist in the Lead or contact object. So that my trigger works fine but when I run test class, my test class failed.

 

What will be the possible cause of such failure of trigger?

 

Thanks & Regards,

Maddy

Hello friends,

 

                      I'm trying to create opportunity using test class but I unable to do the same. I'm writing test class for trigger. This trigger process opportunity, so I need to create it through test class but I fail to do so. But my trigger works fine.

 

Any solution?

Please help.

 

Thanks,

Maddy

Hello Friends,

 

            I'm getting error when I'm calling web page  (.aspx) from Apex Trigger. Following is the code snapshot:

 

 

global class ContactApexClass
{
Httprequest req = new HttpRequest(); id = id.replace(' ','|'); req.setEndpoint('http://65.38.26.120/SB_CreateNewPassword/ContactCreatePWD.aspx?Id='+Id+'&RecType=SI'); req.setMethod('GET'); Http http = new Http(); Httpresponse res = http.send(req);
}
I'm getting  error as follows:
 
16:04:31.059|CALLOUT_REQUEST|[45]|System.HttpRequest[Endpoint=http://65.38.26.120/SB_CreateNewPassword/ContactCreatePWD.aspx?Id=003T000000VP2hQIAT&RecType=SI, Method=GET]
16:04:31.986|CALLOUT_RESPONSE|[45]|System.HttpResponse[Status=Internal Server Error, StatusCode=500]
16:04:31.986|METHOD_EXIT|[45]|System.Http.send(APEX_OBJECT)

 

Please suggest me how to get rid from this error.

 

Thanks,

Maddy

Hi,

I have below class defination and it has no method:

public class ExampleClass
{
        public String name {get; set;}
        public String Week_Ending{get; set;}
        public String Depot {get; set;}
        public String Type_Of_Work{get; set;}
}

I tried various ways to cover this class with no luck. Please help to resolve test class to cover such type of class.

Thanks,
Maddy
Hi, I have written a test class that keeps failing because of a FIELD_FILTER_VALIDATION_EXCEPTION. I have narrowed it down to the exact problem: Part of a lookup filter (that is looking up a Cash Account) specifies that returned records must have their Status__c = 'Active' (see full lookup filter below). When I remove this part of the filter lookup logic, the test class passes. When I add it back in, the test class fails again.

As you can see in my test class below, I have definitely set the Status__c for the Cash Account record insert to be 'Active'. So I just can't figure out what I'm missing that is causing the test class to fail based on this.

Any help much appreciated.

Lookup Filter:
User-added image

Validation Error:
User-added image

Test Class:
@isTest
 private class TestCashAccountRollUpCashIn {static testMethod void myUnitTest() {Profile pf = [Select Id from Profile where Name = 'System Administrator'];User u = new User();
 u.FirstName = 'Test';
 u.LastName = 'User';
 u.Email = 'testuser@test123456789.com';
 u.CompanyName = 'test.com';
 u.Title = 'Test User';
 u.Username = 'testuser@test123456789.com';
 u.Alias = 'testuser';
 u.CommunityNickname = 'Test User';
 u.TimeZoneSidKey = 'America/Mexico_City';
 u.LocaleSidKey = 'en_US';
 u.EmailEncodingKey = 'ISO-8859-1';
 u.ProfileId = pf.Id;
 u.LanguageLocaleKey = 'en_US';
 insert u;
system.runAs(u){
//Set RecordTypeId variable CA
 String strcaRecordTypeId = [Select Id From RecordType WHERE DeveloperName = 'Person' AND sobjectType = 'Cash_Account__c'].Id;
//Insert a cash account 
 Cash_Account__c ca = new Cash_Account__c();
 ca.RecordTypeId = strcaRecordTypeId;
 ca.Name = 'Test Person';
 ca.Status__c = 'Active';
insert ca;
system.assertEquals(ca.Rollup_Cash_In__c, null);
//Set RecordTypeId variable CT
 String strctRecordTypeId = [Select Id From RecordType WHERE DeveloperName = 'Person_to_Person' AND sobjectType = 'Cash_Transfer__c'].Id;
//Test payments on insert
 Cash_Transfer__c ct1 = new Cash_Transfer__c();
 ct1.RecordTypeId = strctRecordTypeId;
 ct1.Destination__c = ca.Id;
 ct1.Amount__c = 100;
 insert ct1;
Cash_Account__c cau1 = [select Rollup_Cash_In__c from Cash_Account__c where Id = :ca.Id];
 system.assertEquals(cau1.Rollup_Cash_In__c,ct1.Amount__c);
//Test payments on update
 Cash_Transfer__c ct1u = [select Amount__c from Cash_Transfer__c where Id = :ct1.Id];
 ct1u.Amount__c = 200;
 update ct1u;
Cash_Account__c cau2 = [select Rollup_Cash_In__c from Cash_Account__c where Id = :ca.Id];
 system.assertEquals(cau2.Rollup_Cash_In__c,ct1u.Amount__c);
//Test payments on second insert
 Cash_Transfer__c ct2 = new Cash_Transfer__c();
 ct2.RecordTypeId = strctRecordTypeId;
 ct2.Destination__c = ca.Id;
 ct2.Amount__c = 800;
 insert ct2;
AggregateResult ag1 = [select sum(Amount__c) from Cash_Transfer__c where Destination__c = :ca.Id];
Cash_Account__c cau3 = [select Rollup_Cash_In__c from Cash_Account__c where Id = :ca.Id];
 system.assertEquals(cau3.Rollup_Cash_In__c,ag1.get('expr0'));
//Test payment on delete
 delete ct2;
AggregateResult ag2 = [select sum(Amount__c) from Cash_Transfer__c where Destination__c = :ca.Id];
Cash_Account__c cau4 = [select Rollup_Cash_In__c from Cash_Account__c where Id = :ca.Id];
 system.assertEquals(cau4.Rollup_Cash_In__c,ag2.get('expr0'));
}
}
}

 
  • February 17, 2015
  • Like
  • 0
hi can anybody write one apex class for  DML operation insert a record into the object and and copy past programme here  
Hi,
 
We have chatter feed tracking in place in object 'Case' for 7-fields. There is a group of users who do not want feed tracking appear in chatter feed for SPECIFIC FIELD in case chatter feed section at top of the page. e.g. Out of 7-fields, they want chatter feed for 6 fields in Case record page. If I disable field in feed tracking in setup, it will stop feed to whole organization. How can I achieve the this using visualforce?
 
Thanks,
Mahadev

Hi,

 

Please let me know how to generate PDF and send via email using custom controller.

 

Appriciate your help!

 

Thanks!

Maddy

Dear Friends,

 

                   i have a trgger on Lead object to check uniquness of employee ID across Lead and contact. So that I write a trigger on Lead for the same. Im getting 100% test coverage but trigger failed to deploy on production.

 

Thanks & Regards,

Maddy

Kudos to SFDC for the new status info available at http://status.salesforce.com/! Is this information available via the SOAP (or any other, I suppose) API?

Thanks,
Charlie
  • February 16, 2006
  • Like
  • 1

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

 

 

Posting this in order to help others who, months from now, might Google "OP_WITH_INVALID_USER_TYPE_EXCEPTION" and find this explanation.

 

We wrote an Apex trigger on the User object, to insert a custom object record anytime a user updates their Chatter status.  This was done to fulfill a client's requirement to audit all Chatter activity.

 

The trigger worked fine, until one day the client signed up some Chatter Free users.  When such a user tried to update their status, they got a pop-up with an OP_WITH_INVALID_USER_TYPE_EXCEPTION error.

 

We scratched our collective heads for awhile.  After all, Apex triggers run in "system mode," right?  That is supposed to mean that "object and field-level permissions of the current user are ignored."  And yet this trigger seemed like it was running in "user mode," enforcing restrictions based on who the current user was.

 

The root cause turned out to be that a Chatter Free user cannot be the owner of a custom object record, and SFDC by default sets the current user as a new record's first owner.  We discovered this when we realized, via experiment, that Apex triggers fired as the result of actions by Chatter Free users could definitely update an existing record, but were having problems creating records.

 

So the simple solution was to explicitly set the owner of the new record to some fully-licensed user prior to inserting it.

Kudos to SFDC for the new status info available at http://status.salesforce.com/! Is this information available via the SOAP (or any other, I suppose) API?

Thanks,
Charlie
  • February 16, 2006
  • Like
  • 1