Clear a field when state changes - Salesforce

683 Views Asked by At

I want to make it so that when you fill in a field (in case) X and go to a state, it is deleted (this field should be saved in the history, I think this is done by default). This is necessary so that the user does not have to be hitting the pencil and erasing the message that comes from another state.

As I saw with a Trigger it can be done, do you have any idea?

1

There are 1 best solutions below

2
On

You don't need code for it, you could do it with config changes (workflow / flow / process builder). But if you're really after a trigger - something like that.

trigger CaseTrigger on Case(before update){
    for(Case c : trigger.new){
        Case old = trigger.oldMap.get(c.Id);
        if(c.Status != old.Status){
            c.Description = null; // whichever field you want to wipe
        }
    }
}

Edit about 0 code solutions

Look into workflows, flows and process builder. Actually if you're starting fresh maybe focus on flows, the other 2 are bit passe and SF recommends migrating away: https://admin.salesforce.com/blog/2021/go-with-the-flow-whats-happening-with-workflow-rules-and-process-builder

Have a look at these and if you're stuck: consider posting at dedicated https://salesforce.stackexchange.com. StackOverflow is really for code related stuff, you'll reach more admins over there.