• Jonathan Meltzer 14
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 2
    Questions
  • 8
    Replies
I will try to generalize this question, as I believe that the issue is not related to the specific objects.  I have an object (call it Object1) that has a Lookup field called Lookup1__c.  The Lookup field looks to another object called Object2__c.  Object2__c has an ID field and a custom field called Field2__c.

When I retrieve a record for Object1, I see a value in the Lookup1__c field - it is an ID.  However, when I try to retrieve Object1.Lookup1__r.ID or Object1.Lookup1__r.Field2__c, all I get are NULL values.  The query is not looking through to Object2, even though the relationship is valid and Developer Console does not show any errors.

Any ideas?  How do I get the Object1.Lookup1__r.Field2__c value, once I am on the Object1 record?
I think there is something I am just not understanding...something basic.  I have written an extension to the Account controller, and have defined an account ID in that extension.  The account ID is defined as the account associated with the contact that is associated with the current user (this is for Communities).

When I use <apex:detail>, I can use subject={!AccountId} and the page is rendered with the correct record.  However, I do not want to use apex:detail, because I want more granular control over the fields that are being shown.  I cannot find a way to bring in the AccountId value when loading the page without using apex:detail, though.  The pageBlockTable works fine, but is there a way to bring a value into a pageBlock or pageBlockSection without using a pageBlockTable?

Current page:
 
<apex:page standardController="Account" extensions="AccountTab_CX">
    <apex:detail subject="{!AccountId}" relatedList="false" />
    <apex:pageBlock title="Support Contacts">
        <apex:pageBlockTable value="{!supportContacts}" var="s">
            <apex:column value="{!s.Contact_Name__c}"/>
            <apex:column value="{!s.Support_Contact__c}"/>
            <apex:column value="{!s.Email}"/>
            <apex:column value="{!s.Phone}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Current Extension code:
 
public with sharing class AccountTab_CX {

    private List<Contact> supportContacts;
    private Account acct;

    public AccountTab_CX(ApexPages.StandardController controller) {
        this.acct = (Account)controller.getRecord();
    }
    
    public Id getAccountId() {
        User u = [SELECT Id, Contact.AccountId, Contact.Account.Name FROM User WHERE Id = :UserInfo.getUserId()];
        return u.Contact.AccountId; 
    }
    
    public List<Contact> getSupportContacts() {
        List<Contact> supContacts = new List<Contact>();
        User u = [SELECT Id, Contact.AccountId, Contact.Account.Name FROM User WHERE Id = :UserInfo.getUserId()];
        if (u.Contact.AccountId <> NULL) {
            supContacts = [SELECT Contact_Name__c,Support_Contact__c,Email,Phone from Contact where AccountId = :u.Contact.AccountId and Support_Contact__c = TRUE ORDER BY Contact_Name__c];
        }
        return supContacts;
    }

}

New page, which does not bring in any record because I cannot find a way to define the subject.  The supportContacts are listed correctly, because the value of the pageBlockTable still gets defined correctly:
 
<apex:page standardController="Account" extensions="AccountTab_CX">
    <apex:form >
        <apex:pageBlock title="Account Details">
          <apex:pageBlockSection columns="1">
            <apex:outputField value="{!Account.Legal_Account_Name__c}"/>
            <apex:outputField value="{!Account.Support_Hrs_Allotted_Text__c}"/>
            <apex:outputField value="{!Account.Support_Hours_Used__c}"/>
            <apex:outputField value="{!Account.Support_Hrs_Pct_Used_Text__c}"/>
          </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock title="Environment">
          <apex:pageBlockSection columns="1">
            <apex:outputField value="{!Account.Client_OS__c}"/>
            <apex:outputField value="{!Account.MTier_OS__c}"/>
            <apex:outputField value="{!Account.CR_DBMS__c}"/>
            <apex:outputField value="{!Account.CR_DBMS_OS__c}"/>
            <apex:outputField value="{!Account.DBMS_Version__c}"/>
          </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock title="Account Team">
          <apex:pageBlockSection columns="1">
            <apex:outputField value="{!Account.Strategic_Account_Director_Text__c}"/>
            <apex:outputField value="{!Account.Relationship_Mgr_Primary__c}"/>
          </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock title="Support Contacts">
            <apex:pageBlockTable value="{!supportContacts}" var="s">
                <apex:column value="{!s.Contact_Name__c}"/>
                <apex:column value="{!s.Support_Contact__c}"/>
                <apex:column value="{!s.Email}"/>
                <apex:column value="{!s.Phone}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
I will try to generalize this question, as I believe that the issue is not related to the specific objects.  I have an object (call it Object1) that has a Lookup field called Lookup1__c.  The Lookup field looks to another object called Object2__c.  Object2__c has an ID field and a custom field called Field2__c.

When I retrieve a record for Object1, I see a value in the Lookup1__c field - it is an ID.  However, when I try to retrieve Object1.Lookup1__r.ID or Object1.Lookup1__r.Field2__c, all I get are NULL values.  The query is not looking through to Object2, even though the relationship is valid and Developer Console does not show any errors.

Any ideas?  How do I get the Object1.Lookup1__r.Field2__c value, once I am on the Object1 record?
Hello Everyone,

I'm currently having issue in standard list controller module where I'm unable to see list of contacts in the preview section. I've used the code given in module. Even though I have so many contacts in my salesforce org. Can anyone please help me out.Here is the code which I've used. 
Not even able to see single contact. User-added image
Hello,

I have a controller class where I have a non static field leadObj which is initialized in constructor with parameter:
// Constructor
public LeadToMerchantController(ApexPages.StandardController controller) {    
    objLead = (Lead)controller.getRecord();
    System.debug('objLead ' + objLead.Id);   
}

I have two non static methods where the leadObj is used and from two testMethods in a TestClass I want to start and test the two methods. Here is how the testMetdhods are implemented:
 
static testMethod void testLeadStatusExistingDeal() {
    Test.startTest();
    Lead leadObj = new Lead(LastName = 'test', Currency__c = 'USD', Company ='test', Monthly_Volume__c= '1234', Phone='1423542452', Website='www.google.com', Status = '0% Dead Lead');
    System.debug('leadObj ' + leadObj);
    String leadStatusExistingDeal = LeadToMerchantController.leadStatusExistingDeal(leadObj);
    System.debug('leadStatusExistingDeal ' + leadStatusExistingDeal);
    Test.stopTest();
}

static testMethod void testConvertOrRedirect(){
    Test.startTest();
    LeadToMerchantController.convertOrRedirect();
    Test.stopTest();
}

the two methods in the LeadToMerchantController class can not be invoked directly(calssName.methodName) because they are not static.

It is not possible to make an object from this LeadToMerchantController class because the constructor has a specific parameter 
public LeadToMerchantController(ApexPages.StandardController controller)
and it is not clear what to pass for parameter.

How can I invoke from the test method the other method 
LeadToMerchantController.convertOrRedirect();
which has to be tested?

 
Hi all,

I have created the controller extension shown below, to add a visualforce page to my standard layout for a custom object.

Below is my controller, test class, and visualforce page. Right now, coverage is only 67%.

When I run the visualforce page that uses this extension, it works. How do I interrogate the value of “activePrograms” so I can bump up my coverage. Everything I’ve tried returns nulls.


public class DisplayActivePrograms {
               private final Call_Report__c callReport;
    
    public DisplayActivePrograms(ApexPages.StandardController stdController) {
        this.callReport = (Call_Report__c)stdController.getRecord();
    }

                public list<active_program__c> activePrograms;   
    public list<active_program__c>  getActivePrograms() {
        if (activePrograms == null) {
            activeprograms = [select
                                name,
                                category__r.name,
                                category__r.Category_Description__c,
                                start_date__c,
                                end_date__c
                 from active_program__c
                 where
                                end_date__c >= today];  
           
        }
       
        return activePrograms;
    }


@istest
public class DisplayActivePrograms_test {
  PUBLIC static @istest void DisplayActivePrograms_test() {
     account acct = new account(name='abc', phone = '999999999');
     insert acct;
     Call_report__c cr = new Call_report__c(call_date__c = date.newInstance(2014, 7, 1), customer__c=acct.id);
     insert cr;
     srp2__c cat = new srp2__c(name='123',category_description__c = '123 description');
     insert cat;
     date sdt = date.newInstance(2014, 6, 23);
     date edt = date.newInstance(2014, 8, 31);
     active_program__c ap = new active_program__c(name='test name for category 462', category__c=cat.id,start_date__c = sdt, end_date__c = edt);
     insert ap;
   
     ApexPages.StandardController sc = new ApexPages.standardController(cr);
     system.assert(sc != null);

  }
}



<apex:page standardcontroller="Call_Report__c" extensions="DisplayActivePrograms">
   <apex:pageBlock Title="Active Programs">
    <table width="100%">
        <tr>
        <td> <b>Program Name</b> </td>
        <td> &nbsp; </td>
        <td> <b>Category</b> </td>
        <td> &nbsp; </td>
        <td> <b>Category Name</b> </td>
        <td> &nbsp; </td>
        <td> <b>Start Date</b> </td>
        <td> &nbsp; </td>
        <td> <b>End Date</b> </td>
        </tr>
        <tr>
        <td colspan="9"> <hr/> </td>
        </tr>
    <apex:repeat value="{!activePrograms}" var="a">
       
        <tr>
            <td> {!a.Name} </td>
                    <td> &nbsp; </td>
            <td> {!a.Category__r.name} </td>
                    <td> &nbsp; </td>
            <td> {!a.Category__r.Category_Description__c} </td>
                    <td> &nbsp; </td>
            <td><apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
                <apex:param value="{!a.Start_Date__c}" />
                </apex:outputText> </td>
                        <td> &nbsp; </td>
            <td><apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
                <apex:param value="{!a.End_Date__c}" />
                </apex:outputText> </td>
           
        </tr>
    </apex:repeat>
        </table>

    </apex:pageBlock>
</apex:page>
Hi,

We have set up Email to Case functionality. We are getting this error at least once in a day and the case is not opened:

UNABLE_TO_LOCK_ROW : unable to obtain exclusive access to this record

We have gone through this knowledge Article: https://help.salesforce.com/apex/HTViewSolution?urlname=Email-to-Case-error-UNABLE-TO-LOCK-ROW-unable-to-obtain-exclusive-access-to-this-record&language=en_US (https://help.salesforce.com/apex/HTViewSolution?urlname=Email-to-Case-error-UNABLE-TO-LOCK-ROW-unable-to-obtain-exclusive-access-to-this-record&language=en_US)

But, when case is created, we are not updating any parent record of it.

What is the reason of this issue?

Thanks,
Rupali

I'm playing with the following example: http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_custom.htm

 

I created both the controller and the page. However, I see an error: http://i.imgur.com/JxJbnMy.png

 

I have *no* idea what went wrong. The question is how to debug this?

The verify steps of the Trailhead "Build an Account Geolocation App" are shifted by one unit.
When trying to validate the first or second Unit, an error pops up due to a missing file, which will be introduced in the next unit.
Build an Account Geolocation App verify error
  • May 28, 2018
  • Like
  • 1
Hello Everyone,

I'm currently having issue in standard list controller module where I'm unable to see list of contacts in the preview section. I've used the code given in module. Even though I have so many contacts in my salesforce org. Can anyone please help me out.Here is the code which I've used. 
Not even able to see single contact. User-added image