2

I've a question with this trigger. I checked the register and it launch the trigger but is not doing anything. It doesnt show me the debug messages, even the first one.

The idea is that when we are creating a new Account, it has to create an event.

Any help will be thankful.

Thanks everybody for your time.

trigger CreateActivity on Account (after insert){    

List<date> dateList = new List<date>();
List<Event> EventList = new List<Event>();
Util_Fechas parse = new Util_Fechas();

system.debug('It is in the Trigger');
for(Account acc : Trigger.new){
    system.debug('It is in the For');
    if(acc.CustomField__c != null){
        system.debug('It is in the If');
        string day = 'Tuesday';
        integer coef = 1;
        Date LookedDay = parse.rellenar_datelist(day, coef);
        system.debug(LookedDay);
        dateList.add(LookedDay);
        EventList.add(new Event(
            //OwnerId = acc.CreateById,
            WhatId = acc.Id,
            CustomField2__c = 'Whatever',
            ActivityDate = LookedDay,
            DurationInMinutes = 60
        ));
    }
}
insert EventList;
}
  • 1
    Have you tried using a workflow rule to create a task? – martin Jul 17 '15 at 10:54
  • 1
    Thanks martin, I'm checking right now. But i would like to know two different things: 1- Why is a workflow more appropriate than a trigger? 2- If it is... anyway, where is my mistake in this code? It's important to me learning as much as possible. Thanks again! – Carloss Jul 17 '15 at 10:59
  • 1
    Are you getting an exception ? if not did you trigger arrive correctly at system.debug('It is in the If'); ? – Amit Bangad Jul 17 '15 at 11:02
  • 1
    No Amit Bangad; the trigger doesnt arrive even to ("it is in the trigger") but in the register it is created: "Operación /setup/build/viewApexTrigger.apexp" – Carloss Jul 17 '15 at 11:03
  • 1
    nop... the trigger is not being launched... :S – Carloss Jul 17 '15 at 11:17
1

Each time you edit a trigger in the ui, the trigger is automatically deactivated and you need to manually re-check the checkbox.

Honestly, this is more a bug in the salesforce ui than anything. It's left me scratching my head dozens of times before I got in the habit of looking for it.

  • 1
    That's a bug. I almost never create triggers that way. Use Mavesn/Sublime – Michael Gill Jul 17 '15 at 12:46
1

Finally it works!

What was happening?

  1. @martin: The ui for some reason deactivates triggers each time you edit them
  2. @Michael Gill: I think you are missing some required fields.

Noob problems.

Thank you all.

  • 1
    I would still do the process and not the trigger. – Michael Gill Jul 17 '15 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.