function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Help with trigger - If formula



I'm trying to use this code:


for(Event r:{
     if (r.WhatID CONTAINS '%006%'){
          Opportunity opp = [select id,name,StageName from Opportunity where id =: r.whatID limit 1];

         r.Stage__c = opp.StageName;


What i'm trying to get, is when the r begins with 006 i paste the stagename on the filed, if not then r must be some text like "Empyt"


This is for the Event object.


Thank you!!!!


I think you want your condition to look something like:



if (r.WhatID.CONTAINS('006')){
... } //But that may give you false positives since 006 maybe be somewhere in the middle of an ID that is not an opportunity Id, so I would go with: ... if (r.WhatID.StartWith('006')){ ... } //Also, you may need to turn it into a string, so it would look like this... ... if (String.valueOf(r.WhatID).StartWith('006')){ ... }

 See if that works.  Good luck.