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
tanushree Dutta 8tanushree Dutta 8 

How can I add current date in Status Update field, everytime whenever new comments are updated in that field

Hi All,

I am new to Salesforce, so please help me with this requirement.
I have a Status update field in support request and we have very frequest to-and-fro comments between us and the clients.
The requirement is to add Current date whenever this field is updated.
Eg :
Updation done by user on 1 Sep 2017 :
"9/1/17 - <<Comments by user>>"

Further updation done by user on 4 Sep 2017 :
"9/1/17 - <<Comments by user>>
9/4/17 - <<Additional comments by user>>"

Please guide.
 
GouthamGoutham
Hi,
do the field contains old comments and new comments. 
Abhishek BansalAbhishek Bansal
Hi Tanushree,

Can you please provide some more information like:
  • What do you mean by this field update. On update of which field you want to update your comments field ?
  • On which field you want to store the current date.
You can acheive this with the help of thr trigger where sample code will look something like below:
trigger updateCommnets on SupportRequest__c(before update){

	for(SupportRequest__c supReq : trigger.new){
		if(trigger.oldMap.get(supReq.id).StatusUpdate__c == null && supReq.StatusUpdate__c != null ){
			supReq.Comments__c = Date.today() + 'Comments added by user';
		}
		else if(trigger.oldMap.get(supReq.id).StatusUpdate__c != supReq.StatusUpdate__c){
			supReq.Comments__c += '\n' + Date.today() + 'Further Comments added by user';
		}
	}
}

//SupportRequest__c is your custom object
//StatusUpdate__c is the field on change of which you want to update the comments
//Comments__c is the field where comments are stored with current date

Please let me know if you need any futher help on this.

Thanks,
Abhishek Bansal.

tanushree Dutta 8tanushree Dutta 8
Hi Abhishek / Goutham,

Thank you both for your replies.
We interact with our clients for their queries/issues on Suport Request and put our statements, starting with current date and then our comments, on this field "Status update" Its a Test Area field.
Also the clients provide their own comments, if thay want to, on this "Status update" field but putting the current date under the last comment and then put their comments and save.

What the requirement is, instead on typing the current date everytime (by us or clients). ithe date should get automaticaly get populated whenever we click on "Update", under the latest comments and we or clients can just put our comments and hit Save.

Please help me with this requirement. Many many thanks.
tanushree Dutta 8tanushree Dutta 8
Hi Abhishek,

From your reply on 5th Sep, can you please help me with following doubts?
Please help me that instead of your lines - "'Further Comments added by user'" and "'Comments added by user'", how can I put the latest data (new update on the Status Update field)?

Thanks in advance.

 
Abhishek BansalAbhishek Bansal
Hi Tanu,

Please find the updated code below:
trigger updateCommnets on SupportRequest__c(before update){

	for(SupportRequest__c supReq : trigger.new){
		if(trigger.oldMap.get(supReq.id).StatusUpdate__c == null && supReq.StatusUpdate__c != null ){
			supReq.Comments__c = Date.today() + StatusUpdate__c;
		}
		else if(trigger.oldMap.get(supReq.id).StatusUpdate__c != supReq.StatusUpdate__c){
			supReq.Comments__c += '\n' + Date.today() + StatusUpdate__c;
		}
	}
}

//SupportRequest__c is your custom object
//StatusUpdate__c is the field on change of which you want to update the comments
//Comments__c is the field where comments are stored with current date

Please let me know if this works for you and you can also contact me on Gmail or Skype if there is any urgency on it.
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790

Thanks,
Abhishek Bansal.
tanushree Dutta 8tanushree Dutta 8
Hi Abhishek,
Thanks a ton for your quick reply. One more help from you I needed.
Actually, Status Update is the only field I need to work on, i.e. no Comments__c field is needed there.

My requirement is to do -
If first time insert of any comments on Status Update --> then StatusUpdate__c = Today's date + Inserted Value
eg: - Inserted value = "Please work on this". So, Status Update should be - 2017/09/27.Please work on this

If update is later, on this same inserted value on Status Update field --> then StatusUpdate__c = Last old value + Today's date + New value.
eg.- Updated value = "Work in progress." 
So the Status Update should now be -
2017/09/27 Please work on this
2017/09/27 Work in progress.

Please guide me. Thank you.
Abhishek BansalAbhishek Bansal
Hi Tanu,

Please find the updated code below:
trigger updateCommnets on SupportRequest__c(before insert, before update){

	for(SupportRequest__c supReq : trigger.new){
		if(trigger.isInsert && supReq.StatusUpdate__c != null ){
			supReq.StatusUpdate__c = Date.today() + StatusUpdate__c;
		}
		else if(trigger.isUpdate){
			if(trigger.oldMap.get(supReq.id).StatusUpdate__c == null && supReq.StatusUpdate__c != null ){
				supReq.StatusUpdate__c = Date.today() + StatusUpdate__c;
			}
			else if(trigger.oldMap.get(supReq.id).StatusUpdate__c != supReq.StatusUpdate__c){
				supReq.StatusUpdate__c += '\n' + Date.today() + StatusUpdate__c;
			}
		}
	}
}

Let me know if you face any issue with this.

Thanks,
Abhishek Bansal.
tanushree Dutta 8tanushree Dutta 8
Hi Abhishek,

I put your code and on savem it gives error - "Error: Compile Error: Variable does not exist: StatusUpdate__c at line 5 column 54"

Its not accepting lines where we have - + StatusUpdate__c. Please guide.
Abhishek BansalAbhishek Bansal
Please update statusupdate__c with supReq.StatusUpdate__c