Getting System.FinalException: Record is read-only when PB calls an apex class
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I am getting this error whenever my Process builder calls an Apex Class. I'm not sure if this is allowed so I'd like to ask for your input.
So basically, my Process Builder is in the Case object and it is triggered when User sends an email to a Queue.
When this happens, the Process Builder then calls an Apex class with an invocable method below:
@InvocableMethod
public static void methodA(List<Case> caseList)
//do some SOQL code here to determine xxxxxxxx
for(Case c : caseList)
c.contactId = 'xxxxxxxx';
update caseList;
Basically, the method just changes the contact Id of the case to something else and then updates the Case.
However, I instead get this error every time I send an email to the Queue.
An Apex error occurred: System.FinalException: Record is read-only
It would seem that I am not allowed to update the contactId of the Case. Is this correct?
If so, then how can I update the contactId of the Case by the Apex Class?
Thanks.
apex process-builder invocable-method order-of-execution
add a comment |Â
up vote
2
down vote
favorite
I am getting this error whenever my Process builder calls an Apex Class. I'm not sure if this is allowed so I'd like to ask for your input.
So basically, my Process Builder is in the Case object and it is triggered when User sends an email to a Queue.
When this happens, the Process Builder then calls an Apex class with an invocable method below:
@InvocableMethod
public static void methodA(List<Case> caseList)
//do some SOQL code here to determine xxxxxxxx
for(Case c : caseList)
c.contactId = 'xxxxxxxx';
update caseList;
Basically, the method just changes the contact Id of the case to something else and then updates the Case.
However, I instead get this error every time I send an email to the Queue.
An Apex error occurred: System.FinalException: Record is read-only
It would seem that I am not allowed to update the contactId of the Case. Is this correct?
If so, then how can I update the contactId of the Case by the Apex Class?
Thanks.
apex process-builder invocable-method order-of-execution
Do you have any trigger written on case?
– Tushar Sharma
1 hour ago
Rather than calling invocable method, you could update in PB field update action
– Santanu Boral
1 hour ago
there is a trigger in the case but it is for a different action. I don't think it is related to this or has any affect on this.
– Jerard Dela Victoria
1 hour ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am getting this error whenever my Process builder calls an Apex Class. I'm not sure if this is allowed so I'd like to ask for your input.
So basically, my Process Builder is in the Case object and it is triggered when User sends an email to a Queue.
When this happens, the Process Builder then calls an Apex class with an invocable method below:
@InvocableMethod
public static void methodA(List<Case> caseList)
//do some SOQL code here to determine xxxxxxxx
for(Case c : caseList)
c.contactId = 'xxxxxxxx';
update caseList;
Basically, the method just changes the contact Id of the case to something else and then updates the Case.
However, I instead get this error every time I send an email to the Queue.
An Apex error occurred: System.FinalException: Record is read-only
It would seem that I am not allowed to update the contactId of the Case. Is this correct?
If so, then how can I update the contactId of the Case by the Apex Class?
Thanks.
apex process-builder invocable-method order-of-execution
I am getting this error whenever my Process builder calls an Apex Class. I'm not sure if this is allowed so I'd like to ask for your input.
So basically, my Process Builder is in the Case object and it is triggered when User sends an email to a Queue.
When this happens, the Process Builder then calls an Apex class with an invocable method below:
@InvocableMethod
public static void methodA(List<Case> caseList)
//do some SOQL code here to determine xxxxxxxx
for(Case c : caseList)
c.contactId = 'xxxxxxxx';
update caseList;
Basically, the method just changes the contact Id of the case to something else and then updates the Case.
However, I instead get this error every time I send an email to the Queue.
An Apex error occurred: System.FinalException: Record is read-only
It would seem that I am not allowed to update the contactId of the Case. Is this correct?
If so, then how can I update the contactId of the Case by the Apex Class?
Thanks.
apex process-builder invocable-method order-of-execution
apex process-builder invocable-method order-of-execution
edited 1 hour ago


Oleksandr Berehovskiy
6,50611532
6,50611532
asked 1 hour ago
Jerard Dela Victoria
485
485
Do you have any trigger written on case?
– Tushar Sharma
1 hour ago
Rather than calling invocable method, you could update in PB field update action
– Santanu Boral
1 hour ago
there is a trigger in the case but it is for a different action. I don't think it is related to this or has any affect on this.
– Jerard Dela Victoria
1 hour ago
add a comment |Â
Do you have any trigger written on case?
– Tushar Sharma
1 hour ago
Rather than calling invocable method, you could update in PB field update action
– Santanu Boral
1 hour ago
there is a trigger in the case but it is for a different action. I don't think it is related to this or has any affect on this.
– Jerard Dela Victoria
1 hour ago
Do you have any trigger written on case?
– Tushar Sharma
1 hour ago
Do you have any trigger written on case?
– Tushar Sharma
1 hour ago
Rather than calling invocable method, you could update in PB field update action
– Santanu Boral
1 hour ago
Rather than calling invocable method, you could update in PB field update action
– Santanu Boral
1 hour ago
there is a trigger in the case but it is for a different action. I don't think it is related to this or has any affect on this.
– Jerard Dela Victoria
1 hour ago
there is a trigger in the case but it is for a different action. I don't think it is related to this or has any affect on this.
– Jerard Dela Victoria
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
let me guess, that records, that are sent to Apex are sent from Process as "Select the Case record that started your process". According to the Order of Execution process is launched after after triggers
. And if you are sending context records, looks like they all have "isReadOnly" flag on the sObject records. This flag is responsible for causing the FinalException. This is similar to situation, when you are trying to change trigger context records in after
trigger event. In order to update records from current transaction, create new Case
record with predefined Id
.
@InvocableMethod
public static void methodA(List<Case> caseList)
List<Case> toUpdate = new List<Case>();
for(Case c : caseList)
toUpdate.add(new Case(
Id = c.Id,
ContactId = 'xxxxxxxx';
));
update toUpdate;
Thanks for this example. I tried adding your AsyncUpdater code and see if it works but I still get the issue when I call AsyncUpdater.run. The error is still about read-only.
– Jerard Dela Victoria
1 hour ago
@JerardDelaVictoria I have updated my answer, check this variant
– Oleksandr Berehovskiy
45 mins ago
my friend, your code works! Thank you so much! I knew that I was missing something, but I just couldn't figure out what it was. Your explanation was also clear and it helped me understand where I got it wrong. Again, this code now works and thank you very much!
– Jerard Dela Victoria
13 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
let me guess, that records, that are sent to Apex are sent from Process as "Select the Case record that started your process". According to the Order of Execution process is launched after after triggers
. And if you are sending context records, looks like they all have "isReadOnly" flag on the sObject records. This flag is responsible for causing the FinalException. This is similar to situation, when you are trying to change trigger context records in after
trigger event. In order to update records from current transaction, create new Case
record with predefined Id
.
@InvocableMethod
public static void methodA(List<Case> caseList)
List<Case> toUpdate = new List<Case>();
for(Case c : caseList)
toUpdate.add(new Case(
Id = c.Id,
ContactId = 'xxxxxxxx';
));
update toUpdate;
Thanks for this example. I tried adding your AsyncUpdater code and see if it works but I still get the issue when I call AsyncUpdater.run. The error is still about read-only.
– Jerard Dela Victoria
1 hour ago
@JerardDelaVictoria I have updated my answer, check this variant
– Oleksandr Berehovskiy
45 mins ago
my friend, your code works! Thank you so much! I knew that I was missing something, but I just couldn't figure out what it was. Your explanation was also clear and it helped me understand where I got it wrong. Again, this code now works and thank you very much!
– Jerard Dela Victoria
13 mins ago
add a comment |Â
up vote
2
down vote
accepted
let me guess, that records, that are sent to Apex are sent from Process as "Select the Case record that started your process". According to the Order of Execution process is launched after after triggers
. And if you are sending context records, looks like they all have "isReadOnly" flag on the sObject records. This flag is responsible for causing the FinalException. This is similar to situation, when you are trying to change trigger context records in after
trigger event. In order to update records from current transaction, create new Case
record with predefined Id
.
@InvocableMethod
public static void methodA(List<Case> caseList)
List<Case> toUpdate = new List<Case>();
for(Case c : caseList)
toUpdate.add(new Case(
Id = c.Id,
ContactId = 'xxxxxxxx';
));
update toUpdate;
Thanks for this example. I tried adding your AsyncUpdater code and see if it works but I still get the issue when I call AsyncUpdater.run. The error is still about read-only.
– Jerard Dela Victoria
1 hour ago
@JerardDelaVictoria I have updated my answer, check this variant
– Oleksandr Berehovskiy
45 mins ago
my friend, your code works! Thank you so much! I knew that I was missing something, but I just couldn't figure out what it was. Your explanation was also clear and it helped me understand where I got it wrong. Again, this code now works and thank you very much!
– Jerard Dela Victoria
13 mins ago
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
let me guess, that records, that are sent to Apex are sent from Process as "Select the Case record that started your process". According to the Order of Execution process is launched after after triggers
. And if you are sending context records, looks like they all have "isReadOnly" flag on the sObject records. This flag is responsible for causing the FinalException. This is similar to situation, when you are trying to change trigger context records in after
trigger event. In order to update records from current transaction, create new Case
record with predefined Id
.
@InvocableMethod
public static void methodA(List<Case> caseList)
List<Case> toUpdate = new List<Case>();
for(Case c : caseList)
toUpdate.add(new Case(
Id = c.Id,
ContactId = 'xxxxxxxx';
));
update toUpdate;
let me guess, that records, that are sent to Apex are sent from Process as "Select the Case record that started your process". According to the Order of Execution process is launched after after triggers
. And if you are sending context records, looks like they all have "isReadOnly" flag on the sObject records. This flag is responsible for causing the FinalException. This is similar to situation, when you are trying to change trigger context records in after
trigger event. In order to update records from current transaction, create new Case
record with predefined Id
.
@InvocableMethod
public static void methodA(List<Case> caseList)
List<Case> toUpdate = new List<Case>();
for(Case c : caseList)
toUpdate.add(new Case(
Id = c.Id,
ContactId = 'xxxxxxxx';
));
update toUpdate;
edited 46 mins ago
answered 1 hour ago


Oleksandr Berehovskiy
6,50611532
6,50611532
Thanks for this example. I tried adding your AsyncUpdater code and see if it works but I still get the issue when I call AsyncUpdater.run. The error is still about read-only.
– Jerard Dela Victoria
1 hour ago
@JerardDelaVictoria I have updated my answer, check this variant
– Oleksandr Berehovskiy
45 mins ago
my friend, your code works! Thank you so much! I knew that I was missing something, but I just couldn't figure out what it was. Your explanation was also clear and it helped me understand where I got it wrong. Again, this code now works and thank you very much!
– Jerard Dela Victoria
13 mins ago
add a comment |Â
Thanks for this example. I tried adding your AsyncUpdater code and see if it works but I still get the issue when I call AsyncUpdater.run. The error is still about read-only.
– Jerard Dela Victoria
1 hour ago
@JerardDelaVictoria I have updated my answer, check this variant
– Oleksandr Berehovskiy
45 mins ago
my friend, your code works! Thank you so much! I knew that I was missing something, but I just couldn't figure out what it was. Your explanation was also clear and it helped me understand where I got it wrong. Again, this code now works and thank you very much!
– Jerard Dela Victoria
13 mins ago
Thanks for this example. I tried adding your AsyncUpdater code and see if it works but I still get the issue when I call AsyncUpdater.run. The error is still about read-only.
– Jerard Dela Victoria
1 hour ago
Thanks for this example. I tried adding your AsyncUpdater code and see if it works but I still get the issue when I call AsyncUpdater.run. The error is still about read-only.
– Jerard Dela Victoria
1 hour ago
@JerardDelaVictoria I have updated my answer, check this variant
– Oleksandr Berehovskiy
45 mins ago
@JerardDelaVictoria I have updated my answer, check this variant
– Oleksandr Berehovskiy
45 mins ago
my friend, your code works! Thank you so much! I knew that I was missing something, but I just couldn't figure out what it was. Your explanation was also clear and it helped me understand where I got it wrong. Again, this code now works and thank you very much!
– Jerard Dela Victoria
13 mins ago
my friend, your code works! Thank you so much! I knew that I was missing something, but I just couldn't figure out what it was. Your explanation was also clear and it helped me understand where I got it wrong. Again, this code now works and thank you very much!
– Jerard Dela Victoria
13 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f233860%2fgetting-system-finalexception-record-is-read-only-when-pb-calls-an-apex-class%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Do you have any trigger written on case?
– Tushar Sharma
1 hour ago
Rather than calling invocable method, you could update in PB field update action
– Santanu Boral
1 hour ago
there is a trigger in the case but it is for a different action. I don't think it is related to this or has any affect on this.
– Jerard Dela Victoria
1 hour ago