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
Minhaj Arifin 5Minhaj Arifin 5 

Identify Cases with a Value and then Update those Records

Hello, 
I want to identify all cases that have the 'Case Origin' field set to 'email'. I then want to update these records with a new  'Case Origin' value of 'Phone'. Can you please explain how I would go about doing this? It would be helpful if you can write out the code as well. Thanks! 
Best Answer chosen by Minhaj Arifin 5
NatsuNatsu
//1. use query to get the list of cases where origin is email
//2. iterate on the list and update origin to phone

list<Case> caseList=[select id from case where Origin='Email'];
for(Case c:caseList){
   c.origin='Phone';
}

update caseList;

 

All Answers

NatsuNatsu
//1. use query to get the list of cases where origin is email
//2. iterate on the list and update origin to phone

list<Case> caseList=[select id from case where Origin='Email'];
for(Case c:caseList){
   c.origin='Phone';
}

update caseList;

 
This was selected as the best answer
Minhaj Arifin 5Minhaj Arifin 5
oh that worked beautifully, thanks Natsu!