1

I'm wondering can anyone help? I have an after insert, after update trigger on Contact that calls an @future method in a helper class to create portal users for contacts.

In an attempt to prevent passing duplicate lists contacts to this method to create users for (caused by the same Trigger code generating the same list of contacts to create as users for insert & update transactions) I set a flag to true after the first pass of the Trigger to indicate that I don't want the same action done in a second pass. After my workflows run they update the contact record and so cause the after update of the same trigger to fire & this does prevent the calling of the @future method in my helper class a second time - so this ensures that the create user code is only called once.

This all works fine in my test class code for both single & mass update tests, however, when I try to do an import via dataloader I notice that the @future method never gets executed. The trigger code does execute and checking debug logs confirms that the call is made to the @future method from my calling code in my Trigger, but for some reason it never fires the code in the @future method. If I do some manual single insert/update transactions on Contact records through the UI, the @future method does get executed.

Can anybody show me the error of my ways? Without wanting to pollute my question with lines & lines of code, here is the snippet at the end of my trigger code where I attempt to call the helper class & fire the @future method to create users for my list of contacts:

if(myContacts.size() > 0 && !ProcessorControl.isAlreadyModified()){
    System.debug('Total number of users to be created: ' + myContacts.size());
    JSONcontacts = JSON.serialize(myContacts); //Serialize list of contacts into JSON string to pass into @future method
    PortalUserHelper.createUser(JSONcontacts); //Call the Helper class and invoke the @future method
    ProcessorControl.setAlreadyModified();  //Set external static flag to true to indicate Trigger has already been executed    
}

Thanks in advance for any help that you can provide me in figuring out what I'm doing wrong.

Kind Regards,

Brian.

  • try running DataLoader with a smaller batch size than the default to see what happens; normally with future, one passes in only the set of IDs and then let the future method requery the Contacts to do the necessary Portal user creation – cropredy Dec 5 '14 at 18:42
  • Thanks for your reply but I used a very small recordset to import - 10 records. I just don't understand why the code doesn't get executed after it has been called. – Brian Casey Dec 8 '14 at 14:13

Your Answer

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

Browse other questions tagged or ask your own question.