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
Abhinav AdminAbhinav Admin 

need a code for Submit Button controller

HI,

My requirement is to create an activity while Clicking on Submit Button can anyone please help me with code.

Thanks&Regards,
Abhinav.
Nirmal ChristopherNirmal Christopher
Try something like this below example...

public pagereference save(){

task.WhatId = Object.id; task.WhoId = userinfo.getuserid(); task.Subject = 'Other'; task.priority= Object.Priority__c; task.status = 'Not Started'; task.description = 'New Work'; insert task;

return null;
}

Hope I answered your question. Hit best answer button if its helpful.

Regards,
Nirmal
Nirmal ChristopherNirmal Christopher
If your code is using the standard controller no need to use the above code use the standard save method. Use the above using controller only if you are using a Extension or a custom controller.

https://www.salesforce.com/docs/developer/pages/Content/pages_controller_std_actions.htm

Hope I answered your question. Hit best answer button if its helpful.

Regards,
Nirmal
KaranrajKaranraj
Hi Abhinav - Try the below code, when the user click the 'Submit' button it will create an Activity record

Visualforce page
<apex:commandbutton action={!submit} value='Submit' title="New Task"/>
Controller code[Method]
public PageReference Submit() {
    Task activityTask = new Task(); 
    ActivityTask.ActivityDate = Date.today().addDays(7);
    ActivityTask.Subject='Sample Task'; 
    ActivityTask.WhatId = a.Id; //Get the id of the record to which you want to associate your activity
    ActivityTask.OwnerId = UserInfo.getUserId();
    ActivityTask.Status='In Progress';
    insert activityTask;
    return null;
}

Thanks,
Karanraj