• Anthony Doyle
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

We only assign Account Numbers for accounts with type of "Client" or "Custom Client" and our account numbers are formatted using six characters like this '001234'. I'm trying to write a trigger that will update the account number field with the next available account number. I created a custom object called, Next_Values__c that has a field called "Next_Account_Number__c". There will only ever be one record in this object and that value will be the next Account Number to use.

 

I'm trying to select the Next_Account_Number__c value from the object, loop through the inserted accounts and assign the next account number value, then add one to the value and assign it to the next account. At the end I want to update the Next Account Number field with the next number.

 

I'm having two problems....adding 1 to my Next_Account_Number__c and also padding the Next_Account_Number__c with the proper amount of zeros on the left. On line 24, I'm getting an error Save error: Illegal assignment from Integer to SET<Integer>. And the lpad function doesn't work. I'm getting this error: Save error: Method does not exist or incorrect signature: lpad(String, Integer, String). The leftpad funtion will only put spaces on the left.

Here's my trigger:

trigger UpdateNewClientInfo on Account (before insert, before update) {
	if (trigger.isInsert){
		// create a list of account ids to update
        Set<id> accountIds= new Set<id>();
        for (Account a : Trigger.new){
        	if (a.Type == 'Client' || a.Type == 'Custom Client'){
        	 accountIds.add(a.Id); 	
        	} 
        }
        // make a map of the Next_Account_number value and assign it to a variable
        Set<Integer> nextAccountNumber = new Set<Integer>();
        for (Next_Values__c nextNumber : [Select Next_Account_Number__c From Next_Values__c WHERE Name ='1']){
        	nextAccountNumber.add(Integer.ValueOf(nextNumber.Next_Account_Number__c));
        }
        
        // create a map for a lookup / hash table for the account info
        Map<id, Account> accts = new Map<id, Account>([Select AccountNumber from Account Where Id in :accountIds]);  
         
         // iterate over the list of records being processed in the trigger and set the AccountNumber
        for (Account a1 : Trigger.new){
        	if (accts.ContainsKey(a1.ID)){
                a1.AccountNumber = String.valueof(nextAccountNumber); 
                //a1.AccountNumber = lpad(String.valueof(nextAccountNumber), 6, '0'); 
                nextAccountNumber = Integer.ValueOf(nextAccountNumber) +1;
                
        	}
        }
        
		//for(Next_values__c n : nextAccountNumber){
		//	n.Next_Account_Number__c = String.ValueOf(newAccountNumber);
		//}
        //update nextAccountNumber;
	}
}

 

 

 

This is Non-Profit where we are trying to integrate the community of volunteers through Chatter Free user accounts.

 

The first step would be creating a button on Volunteer Contact Records creating Chatter Free user accounts for each volunteer, using the contact email.

 

I have succeeded creating a Chatter Free account through apex data loader.

 

I am looking for limitations on this matter... but as wierd as it looks, I haven't found any.

 

Any suggestions?

 

Many thanks.

 

David.