+ Start a Discussion
Baktash H.Baktash H. 

Batchable trigger?



i have written a trigger which does a small fieldupdate on the created record. It is after insert.

I did a bit of research about apex batch, but didn't find anything specific to my problem.


No do I need to learn everything about apex batch or can you tell me what i need to know, maybe you can give me links to the knowledge i need.



Baktash H.Baktash H.

I tried it like in the example:


List<Account> aList = [SELECT Id,(SELECT Name FROM Contracts) FROM Account WHERE Id IN : Trigger.newMap.keySet()];


I made a System.Debug, and aList is empty! How is this possible, the trigger is after insert, and that is the first line.





Is this code on the account trigger or somewhere else?


Could you not do this using a workflow rule with field update or a formula field?

Baktash H.Baktash H.

If found my mistake, the trigger was on Contract not on account.

Now it looks like this:


trigger tName on Contract (after insert) {

            List<Contract> cList = [SELECT Name FROM Contract WHERE Id IN :Trigger.newMap.keySet()];

            List<Contract> ContractsToUpdate = new List<Contract>();


            for(Contract c : cList){

                  c.Name = 'something';



            update ContractsToUpdate;   



This works if I insert a contract over the pagelayout. How can I test it over the api? Do I need the dataloader?

And what do you think is the limit of contracts which can be inserted, with my solution.