You need to sign in to do that
Don't have an account?

Help with challenging Account Number Trigger Requirement
Greetings,
I'm new to apex and have been trying to design a trigger that would populate the Account Number field with a value starting at 10000, when the Opportunity Probability moves to 85%. Before I added my 'if' statements, it worked fine, but after that nothing. I even tried writing the trigger on Opportunity and Account objects.
I created a custom object accNumber__c and custom field Ones__c, where the generated number would be stored.
Please, please, i need some help on this one. Here is what I have so far:
I'm new to apex and have been trying to design a trigger that would populate the Account Number field with a value starting at 10000, when the Opportunity Probability moves to 85%. Before I added my 'if' statements, it worked fine, but after that nothing. I even tried writing the trigger on Opportunity and Account objects.
I created a custom object accNumber__c and custom field Ones__c, where the generated number would be stored.
Please, please, i need some help on this one. Here is what I have so far:
trigger AccountNumberUpdate on Opportunity(before insert, before update) { accNumber__c value = new accNumber__c(Name='1',Ones__c=0); for(accNumber__c record:[SELECT Id,Name,Ones__c FROM accNumber__c WHERE Name='1' FOR UPDATE]) { value = record; } for(Opportunity opps:Trigger.new) { if((opps.Probability>=85)&&(opps.Account.Region__c=='Americas')&&(opps.AccountNumber==null)) { opps.Account.AccountNumber ='0'.repeat(math.max(0,0-String.valueOf(value.Ones__c).length()))+String.valueOf(value.Ones__c); value.Ones__c+=1; } } update value; }The Account object is a lookup on the Opportunity object. Is there another way I can approach this problem? Any help is appreciated.
My bsad,I forgot to update the Account.Try below code,this should work :-
If this helps,please mark it as best answer to help others :)
All Answers
Try to elaborate in detail,then we can help you !!
You don't need custom object,just a Trigger on Opportunity would work.Try below code :-
If this helps,please mark it as best answer to help others :)
If this helps,please mark it as best answer to help others :)
Is there a way to have this assign a sequential number, so that if an Account Number = 10000, then the next will be 10001, 10002,...and so on? Thanks
If this helps,please mark it as bestanswer to help others :)
Try this one,I think this should work :-
If this helps,please mark it as best answer to help others :)
My bsad,I forgot to update the Account.Try below code,this should work :-
If this helps,please mark it as best answer to help others :)
http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_agg_functions.htm
Hope this helps !!