0

We’ve a sync between Salesforce and Remedy. On Salesforce Case Detail page, we’ve a specific button (synchRemedy ) that syncs the Case from salesforce to Remedy and after the case is synced to remedy the field called “isSynced “gets populated with value “Yes”( It is a formula field).

We’ve another field called “Remedy Assigned To Group”.

I am trying to write a trigger, applicable to all Cases: Where the Remedy Assigned to Group is ‘Support’ and the Support rep is hitting ‘synchRemedy’ button, it changes the picklist value for Remedy Assigned to Group from “Support” to “Repair Services”.

I can do this using workflow, but I want this value to be updated before case is synced to remedy so Remedy receives the updated value of “Repair Services”.

Hitting the ‘syncRemedy’ button twice (when using workflow) is doing the job, but that is not the path I want to take.

Below is the trigger and the test class I’ve written but it is giving me the error: Field is not writeable: Case.IsSynced__c Please advise.

Apex Trigger:

trigger ChangeRemedyAssignedtoGroup on Case (before update) {
    for( Case c: Trigger.New){
        if(c.Remedy_Assigned_To__c == 'Support' && c.IsSynced__c == 'Yes'){
            c.Remedy_Assigned_To__c = 'Repair Services';
        }

    }
}

#

Test Class:

@isTest
private class ChangeRemedyAssignedtoGroupTest {
    @isTest static void updateCase(){
        Case c = new Case();
        c.Remedy_Assigned_To__c = 'Support';
        insert c;
    }

}

#

10
  • Your question code doesn't match the question's text. I don't see any compilation errors here. Perhaps you meant to say that "Remedy Assigned To" is a formula?
    – sfdcfox
    Apr 13, 2016 at 19:50
  • “Remedy Assigned To Group” is a picklist field(Remedy_Assigned_To__c). Al I am trying to do with this trigger is update the value from "Support" to "Service Repair" before case gets synced over from salesforce to Remedy. When Support agent hits on the syncRemedy button, case gets synced over to remedy which also change the isSyynced filed to value "Yes".
    – sfdcDev
    Apr 13, 2016 at 20:03
  • Okay, well, the error "IsSynced__c is not writable" wouldn't be coming from any of the code you've posted so far. Perhaps it's coming from your button's code?
    – sfdcfox
    Apr 13, 2016 at 20:08
  • Nope it is not. I forgot the line in test class. Here is the complete Test class:
    – sfdcDev
    Apr 13, 2016 at 20:12
  • You should have used edit to modify the question instead of posting an answer. It's okay, it's a pretty common thing to do the first time around.
    – sfdcfox
    Apr 13, 2016 at 20:14

2 Answers 2

2

Formula fields are not writable, as the error states. What you'll need to do is satisfy the conditions of the formula to do your testing:

@isTest
private class ChangeRemedyAssignedtoGroupTest {
    @isTest static void updateCase(){
        Case c = new Case();
        c.Remedy_Assigned_To__c = 'Support';
        insert c;
        c.Last_Synchronized__c = DateTime.now().addSeconds(-5);
        update c;
    }
}
0
0
@isTest
private class ChangeRemedyAssignedtoGroupTest {
    @isTest static void updateCase(){
        Case c = new Case();
        c.Remedy_Assigned_To__c = 'Support';
        c.IsSynced__c = 'Yes';
        insert c;
           }

}
1
  • however it is throwing the error: Field is not writeable: Case.IsSynced__c
    – sfdcDev
    Apr 13, 2016 at 20:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .