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 url of other cases in the new case

I collected a list of old cases relevant to a new case.
I saw 'related cases' under the cases tab and using apex trigger in the developer console,
I am trying to create links to those cases in the new case's related cases.
Can anyone know how to set this up?

 
Best Answer chosen by Felix Jong Seok Chae
HARSHIL U PARIKHHARSHIL U PARIKH
I would try using the following code:
 
List<Case> listOfOldCases = New List<Case>();
// I am imagine that you have all the cases stored in this list called: listOfOldCases 

List<Case> finalListToUpdate = New List<Case>();

 For(Case EveryCase : listOfOldCases )
 {
     If(EveryCase.ParentId != Null)
     {
         EveryCase.ParentId = '50046000001quNs';
          // Of course, put your newCase.Id here. You can also hardcode Id in this case
     }
     finalListToUpdate.add(EveryCase);
    
 }
Try{
    If(!finalListToUpdate.IsEmpty()){
        Updte finalListToUpdate;
    }
}
Catch(Exception e){
    system.debug(e.getMessage());
}
There are two ways of doing this I believe,
1) Using Developer Console and 2) Using Data Loader.
 

All Answers

Felix Jong Seok ChaeFelix Jong Seok Chae
Also how do I access to account_name, subject, etc. of 'related cases' in the developer console?
HARSHIL U PARIKHHARSHIL U PARIKH
There is a field on Case record named "Parent Case" and it is hidden by default so if its not visiable to you then you can get that from edit layout link.
Now, just update (using data loader) all the 'related cases' Parent Case field with the ID of the case you need to attach under to (or in other words ID of parent Case).
At a time, one case can have only one Parent Case only.

As far as getting Account Name field, you can go to the Edit Page Link from the case record layout and get it from the dialogue bix like below,

User-added image

Just to remember that "Description" field won't appear in that dialogue box since its too long to be shown under the related list :)

Hope this helps mark it best if its solves the query!
 
Felix Jong Seok ChaeFelix Jong Seok Chae
I am sorry I should have emphasized it. I already have a list whose elements are cases in the "developer console" and I want to find a way to create url of these cases in the list for the new case also in the developer console.
 
HARSHIL U PARIKHHARSHIL U PARIKH
Okay so this is what i am undderstanding:

You have let's say 50 old cases into your org and one new case let's say the name "New Case - 1." Now, you are trying to attach means you are trying to make all of these 50 old cases as a childs of this "New Case - 1." Correct?

If yes, then I would ask one question, Are these 50 cases already have value in Parent Case field? Means are they already a child of some other cases? If they are already a child of other cases (other than "New Case - 1") then you can not make them child for "New Case -1."

One case can have many child cases. But one case can have only one parent. It's like an opportunity, one opportunity can have only one account or one opportunity can be associated with one account only but one account can have multiple opportunities.

Now, if those 50 cases doesn't have any parent (means Parent Case field is blank) then you can easily make all of them a child of "New Case - 1" by using data loader.
Your excel file would have two columns only:
Id & Parent Case. In Id you will have all of these 50 cases IDs one by one and on Parent Case you will have ID of "New Case - 1" 50 times (each time in each row).

Hope this helps!
Felix Jong Seok ChaeFelix Jong Seok Chae
Thank you for your detailed answer. I executed my program with the following code, but nothing appeared in both parentid field of a old case and related case field of a new case. My goal is to create a link to each old case so that customer can see references from some field of a new case. 
for (Case oldCase: oldCases) {
            oldCase.ParentId = newCase.Id;
}
HARSHIL U PARIKHHARSHIL U PARIKH
I would try using the following code:
 
List<Case> listOfOldCases = New List<Case>();
// I am imagine that you have all the cases stored in this list called: listOfOldCases 

List<Case> finalListToUpdate = New List<Case>();

 For(Case EveryCase : listOfOldCases )
 {
     If(EveryCase.ParentId != Null)
     {
         EveryCase.ParentId = '50046000001quNs';
          // Of course, put your newCase.Id here. You can also hardcode Id in this case
     }
     finalListToUpdate.add(EveryCase);
    
 }
Try{
    If(!finalListToUpdate.IsEmpty()){
        Updte finalListToUpdate;
    }
}
Catch(Exception e){
    system.debug(e.getMessage());
}
There are two ways of doing this I believe,
1) Using Developer Console and 2) Using Data Loader.
 
This was selected as the best answer
Felix Jong Seok ChaeFelix Jong Seok Chae
Thank you for the code, but I still don't see any change in new case's related cases field nor in old case' parent case field.
I also looked up all fields that may be associated with related cases field, but I couldn't find such field. Do you know the field for 'related cases'?
Felix Jong Seok ChaeFelix Jong Seok Chae
Govind, your code was correct except I should change a part of a conditional statement in line 8 to (== null).
Thank you so very much for your help : - )