+ Start a Discussion

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


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


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;