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
Sascha DeinertSascha Deinert 

Return.Page AccountID

Hi,

How can I add to return.page syntax the account id.
My code below doesn't work. 
 
public class Bestandsauswertung3_class {

private Id accId {get; set;}
public Bestandsauswertung3_class(ApexPages.StandardController stdcontroller) { 
    accId = stdcontroller.getRecord().Id;
}

public Decimal testValue { get; set; }

public PageReference nextPage () {    
        
        if(testValue == null) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Required value'));
            return null;
        }        
        
        testValue += 500;
        
        return Page.Bestandsauswertung3?id=accid;    
    }
Thanks,
Sascha
 
Best Answer chosen by Sascha Deinert
Mathew Andresen 5Mathew Andresen 5
I created a quick test class to test things I noticed

    AnteilM = 0;
    AnteilF = 0;

Aren't declared

I also did a quick test to see if account was going over, and for me it was working fine.  Note I replaced Unternehmens_Id_Long__c with Id.  I'm not sure what Unternehmens_Id_Long__c is, but the account Id should match id when in the account object.  I don't know why Unternehmens_Id_Long__c would have the same value as id (maybe you have a good reason, I'm just not famaliar with your org).


Here is what I did, make sure you put the id in the URL to test  for example  
"https://c.cs13.visual.force.com/apex/Bestandsauswertung3?core.apexpages.request.devconsole=1&id=001W000000IEcYg"

 
<apex:page controller="Bestandsauswertung3_class" showheader="false" sidebar="false">

test
 
    <apex:pageblock>
    <apex:pageBlockTable value = "{!accList}" var= "acc">
        <apex:column value="{!acc.name}"/>
        
        
        </apex:pageBlockTable>
    
    
    </apex:pageblock>



</apex:page>
 
public class Bestandsauswertung3_class {
	private Id accId {get; set;}
    Public List<Account> AccList {get; set;}
public Bestandsauswertung3_class() { 
    accId = ApexPages.currentPage().getParameters().get('id');
    AccList = [SELECT Name, NumberOfEmployees FROM Account WHERE id = :accId]; 

    Integer AnteilM = 0;
    Integer AnteilF = 0;

 //   getEZRen();   

}
}


Please mark this as solved if this fixed your problem

All Answers

Mathew Andresen 5Mathew Andresen 5
I always use accId = ApexPages.currentPage().getParameters().get('id');
Sascha DeinertSascha Deinert
Ok, but how can I add the ID to 
 
return Page.Bestandsauswertung3?id=accid

If I try to save the syntax I'll get an error Compile Error: expecting a colon, found ';' 

It is possible to add the ID to the string Page.Bestandsauswertung3?id=.......

Thanks,
Sascha
Mathew Andresen 5Mathew Andresen 5
I think if you return the actual page reference that would work.  For example, I did the following 
 
public PageReference saveNew() {

       upsert prod; 
            prod = new Client_Plan_Product__c(); 
            prod.Client_Plan__C = clientId;
       PageReference clientPage = new ApexPages.StandardController(prod).view();

       clientPage.setRedirect(true);
       return clientPage;  
    }

Or I think
 
ApexPages.currentPage().getParameters().put('id', prod.id);

Might work.
Sascha DeinertSascha Deinert
Thanks for your response, but I don't know how can I use this for my code.
Could you help me.

Thanks,
Sascha
Sascha DeinertSascha Deinert
Hi Mathew,

I fixed the problem with the error, but I still get no information about the account.
Could you take a look.
 
<apex:page controller="Bestandsauswertung3_class" showheader="false" sidebar="false">
  <apex:sectionHeader title="Baw 1" subtitle="Next page test" />
  <apex:form >
      <apex:pageMessages id="messages" />
      <apex:pageBlock >
                     <apex:commandbutton value="Wert für SV-Ersparnis" action="{!nextPage}" />
          <apex:inputText value="{!testValue}" />
      </apex:pageBlock>
  </apex:form>
</apex:page>
 
<apex:page controller="Bestandsauswertung3_class" showheader="false" sidebar="false">

  {!testvalue}

  <br/>

  <apex:dataTable value="{!AccList}" var="Record">
  {!Record.Name}
  </apex:dataTable>

</apex:page>
 
public class Bestandsauswertung3_class {

private Id accId {get; set;}
    Public List<Account> AccList {get; set;}
public Bestandsauswertung3_class() { 
    accId = ApexPages.currentPage().getParameters().get('id');
    AccList = [SELECT Name, NumberOfEmployees FROM Account WHERE Unternehmens_Id_Long__c = :accId]; 

    AnteilM = 0;
    AnteilF = 0;

    getEZRen();   

}

public Integer AnteilM {get; set;}
public Integer AnteilF {get; set;}

public Decimal testValue { get; set; }

public PageReference nextPage () {    

    if(testValue == null) {
    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Required value'));
        return null;
    }        

   testValue += 500;
   return new PageReference('/apex/Bestandsauswertung3?id='+accid);   
} 


public void getEZRen() {

List<Einzelrisiko__c> EZRList = [SELECT Geschlecht__c FROM Einzelrisiko__c WHERE Unternehmens_Id_Long__c = :accId];

    FOR (Einzelrisiko__c EZR : EZRList) {  

    IF(EZR.Geschlecht__c == 'W') { AnteilF++; } 
    IF(EZR.Geschlecht__c == 'M') { AnteilM++; }  

} }

}

Thanks,
Sascha
Mathew Andresen 5Mathew Andresen 5
I created a quick test class to test things I noticed

    AnteilM = 0;
    AnteilF = 0;

Aren't declared

I also did a quick test to see if account was going over, and for me it was working fine.  Note I replaced Unternehmens_Id_Long__c with Id.  I'm not sure what Unternehmens_Id_Long__c is, but the account Id should match id when in the account object.  I don't know why Unternehmens_Id_Long__c would have the same value as id (maybe you have a good reason, I'm just not famaliar with your org).


Here is what I did, make sure you put the id in the URL to test  for example  
"https://c.cs13.visual.force.com/apex/Bestandsauswertung3?core.apexpages.request.devconsole=1&id=001W000000IEcYg"

 
<apex:page controller="Bestandsauswertung3_class" showheader="false" sidebar="false">

test
 
    <apex:pageblock>
    <apex:pageBlockTable value = "{!accList}" var= "acc">
        <apex:column value="{!acc.name}"/>
        
        
        </apex:pageBlockTable>
    
    
    </apex:pageblock>



</apex:page>
 
public class Bestandsauswertung3_class {
	private Id accId {get; set;}
    Public List<Account> AccList {get; set;}
public Bestandsauswertung3_class() { 
    accId = ApexPages.currentPage().getParameters().get('id');
    AccList = [SELECT Name, NumberOfEmployees FROM Account WHERE id = :accId]; 

    Integer AnteilM = 0;
    Integer AnteilF = 0;

 //   getEZRen();   

}
}


Please mark this as solved if this fixed your problem
This was selected as the best answer
Sascha DeinertSascha Deinert
Hi Mathew,

Thank you, it works so far. 
It is possible to use the variables lie {!acc.name} without the apexblock or apexblocktable?

Thanks,
Sascha
Mathew Andresen 5Mathew Andresen 5
yes.  But bear in mine that accList is a List, so you have to cycle through the list, that's what something like Apex:pageblocktable or apex:repeart does


So if you did something like 
public Account acc {get; set; }

acc  = [SELECT Name, NumberOfEmployees FROM Account WHERE Unternehmens_Id_Long__c = :accId LIMIT 1];