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
alex_from_parisalex_from_paris 

Issue on mass update and trigger : trigger does not always work but no error

Hello

I am using bulk api to insert object instance in Force.com

I have defined a trigger on before insert, update

 

Map<String, Visite__c> myorgalist = new Map<String, Visite__c>();

for (Visite__c evt : Trigger.new) {
        myorgalist.put(evt.Organization__c,evt);
}

 

for (FAI_Blind__c myorga: [Select Name__c from FAI_Blind__c where Name__c IN :myorgalist.keySet()] )
    {
        Visite__c myvisit=myorgalist.get(myorga.Name__c);
         myvisit.Type__c='FAI BLIND';
         myvisit.Finished__c=true;
     }

 

Insertion works perfectly (job with batches with 100 insert) but when I look at the result in SF, I have some visit that should have been found in my loop and trigger did not found it (TYPE is NOT FOUND : default value).

If I edit the visit and save it, trigger work wells and visit is found in the loop -> Type is changed to FAI BLIND

Do you have any idea of what is going wrong ? Bad script ? Performance issue ?

Do you know a workaround ?

Thanks for your help

Regards

Mojtaba NasiriMojtaba Nasiri

Hi there,

 

try insert with batches of less than 20.

i was facing somewhat the same issue yesterday and this resolved it.

 

let me know if it works.

 

Mojtaba

alex_from_parisalex_from_paris

Hi

I have tried that (10 inserts) : result is better but no perfect - I have written a javascript button to update visit (one by one) and there is still a little gap.

Indeed I have not written complete code : in my trigger I perform 5 loops request on different fields so ....

In any case, thanks for your help : I am happy my code is good but if anyone has another workaround... he is welcome

Regards

alex_from_parisalex_from_paris

Hi

I have received support from SF expert guy and I found my issue

In fact I was creating a map with a value that could be inserted several time (ex : user location) in the same batch

What I did not know was that a map only add value,id only when value is not already in the map

Therefore in my mass update trigger, it was only treating some of my insert record

By reducing inserting step, I have less chance to get twice same value so it was working well

Hope this will help you

Regards