如何将MasterDetails字段插入控制器Salesforce?
在Stud Sobject中,有两个Master_Deatils,即课程和教练名称。我需要插入数据。但无法插入。请帮助我...提前thaks ..
< apex:page controller =“ insert_cc_class”> < apex:form>
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="SAVE" action="{!save}"/>
<apex:commandButton value="CANCEL" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Student Details">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Student Name"/>
<apex:inputText value="{!Sname}" />
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Contact Number"/>
<apex:inputText value="{!Snumber}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Course Name"/>
<apex:inputText value="{!SCourseName}" />
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Trainer Name"/>
<apex:inputText value="{!trainername}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Date Of Birth"/>
<apex:inputText value="{!dob}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Qualification"/>
<apex:selectList size="1">
<apex:selectOption itemValue="B-Tech" />
<apex:selectOption itemValue="Diploma" />
<apex:selectOption itemValue="Graduate" />
<apex:selectOption itemValue="MBA" />
<apex:selectOption itemValue="MCA" />
<apex:selectOption itemValue="PG" />
<apex:selectOption itemValue="PHD" />
<apex:selectOption itemValue="Under Graduate" />
</apex:selectList>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="State"/>
<apex:inputText value="{!state}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="City"/>
<apex:inputText value="{!city}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
&lt;/apex:form&gt; &lt;/apex:page&gt;
公共类Insert_cc_class {
// private Apexpages.standardController Controller;
public String city { get; set; }
public String state { get; set; }
public String qualification { get; set; }
public integer dob { get; set; }
public String trainername { get; set; }
public String SCourseName { get; set; }
public integer Snumber { get; set; }
public String Sname { get; set; }
public PageReference cancel() {
return null;
}
public pagereference save(){
Stud__C obj = new Stud__C();
obj.Sname__c = Sname;
obj.Contact_Number__c = String.valueOf(Snumber);
obj.Qualification__c = qualification;
obj.DOB__c = date.ValueOf(dob);
obj.Course_Name__c = SCourseName;
obj.Trainer_Name__c = trainername;
obj.State__c = state;
obj.City__c = city;
Insert obj;
return null;
}
}
Here in stud Sobject there are two master_deatils i.e course and trainer name. I need to insert the data. But not able to insert.Please help me...Thaks In Advance..
<apex:page controller="insert_cc_Class">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="SAVE" action="{!save}"/>
<apex:commandButton value="CANCEL" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Student Details">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Student Name"/>
<apex:inputText value="{!Sname}" />
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Contact Number"/>
<apex:inputText value="{!Snumber}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Course Name"/>
<apex:inputText value="{!SCourseName}" />
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Trainer Name"/>
<apex:inputText value="{!trainername}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Date Of Birth"/>
<apex:inputText value="{!dob}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Qualification"/>
<apex:selectList size="1">
<apex:selectOption itemValue="B-Tech" />
<apex:selectOption itemValue="Diploma" />
<apex:selectOption itemValue="Graduate" />
<apex:selectOption itemValue="MBA" />
<apex:selectOption itemValue="MCA" />
<apex:selectOption itemValue="PG" />
<apex:selectOption itemValue="PHD" />
<apex:selectOption itemValue="Under Graduate" />
</apex:selectList>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="State"/>
<apex:inputText value="{!state}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="City"/>
<apex:inputText value="{!city}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class insert_cc_Class {
// private ApexPages.StandardController controller;
public String city { get; set; }
public String state { get; set; }
public String qualification { get; set; }
public integer dob { get; set; }
public String trainername { get; set; }
public String SCourseName { get; set; }
public integer Snumber { get; set; }
public String Sname { get; set; }
public PageReference cancel() {
return null;
}
public PageReference save() {
Stud__C obj = new Stud__C();
obj.Sname__c = Sname;
obj.Contact_Number__c = String.valueOf(Snumber);
obj.Qualification__c = qualification;
obj.DOB__c = date.ValueOf(dob);
obj.Course_Name__c = SCourseName;
obj.Trainer_Name__c = trainername;
obj.State__c = state;
obj.City__c = city;
Insert obj;
return null;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是非常复杂的方法。您是否真的需要所有这些“ outputLabel,InputText”等?如果您使用Apex:InputField(它神奇地知道字段标签以及字段类型是否为文本/日期/选择列表),则更简单,并且它也可以让您轻松显示查找。
当您无法做到这一点时,很少有这样的情况(需要绕过SF配置文件字段权限),但它在“我真的知道我在做什么”类别中。对于这些,如果您不能仅显示查找,则需要手工制作一些搜索 +自动完成解决方案。网络上应该有很多示例如何按名称功能创建VF+APEX搜索。
虽然这确实使轮子发动机。认真地考虑使用
&lt; apex:inputfield&gt;
this is very complicated way to do it. Do you really need all these "outputLabel, inputText" etc? It's simpler if you use apex:inputField (it'd magically know the field label and whether the field type is text/date/picklist) and it'd let you easily display lookups too.
There are rare situations when you can't do that (need to bypass SF profile field permissions) but it's in "I really know what I'm doing" category. And for these if you can't just display a lookup you need to hand-craft some search + autocomplete solution. There should be lots of examples on net how to create VF+apex search by name functionality.
That's really reiinventing the wheel though. Seriously, consider using
<apex:inputField>