function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DeepVDeepV 

update a field based on the contactid from the url

Hi,

I'm passing accountid as id and contactid in the url.

When the users click save, I need to update a datefield__c to today(without time) on contact object.

Here is my vf page - 
<apex:page controller="myAudit">
    <apex:form >
        <apex:pageblock >
          <apex:pageblockSection columns="1">
            <p><apex:inputText value="{!account}" label="Account"/></p>
            <apex:inputText id="Survey" value="{!txtSurvey}" label="SurveyName"/>
              <apex:commandButton action="{!save}" value="save"/>
          </apex:pageblockSection>
        </apex:pageblock>
    </apex:form>
</apex:page>

My apex class:
public class myAudit {

   public myAudit() {
    account =  [SELECT Id, Name FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('id')].Name;
   }

    public String account { get; set; }

    public String txtSurvey { get; set; }

    public PageReference save() {
         Audit_Questionnaire__c aq = new Audit_Questionnaire__c();
            aq.Name = txtSurvey;
            aq.account__c = apexpages.currentpage().getparameters().get('id');
            insert aq;
            return null;
        }
}
 
Best Answer chosen by DeepV
Alex EzhilarasanAlex Ezhilarasan
Hi DeepV,

Add the below ling in Save() method
 
Contact c = new Contact( id = apexpages.currentpage().getparameters().get('id'), dateTime__c = Date.valueOf(system.today() );

update c;

Please do let me know if this helps.

Thanks,
Alex

All Answers

Alex EzhilarasanAlex Ezhilarasan
Hi DeepV,

Add the below ling in Save() method
 
Contact c = new Contact( id = apexpages.currentpage().getparameters().get('id'), dateTime__c = Date.valueOf(system.today() );

update c;

Please do let me know if this helps.

Thanks,
Alex

This was selected as the best answer
DeepVDeepV
Thanks Alex, I'm able to execute the code succesfully but I dont see the date field , it is empty.

note: It is a date field not a datetime field
DeepVDeepV
Thanks Alex, it worked.
Alex EzhilarasanAlex Ezhilarasan

Good to know you got answer DeepV. :) I made a mistake in parameters get(used id instead of contactId). Glad you figured that out :)