• Mohit S.
  • NEWBIE
  • 35 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 8
    Replies
I have a simple VF page with some html input fields. Please help me with how can I pass the information from these html input fields to the salesforce and save in Salesforce Contact object, without redirecting away.
VF & Apex code given below is what I was trying with no success. The code is not complete & correct at all, its just few relevant yet non woking pieces I put together. Kindly help and feel free to share any code, which solves the purpose.

VF PAGE (Page Name - CSAManageProfile)
<apex:page showHeader="false" sidebar="false" standardStylesheets="false" applyHtmlTag="false" docType="html" controller="G_ManageUserViewController">

<apex:form >

<input id="txtFirstName" type="text"  class="form-control" value="{!cont.firstname}"> </input>
<input id="txtMiddleName"  type="text" class="form-control placeholder-field" Placeholder="Middle Name"/>
<input id="txtLastName" type="text"  class="form-control" value="{!cont.lastname}"> </input>

<button id="btnSaveProfile" type="button" class="btn btn-blue" value="Submit" onClick="saveProfile()">Save</button>

<script>  
function saveProfile(){
                                
    var fname = document.getElementById("txtFirstName").value;
    var mname = document.getElementById("txtMiddleName").value;
    var lname = document.getElementById("txtLastName").value;
   
}         
</script>
</apex:form >
APEX CODE (Class Name - G_ManageUserViewController)
 
public class G_ManageUserViewController {
    
    Public Contact cont{get;set;}
    Public boolean EditProfile{get;set;}
    Public boolean EditContact{get;set;}
    Public boolean isOpen {get;set;}
    public String strPageId {get;set;}
    
    public G_ManageUserViewController(ApexPages.StandardController stdController) {

    cont = (Contact) stdController.getRecord();
    }
    /*
    public Contact getMyContact() {
        //User[] users = [SELECT ContactId FROM User WHERE Id = :UserInfo.getUserId()];
        //User usr = users[0];
        //Contact[] contacts = [SELECT Name, Firstname, Lastname, Email, Phone, MobilePhone, OtherPhone, Contact_Preference__c, Communication_Preferences__c, Contact_Time_Zone__c, Work_Schedule__c, Start_Time__c, Stop_Time__c  FROM Contact WHERE Id = :usr.ContactId];
        strPageId=ApexPages.currentPage().getParameters().get('parent_id');
        Contact[] cont = [Select Id, Name,LastName,FirstName,Title, User_ID__c, User_Status__c,Email,Phone from Contact where Id=:ApexPages.currentPage().getParameters().get('Id')];    
            if (cont.isEmpty()) {
            return Null;
            // handle when contacts is empty
            } else {
                Contact MyContact = cont[0];

            return MyContact;       
        }
    }
    
    public pagereference ProfileEdit(){
        EditProfile = true;
        return null;
   }
   
   public PageReference saveContact() {
        try {
            Database.DMLOptions dmlOpts = new Database.DMLOptions();
            dmlOpts.assignmentRuleHeader.useDefaultRule = true;
            cont.setOptions(dmlOpts);
            upsert(cont);
            
        } catch (System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }

        PageReference p = new PageReference('/'+strPageId);
        p.setRedirect(true);
        return p;
    }
   */
}


 
Hi there,

I have a VF page which displays Date and Comments column for Case Comments. I need to sort the table descending on Date, so that the latest comment comes on top. Kindly suggest the code changes. I believe it involves List and querying, but not sure how. Below is my code.

<apex:page standardController="Case" tabStyle="Case" > 
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockButtons location="top">
         <a href="/apex/SaveCaseCommentsVF?parent_id={!case.id}&id={!id}" target="_parent" > <button type="button" > New </button>  </a>
        </apex:pageBlockButtons>
  
      <apex:pageBlockTable value="{!Case.CaseComments}" var="c" id="myTable">
        <apex:column width="30%" headerValue="Date"> 
            <apex:outputField value="{!c.CreatedDate}"/> 
            <apex:outputText value=" ({!c.CreatedBy.Name}) " style="font-weight: bold;"/>
        </apex:column>

        <apex:column width="70%" headerValue="Comment" value="{!c.CommentBody}"/>
      </apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>
</apex:page>
How can I make the values of field CreatedBy.Name appear in bold, in following code?

<apex:pageBlockTable value="{!Case.CaseComments}" var="c">
            <apex:column width="28%" headerValue="Date" value="{!c.createddate} ({!c.CreatedBy.Name})" />
</apex:pageBlockTable>
On the CASE object detail page, I have created a Case Comments VF page (Secure_Message_Comments_VF) as a component on Case object detail page. The 'New' button on this VF page should open the 'Case Comment Edit' page (NewCaseComments_VF) on Case detail page itself, but it is opening the 'Case Comment Edit' page within that component instead. Below is the command button VF code. Please advise.

<apex:page standardController="Case" extensions="CaseCommentRelatedListExt">
<apex:form >
    <apex:pageBlock >
    
    <apex:pageBlockButtons location="top">
           <apex:commandButton value=" New " action="{!"/apex/NewCaseComments_VF"}" />
    </apex:pageBlockButtons>
    
        <apex:pageBlockTable value="{!Case.CaseComments}" var="c">
            <apex:column width="28%" headerValue="Date" value="{!c.createddate} ({!c.CreatedBy.Name})" />
            <apex:column headerValue="Comment" value="{!c.CommentBody}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>
</apex:page>

Do I need to specify parent_id of the case or anything else? Please help with the solution.
I created a VF page and an associated controller, but its not working. Please suggest me the code changes to get it working.

VF Page Code:

<apex:page standardController="Case" extensions="CaseCommentController" tabStyle="Case">
<apex:form >
<apex:pageBlock title="Case Comment Edit" >
<apex:pageBlockButtons >
<apex:commandButton action="{!Save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Case Details" columns="1" collapsible="false">
<apex:outputField value="{!Case.Subject}"/>
<apex:outputField value="{!Case.Description}"/>
</apex:pageBlockSection>

<apex:pageBlockSection title="Comment Details" columns="1" collapsible="false">
<apex:inputField id="mycomment" label="Comments" value="{!Case.VF_Case_Comments__c}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller Class Code:

Public Class CaseCommentController {
    public Case myCase {get; set;}

    public CaseCommentController(ApexPages.StandardController controller) {  
    Id id = ApexPages.currentPage().getParameters().get('id');
    myCase = (id == null) ? new Case() : [SELECT VF_Case_Comments__c FROM Case WHERE Id = :id];

    }
    
   public PageReference save() 
        {
          upsert(myCase);
          return null;
        PageReference redirectSuccess = new ApexPages.StandardController(myCase).view();
        return (redirectSuccess);
        }

}
 
How can I make the values of field CreatedBy.Name appear in bold, in following code?

<apex:pageBlockTable value="{!Case.CaseComments}" var="c">
            <apex:column width="28%" headerValue="Date" value="{!c.createddate} ({!c.CreatedBy.Name})" />
</apex:pageBlockTable>
I created a VF page and an associated controller, but its not working. Please suggest me the code changes to get it working.

VF Page Code:

<apex:page standardController="Case" extensions="CaseCommentController" tabStyle="Case">
<apex:form >
<apex:pageBlock title="Case Comment Edit" >
<apex:pageBlockButtons >
<apex:commandButton action="{!Save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Case Details" columns="1" collapsible="false">
<apex:outputField value="{!Case.Subject}"/>
<apex:outputField value="{!Case.Description}"/>
</apex:pageBlockSection>

<apex:pageBlockSection title="Comment Details" columns="1" collapsible="false">
<apex:inputField id="mycomment" label="Comments" value="{!Case.VF_Case_Comments__c}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller Class Code:

Public Class CaseCommentController {
    public Case myCase {get; set;}

    public CaseCommentController(ApexPages.StandardController controller) {  
    Id id = ApexPages.currentPage().getParameters().get('id');
    myCase = (id == null) ? new Case() : [SELECT VF_Case_Comments__c FROM Case WHERE Id = :id];

    }
    
   public PageReference save() 
        {
          upsert(myCase);
          return null;
        PageReference redirectSuccess = new ApexPages.StandardController(myCase).view();
        return (redirectSuccess);
        }

}