Question
I have an issue where by I need a temporary fix, I am trying to create a method of looking at a string of text on the opportunity and replacing all the $ with £ (custom text field)
A trigger example I found is
trigger YourTrigger on Solution (before update) {
for(Solution s : trigger.new) {
s.replaceAll('Hello World','Goodbye World');
}
}
but if possible I would rather have a button on the opportunity that could provide this functionality. I also need to limit this trigger to fire only on opptys that match a pre specified field criteria eg checkbox__c = true
Best Answer
Why would you need to this with a Trigger? You could do this with a Workflow Rule+ Field Update. Something like this:
- Setup | Create | Workflows & Approvals | Workflow Rules
- New Rule
- Select the Object: Opportunity
- Evaluation Criteria: created and every time it’s edited [2nd Option]
- Rule Criteria: formula evluates to true
-
Formula:
AND( Checkbox_Field__c = TRUE, NOT(ISBLANK(Text_Field__c)), FIND('$', Text_Field__c) >= 1, OR( ISNEW(), ISCHANGED(Text_Field__c), ISCHANGED(Checkbox_Field__c) ) )
- Click Save & Next
- From under Immediate Workflow Actions, click Add Workflow Action to select Field Update
- Select the Field to Update: Opportunity: Text Field
- Select Use a Formula to Set the New Value
-
Formula:
SUBSTITUTE(Text_Field__c, '$', '£')
- Click Save
- Click Done
- Click Activate
No comments:
Post a Comment