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
Felix Jong Seok ChaeFelix Jong Seok Chae 

create a link to a given case record in apex trigger

I have a pointer to a case record and I can retrieve any field of that case.
I would like to create a url link of this record in the custom text-typed field of an another record so that
in the salesforce I can simply click the single button (case number for example) in that custom field,
and I will be directed to that case record. 
Thanks.
Glyn Anderson 3Glyn Anderson 3
It would be better if the target field were of type "URL", rather than "Text".  If you can change the datatype to "URL", then you can assign it this way:

<pre>
otherRecord.Link_to_Case__c = '/' + theCase.Id;
</pre>
 
Glyn Anderson 3Glyn Anderson 3
For a prettier result, put the Case Id and Case Number in separate hidden fields, and create a formula field:

HYPERLINK( "/" & Case_Id__c, Case_Number__c, "_self" )
Felix Jong Seok ChaeFelix Jong Seok Chae
Hi Glyn,
if I make type of the target field to URL, can I generate links to more than one case?
Also, is the following an complete command? otherRecord.custom_field = HYPERLINK("/"&ID, "_self")
Felix Jong Seok ChaeFelix Jong Seok Chae
I have the following code and received some error messages:
String oldCaseID = similarCasesL.get(0).ID;
updateCase.similarCases__c = HYPERLINK("/" & 
                                                   oldCaseID, 
                                                   "_self")

2nd line: Unrecognized symbol '"', which is not a valid Apex identifier.
3rd line: unexpected syntax: 'mismatched input ',' expecting SEMICOLON'
last line: unexpected syntax: 'mismatched input ')' expecting SEMICOLON'
Glyn Anderson 3Glyn Anderson 3
My first post showed Apex code, while my second post showed a formula solution.  You can't combine the two.  Either write Apex code to create a URL as in my first post, or use a formula field with the HYPERLINK formula.  You can't use formulas in Apex.

I might not understand your question, but you can't create a single URL that links to more than one thing.
Felix Jong Seok ChaeFelix Jong Seok Chae
Thanks. 
I meant is it possible to have multiple links (one link for one record) in the custom url field?