如何从视觉力页面获取指定自定义对象记录的ID到apex类?

发布于 2025-01-14 14:02:47 字数 2016 浏览 1 评论 0原文

我正在尝试做一个小项目,但我陷入困境,因为我无法从 vf 页面到 apex 类中提取自定义对象的指定记录的 ID,代码如下所示

<apex:page   standardController="enquiry__c" extensions='callme' recordSetVar="items"> <!--here enquiry__c is a custom object -->
    <apex:form>
        <apex:pageblock>
            <apex:pageblocksection>
               <apex:pageBlockTable value='{!items}' var='en' width="200"  >
                   <apex:column value='{!en.name}'/>
                   <apex:column value='{!en.Student_Enquiry_Name__c}'/>
                   <apex:column value='{!en.phone__c}'/>
                   <apex:column value='{!en.email__c}'/>
                   <apex:column value='{!en.Status__c}'/>
                   <apex:column headerValue="Action">
                       <apex:commandButton value='convert to student'/>
                   </apex:column>  
                   <apex:column headerValue="Record ID">
                       <apex:outputText value='{!en.id}'  />
                   </apex:column>
                  
               </apex:pageBlockTable> 
                <apex:commandButton value='new' action='{!newenquiry}'/>
            </apex:pageblocksection>
        </apex:pageblock>
    </apex:form>
</apex:page>

,输出如下

是,当我单击特定记录旁边的“转换为学生”按钮时,我必须将该记录的 ID 获取到 apex 类中,并且 apex 代码是下面给出

public class callme
{
    public enquiry__c e {get;set;}
    public id i {get;set;}
    public callme(ApexPages.StandardSetController c)
    {
        
        
    }
     public PageReference newenquiry()
    {
        PageReference p=new PageReference('/apex/vfTab_on_enquiry');
        return p;
    }
    public PageReference newcourse()
    {
        PageReference p=new PageReference('/apex/courseInsertion');
        return p;
    }
}

请帮我解决这个问题,提前致谢。

I'm trying to do a small project and I am stuck as I couldn't pull out the ID of the specified record of a custom object from vf page to apex class the code is given below

<apex:page   standardController="enquiry__c" extensions='callme' recordSetVar="items"> <!--here enquiry__c is a custom object -->
    <apex:form>
        <apex:pageblock>
            <apex:pageblocksection>
               <apex:pageBlockTable value='{!items}' var='en' width="200"  >
                   <apex:column value='{!en.name}'/>
                   <apex:column value='{!en.Student_Enquiry_Name__c}'/>
                   <apex:column value='{!en.phone__c}'/>
                   <apex:column value='{!en.email__c}'/>
                   <apex:column value='{!en.Status__c}'/>
                   <apex:column headerValue="Action">
                       <apex:commandButton value='convert to student'/>
                   </apex:column>  
                   <apex:column headerValue="Record ID">
                       <apex:outputText value='{!en.id}'  />
                   </apex:column>
                  
               </apex:pageBlockTable> 
                <apex:commandButton value='new' action='{!newenquiry}'/>
            </apex:pageblocksection>
        </apex:pageblock>
    </apex:form>
</apex:page>

And the output is as below
enter image description here

So my question is when I click on button "convert to student" beside a particular record I have to get the ID of that record into apex class and the apex code is given below

public class callme
{
    public enquiry__c e {get;set;}
    public id i {get;set;}
    public callme(ApexPages.StandardSetController c)
    {
        
        
    }
     public PageReference newenquiry()
    {
        PageReference p=new PageReference('/apex/vfTab_on_enquiry');
        return p;
    }
    public PageReference newcourse()
    {
        PageReference p=new PageReference('/apex/courseInsertion');
        return p;
    }
}

Please help me with this, thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晒暮凉 2025-01-21 14:02:47

->您可以为此使用 actionFunction 。

->创建一个名为 callActionMethod 的 js 函数,并在单击“转换为学生”按钮时调用此函数。

->在 apex 类中创建 ConvertStudent 方法。

->创建一个名为 callConvertStudentMethod 的操作函数,并将记录 id 传递给参数。

Apex 控制器:

public class callme
{
    public enquiry__c e {get;set;}
    public id i {get;set;}
    public callme(ApexPages.StandardSetController c)
    {
        e = new enquiry__c();
        
    }
     public PageReference newenquiry()
    {
        PageReference p=new PageReference('/apex/vfTab_on_enquiry');
        return p;
    }
    public PageReference newcourse()
    {
        PageReference p=new PageReference('/apex/courseInsertion');
        return p;
    }
    public void convertStudent(){
        system.debug('record id ---->'+i);
        e = [SELECT FIELDS(ALL) FROM enquiry__c WHERE ID = :i]; 
        system.debug('student record ---->'+e);
    }
}

VF 页面:

<apex:page   standardController="enquiry__c" extensions='callme' recordSetVar="items"> <!--here enquiry__c is a custom object -->
    <apex:form>
        <apex:pageblock id='resultPanel'>
            <apex:pageblocksection>
               <apex:pageBlockTable value='{!items}' var='en' width="200"  >
                   <apex:column value='{!en.name}'/>
                   <apex:column value='{!en.Student_Enquiry_Name__c}'/>
                   <apex:column value='{!en.phone__c}'/>
                   <apex:column value='{!en.email__c}'/>
                   <apex:column value='{!en.Status__c}'/>
                   <apex:column headerValue="Action">
                       <apex:commandButton value='convert to student' onclick="callActionMethod({!en.id})" />
                   </apex:column>  
                   <apex:column headerValue="Record ID">
                       <apex:outputText value='{!en.id}'  />
                   </apex:column>
                  
               </apex:pageBlockTable> 
                <apex:commandButton value='new' action='{!newenquiry}'/>
            </apex:pageblocksection>
        </apex:pageblock>
        <apex:actionFunction name="callConvertStudentMethod" action="{!convertStudent}" reRender="resultPanel" >
            <apex:param name="firstParam" assignTo="{!i}" value="" />
        </apex:actionFunction>

    </apex:form>
    <script type="text/javascript">

        function callActionMethod(ele)
        {

           callConvertStudentMethod(ele);

        }

    </script>
</apex:page>

-> you can use actionFunction for this.

-> create a js function called callActionMethod and invoke this function on the click of "convert to student" button.

-> create convertStudent method in apex class.

-> create an actionfunction named callConvertStudentMethod and pass the record id to the parameter.

Apex Controller:

public class callme
{
    public enquiry__c e {get;set;}
    public id i {get;set;}
    public callme(ApexPages.StandardSetController c)
    {
        e = new enquiry__c();
        
    }
     public PageReference newenquiry()
    {
        PageReference p=new PageReference('/apex/vfTab_on_enquiry');
        return p;
    }
    public PageReference newcourse()
    {
        PageReference p=new PageReference('/apex/courseInsertion');
        return p;
    }
    public void convertStudent(){
        system.debug('record id ---->'+i);
        e = [SELECT FIELDS(ALL) FROM enquiry__c WHERE ID = :i]; 
        system.debug('student record ---->'+e);
    }
}

VF Page:

<apex:page   standardController="enquiry__c" extensions='callme' recordSetVar="items"> <!--here enquiry__c is a custom object -->
    <apex:form>
        <apex:pageblock id='resultPanel'>
            <apex:pageblocksection>
               <apex:pageBlockTable value='{!items}' var='en' width="200"  >
                   <apex:column value='{!en.name}'/>
                   <apex:column value='{!en.Student_Enquiry_Name__c}'/>
                   <apex:column value='{!en.phone__c}'/>
                   <apex:column value='{!en.email__c}'/>
                   <apex:column value='{!en.Status__c}'/>
                   <apex:column headerValue="Action">
                       <apex:commandButton value='convert to student' onclick="callActionMethod({!en.id})" />
                   </apex:column>  
                   <apex:column headerValue="Record ID">
                       <apex:outputText value='{!en.id}'  />
                   </apex:column>
                  
               </apex:pageBlockTable> 
                <apex:commandButton value='new' action='{!newenquiry}'/>
            </apex:pageblocksection>
        </apex:pageblock>
        <apex:actionFunction name="callConvertStudentMethod" action="{!convertStudent}" reRender="resultPanel" >
            <apex:param name="firstParam" assignTo="{!i}" value="" />
        </apex:actionFunction>

    </apex:form>
    <script type="text/javascript">

        function callActionMethod(ele)
        {

           callConvertStudentMethod(ele);

        }

    </script>
</apex:page>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文