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
NiccoleNiccole 

Need help with a trigger to update multiple fields on a case

I have several fields on my Case object that I want to auto populate depending on certain conditions.  For the most part, I have my trigger set up to do what I want.  The issue I am running into is at the end of the trigger.  The field (c.Task_Steps__c) is a text field with the ability to have 255 characters.  Currently, how my trigger is written, it populates the text field with a horizontal list like such:

1. Review Quote  2. Approve / Reject Quote  3. Complete task in Salesforce

However, I want to populate this field with vertical list values so that it looks like the following:

  1. Review Quote
  2. Approve / Reject Quote
  3. Complete task in Salesforce

Is this even possible?  I am new to writing Apex and Triggers so any information / code modification would be greatly appreciated :)!

Code:

trigger SEApproveRejectQuote_assignment on Case (Before update)
{for (Case c: Trigger.new)
{if(c.Reason=='Approve / Reject Quote' && c.Status=='New')
{
c.Origin='End User Request';
c.Type='SE Task';
c.Subject='Approve / Reject Quote';
c.Description='Quote approval is needed';
c.Task_Steps__c='1. Review Quote  2. Approve / Reject Quote  3. Complete task in Salesforce';
             }}}

 

Best Answer chosen by Niccole
Bradley DelauneBradley Delaune
Hi Niccole!

Here is how you would add new lines (this will only work if the Task_Steps__c field is a text area)
trigger SEApproveRejectQuote_assignment on Case (Before update)
{
	for (Case c: Trigger.new)
	{
		if(c.Reason=='Approve / Reject Quote' && c.Status=='New')
		{
			c.Origin='End User Request';
			c.Type='SE Task';
			c.Subject='Approve / Reject Quote';
			c.Description='Quote approval is needed';
			c.Task_Steps__c='1. Review Quote \n2. Approve / Reject Quote \n3. Complete task in Salesforce';
		}
	}
}

The '\n' indicates to add a newline character.

I hope this helps!

All Answers

Bradley DelauneBradley Delaune
Hi Niccole!

Here is how you would add new lines (this will only work if the Task_Steps__c field is a text area)
trigger SEApproveRejectQuote_assignment on Case (Before update)
{
	for (Case c: Trigger.new)
	{
		if(c.Reason=='Approve / Reject Quote' && c.Status=='New')
		{
			c.Origin='End User Request';
			c.Type='SE Task';
			c.Subject='Approve / Reject Quote';
			c.Description='Quote approval is needed';
			c.Task_Steps__c='1. Review Quote \n2. Approve / Reject Quote \n3. Complete task in Salesforce';
		}
	}
}

The '\n' indicates to add a newline character.

I hope this helps!
This was selected as the best answer
geosowgeosow
Is your Task_Steps__c a text area field?  If so try this (add \n\r to force a new row):

c.Task_Steps__c='1. Review Quote \n\r2. Approve / Reject Quote  \n\r3. Complete task in Salesforce';
NiccoleNiccole
Thanks so much guys :)!  That is exactly what I was looking for, it worked perfectly.

And my apologies, I thought I said that the field was a Text Area, but I guess I just said text...oops.