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
stcforcestcforce 

HELP add error and create separate object

hello all,
I am trying to add an error on event when the event being entered coincides with existing. I want to be able to rollback the entire operation but create a separate object that is not included in the rollback. I would be grateful for any help that could be offered. If you have some expertise and believe it to be impossible, i would grateful if you would tell me - I have been trying to get a definitive answer for the last two weeks (good times.).



specifics:
1) I do not have access to the calling apex and as such cannot enclose it in a try/catch block. The event creation is occuring via the standard calendar interface. As such, I don't have access to override the calling methods and the people for whom i am writing this code are not organised enough to deploy greasemonkey to override the button. I am thus forced to find a means within a trigger to a) rollback and b) create a separate object that is not subject to the rollback. THESE HAVE TO OCCUR WITHIN A SINGLE TRANSACTION.
2) the desired behavior is on a new event to determine if it has a conflict and if so, rollback and create a object to log conflicts. A subsequent attempt to add a meeting with the same details will find the object storing the conflict and save anyway. A SECOND, MATCHING INSERT OPERATION OVERRIDES A CONFLICT.

 

i appreciate any help. thank you.
stc.

Ispita_NavatarIspita_Navatar

Hi stcforce,

Do try the following:-

1. In the trigger on event object while insertion is happening put the logic for checking conflict in case there is an error/conflict you can raise an error as follows:-

  • Trigger.new.myField__C.addError('bad conflict'); if the adderror is put in before insert the error will be shown on the UI of event creation page and there wont be any need of rollback
  • Also you can create another record as desired by you in another object to log the conflicts.

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

stcforcestcforce

Hi Ispita,

That probably would do the trick, though the initial lack of response meant that i made some slighly different design decisions. I was never that happy with the requirement and have just opted to email the user in the event of conflicts, thus not needing to add the error at all. Thank you.

stc.

stcforcestcforce

Hi Ispita,

i tried it and it did not commit the object created - seeming to rollback. As such it doesn't really do what i needed it to. I have talked with Bob Buzzard, this here forum's most frequent contributor, and he more or less stated that it couldn't be done. Thank you anyway.

apaiapai

Hi,

 

Allow the event to be inserted in the before insert trigger and also, create the other new object.

 

In the after insert trigger, delete the newly created event based on the error criteria.

 

Hope this helps !

 

Cheers.