+ Start a Discussion
rebvijkumrebvijkum 

create a new record in custom object

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;
        
    }  
}
Aditya MohanAditya Mohan
So you want to copy data from one custom object to other custom object right?
rebvijkumrebvijkum
I'm getting data from soql queries from Core_Benefit__kav and Core_Benefit__DataCategorySelection objects, and now i need to create a record on Article_Feedback__c object with these data. as of now i could save a record but the field are empty
public class GetURLnew {
    public Article_Feedback__c ArticleFeedbackObj = new Article_Feedback__c();
    public Core_Benefit__kav filterid;
    public string cbkId {get; set;}
    public Core_Benefit__DataCategorySelection CatDetails;
   
    public Article_Feedback__c getArticleFeedbackObj(){
      return ArticleFeedbackObj;
   }
   public void setArticleFeedbackObj(Article_Feedback__c ArticleFeedbackObj){
      this.ArticleFeedbackObj = ArticleFeedbackObj;
   }
    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 saveclick() {
        
         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 ArticleFeedbackObj;
         return null;
    }  
}