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
eduardofernandeseduardofernandes 

Problem with SOQL - MAX(row) value

Hello everyone.

I have a problem using SOQL. My problem is:

When I use the trigger to execute before insert to the salesforce get to me a value of autonumber, but this number is one less of the created. Example:

My SOQL give me back the number 10, but after the SF save the value of number is 11.

The problem is the my value if is yet: OP000035-2011

And the SOQL return to me is the value: OP000034-2011

If I change to after insert the trigger can't be execute.

Thanks for all answers

info.shailinfo.shail

What's d problem with after insert ? are u updating any field of same object ? could u share the code ?

eduardofernandeseduardofernandes

Of course.

 

 

 

trigger concatenaNomeOportunidade on Opportunity (before insert) {
   
AggregateResult[] numeroOportunidade = [SELECT MAX(oportunidadeNumero__c)NUMERO FROM Opportunity];

    for(Opportunity oportunidade : Trigger.new){
        for(AggregateResult ar : numeroOportunidade){
            String nomes = ar.get('NUMERO')+' - '+oportunidade.Name;
            oportunidade.Name = nomes;
        }      
    }  
}