+ Start a Discussion
NevDevNevDev 

Trigger that updates a text field with a specific value based on picklist fields

I have a requirement where I need a text field to update with a specific value based on other picklist field values selected.
I need it to be configured using a trigger as there is already another trigger running on the same object. I have already configured this in process builder but I am getting an unhandled error message due to the existing trigger.
So what I need is the follow

Picklist_1__c = CIF
Picklist_2__c = Air

Text_Field__c = 4%
Veena GopalVeena Gopal

Hellos,
Could you please give more detail on the error message encountered by you. 
The below is the execution order in salesforce and process builder workflows comes in the end and triggers have executed way before.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm

The unhandled error message could be because of some other reason because process builder will not come in way of trigger execution.
Regards,
Veena.
 

NevDevNevDev
Hi Veena,

This is the error that I am getting

"Apex trigger OpportunityTrigger caused an unexpected exception, contact your administrator: OpportunityTrigger: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 006g000000EpgiFAAR; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 30146000000PnDU. Flow error messages: An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: []: Class.OpportunityTriggerHandler.pushFieldValuetoProject: line 242, column 1"
NevDevNevDev
I just received this email:

This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.

Flow Details
Flow Name: Calc_Incoterms_Shipping_Adjustment
Type: Workflow
Version: 6
Status: Active

Flow Interview Details
Interview Label: Calc_Incoterms_Shipping_Adjustment-6_InterviewLabel
Current User: Nevin O'Regan (00546000000sHXc)
Start time: 09/07/2017 21:28
Duration: 0 seconds

How the Interview Started
Nevin O'Regan (00546000000sHXc) started the flow interview.
Some of this flow's variables were set when the interview started.
myVariable_old = 006g000000EpgiFAAR
myVariable_current = 006g000000EpgiFAAR

ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
Result
{!myVariable_waitStartTimeVariable} = "09/07/2017 21:28"

DECISION: myDecision
Executed this outcome: myRule_1
Outcome conditions: and
1. {!myVariable_current.Incoterms__c} (C&F) Equals C&F
2. {!myVariable_current.Shipping_Mode__c} (By Land) Does not equal By Air
Logic: All conditions must be true (AND)

RECORD UPDATE: myRule_1_A1
Find all Opportunity records where:
Id Equals {!myVariable_current.Id} (006g000000EpgiFAAR)
Update the records’ field values.
Incoterms_Shipping_Adjustment__c = 1.04
Result
Failed to update records that meet the filter criteria.

Error Occurred: The flow tried to update these records: null. This error occurred: LIMIT_EXCEEDED: System.LimitException: Too many SOQL queries: 101. For details, see API Exceptions.
D-CoderD-Coder
Go for workflow field update. Create one field update action for Text_Field__c. In formula editor , add your logic using Picklist_1__c and Picklist_2__c and then set calculated text value in Text_Field__c.
HARSHIL U PARIKHHARSHIL U PARIKH
Are those two pick-lists values such as Picklist_1__c = CIF, and Picklist_2__c = Air are getting populated using Trigger?

If yes, then you can definitely create workflow and set the calculated logic for that Text_Field__c.

In addition, make sure you are putting text under the double quotations etc.. Also it there is still an issue then post your trigger and we will see if we can fit the workflows code/automation inside the trigger and you might not need an workflow or process builder.

Triggers are fired before workflows.

Hope this helps!
Veena GopalVeena Gopal
Hello, if you have already set up the process builder, it will be wise enough to disable the trigger if it is doing the same thing.
if it is not for the same action then please put the trigger code and we will be able to find out what error it is having.
The question is kinda misleading to somewhere else but the error is due to something else.
Veena.