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 

GetRecord Controller

Hi,

I wrote a big class with a lot of calculation, but all the calculation use the account id as inidicator.
If I open the visualforce/class it use the account id.
current: https://domain--dev--c.csXX.visual.force.com/apex/Parentanalyse?scontrolCaching=1&id=001b000000XUVdv <-- account id

Now I want to change the account id to a customfield parentanalyse_id__c. How can I use the customfield with the code below.
future: https://domain--dev--c.csXX.visual.force.com/apex/Parentanalyse?scontrolCaching=1&id=001b000000XUVdv <-- parentanalyse_id__c

Is this the correct way to get this information? If not, pleas let me know.
 
public class ParentAnaylse_class {

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

Thanks,
Sascha
Best Answer chosen by Sascha Deinert
Sascha DeinertSascha Deinert
Ok. I have the code below, but I get no information at the vfp.
Can you help me.
 
public class Parentanalyse_class {

private Id KaccId {get; set;}
public Parentanalyse_class () { 
    KaccId = ApexPages.currentPage().getParameters().get('id');
getAcc();
}

public String AccName {get; set;}

public void getAcc() {
  List<Account> AccList = [SELECT Name FROM Account WHERE Account_Id_Long__c = :KaccId];
    FOR ( Account Acc : AccList) {

String AccName = Acc.Name;

}
}
 
VISUALFORCE PAGE:

<table width="950" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td width="100%" colspan="2"><span style="font-size:32px; font-weight:bold">{!AccName}</span></td>
    </tr>
    <tr>    
        <td width="100%">
           
        </td>
    </tr>
</table>

Thanks,
Sascha

All Answers

Ramesh KosalairamanRamesh Kosalairaman
Hi,
Remove the sandardcontroller and extension attribute from the page add controller attribute 

like controller="ParentAnaylse_class"
public class ParentAnaylse_class {

private Id KaccId {get; set;}
public ParentAnaylse_class() { 
    KaccId = ApexPages.currentPage().getParameters().get('id'); // parentanalyse_id__c

further you can process with this id value
Sascha DeinertSascha Deinert
Hi,

If I change the first line in the page from

<apex:page standardcontroller="account" extensions="Parentanalyse_class" showheader="false" sidebar="false">

to

<apex:page controller="Parentanalyse_class" showheader="false" sidebar="false">.

Now I get the error "String.Name" etc., because I need the account for some information within the page. How can I solve this?

Thanks,
Sascha
 
Ramesh KosalairamanRamesh Kosalairaman
you need to Query account details by account id within contructor and assign to global variable 

and try to use that variable inside visualforce page
Sascha DeinertSascha Deinert
Ok. I have the code below, but I get no information at the vfp.
Can you help me.
 
public class Parentanalyse_class {

private Id KaccId {get; set;}
public Parentanalyse_class () { 
    KaccId = ApexPages.currentPage().getParameters().get('id');
getAcc();
}

public String AccName {get; set;}

public void getAcc() {
  List<Account> AccList = [SELECT Name FROM Account WHERE Account_Id_Long__c = :KaccId];
    FOR ( Account Acc : AccList) {

String AccName = Acc.Name;

}
}
 
VISUALFORCE PAGE:

<table width="950" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td width="100%" colspan="2"><span style="font-size:32px; font-weight:bold">{!AccName}</span></td>
    </tr>
    <tr>    
        <td width="100%">
           
        </td>
    </tr>
</table>

Thanks,
Sascha
This was selected as the best answer