You need to sign in to do that
Don't have an account?
rebvijkum
create a new record in custom obj from visualforce page, where data is queried using soql query from another two objects
i don't knw how to write a record to custom object after querying the data from another objects.Plz help me
The feilds in custom obj(Article_Feedback__c) are Article_ID__c,Article_Title__c,Article_Type__c,Comments__c,Data_Category__c,Data_Category_Group__c and Reason__c.
My VFP:
<apex:page standardController="Core_Benefit__kav" extensions="GetURLnew" >
<apex:form>
<apex:outputField id="id" value="{!cbk.Id}"/>
<apex:outputField id="title" value="{!cbk.Title}"/>
<apex:outputField id="arttype" value="{!cbk.ArticleType}"/>
<apex:outputField id="artnumb" value="{!cbk.ArticleNumber}"/>
<apex:outputField id="urlname" value="{!cbk.UrlName}"/>
<apex:outputField id="createdby" value="{!cbk.CreatedById}"/>
<apex:outputField id="ownerid" value="{!cbk.OwnerId}"/>
<apex:inputField id="comments" value="{!cbk.Comments__c}"/>
<apex:inputField id="reason" value="{!cbk.Reason__c}"/>
<apex:outputText id="datacatname" value="{!Category.DataCategoryName}"/>
<apex:outputText id="datacatgrpname" value="{!Category.DataCategoryGroupName}"/>
<apex:commandButton action="{!save}" value="save"/>
</apex:form>
</apex:page>
My controller:
public class GetURLnew {
public List<Article_Feedback__c> artfeed=new List<Article_Feedback__c>();
public Core_Benefit__kav filterid;
public string cbkId {get; set;}
public Core_Benefit__DataCategorySelection CatDetails;
public Core_Benefit__kav cbk {get; set;}
public GetURLnew(ApexPages.KnowledgeArticleVersionStandardController controller) {
cbkId = apexpages.currentpage(). getParameters().get('id');
cbk = new Core_Benefit__kav();
if(cbkId != null && cbkId != '') {
cbk = [Select Id, Title,Exam__c,Lens__c,UrlName, Lens_Enhancements__c,Frame__c,Contacts__c,Support_Queue_Steps__c,Doctor_Network__c,Lab__c,Additional_Benefits__c, ArticleType, ArticleNumber, CreatedById, OwnerId, Comments__c, Reason__c from Core_Benefit__kav where PublishStatus = 'online' AND Language = 'en_US' AND KnowledgeArticleId =: cbkId];
}
}
public Core_Benefit__DataCategorySelection getCategory() {
return CatDetails;
}
public PageReference save() {
filterid=[SELECT Id,UrlName FROM Core_Benefit__kav WHERE ArticleNumber =: cbk.ArticleNumber AND PublishStatus = 'online' AND Language = 'en_US'];
CatDetails= [Select DataCategoryName,DataCategoryGroupName from Core_Benefit__DataCategorySelection where ParentId =:filterid.Id];
insert artfeed;
}
}
The feilds in custom obj(Article_Feedback__c) are Article_ID__c,Article_Title__c,Article_Type__c,Comments__c,Data_Category__c,Data_Category_Group__c and Reason__c.
My VFP:
<apex:page standardController="Core_Benefit__kav" extensions="GetURLnew" >
<apex:form>
<apex:outputField id="id" value="{!cbk.Id}"/>
<apex:outputField id="title" value="{!cbk.Title}"/>
<apex:outputField id="arttype" value="{!cbk.ArticleType}"/>
<apex:outputField id="artnumb" value="{!cbk.ArticleNumber}"/>
<apex:outputField id="urlname" value="{!cbk.UrlName}"/>
<apex:outputField id="createdby" value="{!cbk.CreatedById}"/>
<apex:outputField id="ownerid" value="{!cbk.OwnerId}"/>
<apex:inputField id="comments" value="{!cbk.Comments__c}"/>
<apex:inputField id="reason" value="{!cbk.Reason__c}"/>
<apex:outputText id="datacatname" value="{!Category.DataCategoryName}"/>
<apex:outputText id="datacatgrpname" value="{!Category.DataCategoryGroupName}"/>
<apex:commandButton action="{!save}" value="save"/>
</apex:form>
</apex:page>
My controller:
public class GetURLnew {
public List<Article_Feedback__c> artfeed=new List<Article_Feedback__c>();
public Core_Benefit__kav filterid;
public string cbkId {get; set;}
public Core_Benefit__DataCategorySelection CatDetails;
public Core_Benefit__kav cbk {get; set;}
public GetURLnew(ApexPages.KnowledgeArticleVersionStandardController controller) {
cbkId = apexpages.currentpage(). getParameters().get('id');
cbk = new Core_Benefit__kav();
if(cbkId != null && cbkId != '') {
cbk = [Select Id, Title,Exam__c,Lens__c,UrlName, Lens_Enhancements__c,Frame__c,Contacts__c,Support_Queue_Steps__c,Doctor_Network__c,Lab__c,Additional_Benefits__c, ArticleType, ArticleNumber, CreatedById, OwnerId, Comments__c, Reason__c from Core_Benefit__kav where PublishStatus = 'online' AND Language = 'en_US' AND KnowledgeArticleId =: cbkId];
}
}
public Core_Benefit__DataCategorySelection getCategory() {
return CatDetails;
}
public PageReference save() {
filterid=[SELECT Id,UrlName FROM Core_Benefit__kav WHERE ArticleNumber =: cbk.ArticleNumber AND PublishStatus = 'online' AND Language = 'en_US'];
CatDetails= [Select DataCategoryName,DataCategoryGroupName from Core_Benefit__DataCategorySelection where ParentId =:filterid.Id];
insert artfeed;
}
}
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
All Answers
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
Thanks Balaji for quick reply, the record is saved wen i click on save button, but the field values are empty.
should i map the data i got from soql query to the custom fields in Article_Feedback Custom object??
if that is, can u show how to map?
public class GetURLnew {
public Article_Feedback__c ArticleFeedbackObj = new Article_Feedback__c();
//private final Article_Feedback__c artfeed;
public Core_Benefit__kav filterid;
public string cbkId {get; set;}
public String sfUrl=URL.getSalesforceBaseUrl().getHost();
public Core_Benefit__DataCategorySelection CatDetails;
public Core_Benefit__kav cbk {get; set;}
public GetURLnew(ApexPages.KnowledgeArticleVersionStandardController controller) {
cbkId = apexpages.currentpage(). getParameters().get('id');
cbk = new Core_Benefit__kav();
if(cbkId != null && cbkId != '') {
cbk = [Select Id, Title,Exam__c,Lens__c,UrlName, Lens_Enhancements__c,Frame__c,Contacts__c,Support_Queue_Steps__c,Doctor_Network__c,Lab__c,Additional_Benefits__c, ArticleType, ArticleNumber, CreatedById, OwnerId, Comments__c, Reason__c from Core_Benefit__kav where PublishStatus = 'online' AND Language = 'en_US' AND KnowledgeArticleId =: cbkId];
filterid=[SELECT Id,UrlName FROM Core_Benefit__kav WHERE ArticleNumber =: cbk.ArticleNumber AND PublishStatus = 'online' AND Language = 'en_US'];
CatDetails= [Select DataCategoryName,DataCategoryGroupName from Core_Benefit__DataCategorySelection where ParentId =:filterid.Id];
}
}
public String getsfurll() {
return sfURL;
}
public Article_Feedback__c getArticleFeedbackObj(){
return ArticleFeedbackObj;
}
public void setArticleFeedbackObj(Article_Feedback__c ArticleFeedbackObj){
this.ArticleFeedbackObj = ArticleFeedbackObj;
}
public String getReturnid() {
return cbkId;
}
public Core_Benefit__DataCategorySelection getCategory() {
return CatDetails;
}
public PageReference saveclick() {
ArticleFeedbackObj.Article_ID__c=cbk.Id;
ArticleFeedbackObj.Article_Title__c=cbk.Title;
ArticleFeedbackObj.Article_Type__c=cbk.ArticleType;
ArticleFeedbackObj.Article_URL__c=cbk.UrlName;
ArticleFeedbackObj.Comments__c=cbk.Comments__c;
ArticleFeedbackObj.Data_Category__c=CatDetails.DataCategoryName;
ArticleFeedbackObj.Data_Category_Group__c=CatDetails.DataCategoryGroupName;
ArticleFeedbackObj.Reason__c=cbk.Reason__c;
insert ArticleFeedbackObj;
return null;
}
}