function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tlsarna1tlsarna1 

Completely Frustrated and Feel Like Crying ... Trying to Pull Field from Account Record

I'm honestly starting to wonder whether I will EVER get this .... here's what I'm trying to do:

 

1./  Ask user for Account Name on page 1 of wizard

2./  Display account name chosen AS WELL AS value of custom field on that account record on page 2 of wizard.

3./  Ask user for Request Type, Category and Action on page 2 of wizard.  The picklist options in the Request Type, Category and Action fields will be based on  the value of the custom field (Global Region) in the account record.

 

I am COMPLETELY FRUSTRATED and lost in trying to get this to work.  It just seems like it should be SOOO simple ... although I'm new to Apex, I know other programming languages ... why is this so difficult to grasp?

 

If anyone can help, I would be forever grateful.   And please ... give me notes and reasons why I'm doing things ... others have tried to help by just giving me links to other wizards, but because those wizards aren't doing what I want to do, they don't help me understand how to build mine.

 

Thanks ...

 

Current Custom Controller Code

public class ARWizard {

    public ApexPages.standardController controller {get; set;}
    
             
    public Assistance_Request__c assistanceRequest { get; set; }
     
    public Account account {get;set;}
    
    public ID accountID {get;set;}
    
    public ARWizard (ApexPages.standardController controller) {
        //Added by Lokesh
        if(assistanceRequest ==null)
             assistanceRequest =  new Assistance_Request__c();
      
  }   
  

    public PageReference step1() {
        return Page.arStep1;
    }

     public PageReference step2() {

      
        try {
            account = [SELECT Id,Name,Global_Region__c
                       FROM Account
                       WHERE Id =: AssistanceRequest.Account_Name__c];
                      
           }
        catch(Exception e)  {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage()));
    }
    return Page.arStep2;
     }


       public PageReference save() {
                System.debug('&&&&&&& Account=' + account);
            try{
                insert assistanceRequest;
            } catch (System.DmlException e) {
                ApexPages.addMessages(e);
                return null;
            }
            controller = new ApexPages.standardController(assistanceRequest);
            return controller.view();
        }
}

 

Current Page 1 Code:

<apex:page standardController="Assistance_Request__c" extensions="ARWizard" tabStyle="Assistance_Request__c">
  
    <script>
    function confirmCancel(){
    var isCancel = confirm("Are you sure you wish to cancel and exit this Assistance Request?");
    if (isCancel) return true;
    return false;
    }
    </script>
    
    <apex:sectionHeader title="Assistance Request" subtitle="Step 1 of X"/>
  <apex:form > 
      <apex:pageBlock id="theBlock" title="Assistance Request Creation" mode="edit">
          <apex:pageBlockButtons >
              <apex:commandButton action="{!step2}" value="Next"/>
              <apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true" style="margin-left: 2em"/>
          </apex:pageBlockButtons>
          <apex:pageBlockSection title="Account Information" columns="1">
              <apex:inputField value="{!AssistanceRequest.Account_Name__c}"/>
          </apex:pageBlockSection>
      </apex:pageBlock> 
  </apex:form>
</apex:page>

 Current Page 2 Code:

<apex:page standardController="Assistance_Request__c" extensions="ARWizard" tabStyle="Assistance_Request__c">
  
        <script>
    function confirmCancel(){
    var isCancel = confirm("Are you sure you wish to cancel and exit this Assistance Request?");
    if (isCancel) return true;
    return false;
    }
    </script>
    
    <apex:sectionHeader title="Assistance Request" subtitle="Step 2 of X"/>
    
  <apex:form > 
      <apex:pageBlock id="theBlock" title="Assistance Request Creation - Request Details" mode="edit">
          <apex:pageBlockButtons >
              <apex:commandButton action="{!step1}" value="Previous"/>
              <apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true" style="margin-left: 2em"/>
          </apex:pageBlockButtons>
          <apex:pageBlockSection title="Account Information" columns="2">
              <apex:outputField value="{!AssistanceRequest.Account_Name__c}"/>
              <apex:outputField value="{!AssistanceRequest__r.Account.Global_Region__c}"/>
          </apex:pageBlockSection>
          
           <apex:pageBlockSection title="Request Information" columns="2">
              This is where the request product, category and action will go.
          </apex:pageBlockSection>
      </apex:pageBlock> 
  </apex:form>
</apex:page>

 

shruthishruthi
          <apex:pageBlockSection title="Account Information" columns="2">
              <apex:outputField value="{!AssistanceRequest.Account_Name__r.Name}"/>
              <apex:outputField value="{!AssistanceRequest.Account_Name__r.Global_Region__c}"/>
          </apex:pageBlockSection>

Try the above code in your second page [for Account Information PageBlockSection].

tlsarna1tlsarna1

That doesn't work.  If I change the Account Name output field on the first line, it doesn't come across at all on page 2.  Is there maybe something I need to do with the fields that I created on the object?