+ Start a Discussion
RadDude89RadDude89 

too many enum value

Hi,

We have added additional logic to an aex class on our Salesforce - the logic is applied to a custom object called Registration__c.

When you create a registration, the system will go through a number of conditions and will create a record called Credit - only if sertian criteria is met.
When we test this on our sandboxes, it works perfectly but when we attempt to register a site on production:
"Insert failed. First exception on row 0; first error: TOO_MANY_ENUM_VALUE, Credit Risk Reason: too many items selected: 18517 [Credit_Risk_Reason__c}"

Below is the code which causes the issue:
    listregQry2=[Select High_Risk_Email__c, High_Risk_Phone_Number__c from High_Risk__c]                           
                if(listregQry!=null){
                    for(Registrations__c r:listregQry){
                        String CreditComReason='';
                        if(sitenames==null||!sitenames.contains(r.site__r.name)){
                            Credit_Committee__c CCobj = new Credit_Committee__c(status__c='Referred');
                            CCobj.Comments_For_Credit_Committee__c=r.Comments_For_Credit_Committee__c;
                            sitenames.add(r.site__r.name);
                            if(listregQry2!=null){                               
                                for(Bad_Debt_Data__c r1:listregQry2){                                                                      
                                    if(r1.High_Risk_Email__c == r.site__r.contact__r.email)  {                                     
                                        System.debug('high risk email');
                                        CreditComReason=CreditComReason+'High Risk Email Found;';
                                    }
                                }
                               
                                if(r.site__r.contact__r.Phone != NULL){
                                    for(Bad_Debt_Data__c r2:listregQry2){
                            if(r2.High_Risk_Phone_Number__c == r.site__r.contact__r.Phone){ 
                                System.debug('high risk contact');
                                CreditComReason=CreditComReason+'High Risk Phone Number Found;';
                            }
                            }
                            }
                        }

Does anyone know what is causing this issue? Any ideas on how to resolve?

Any help is much appreciated.

Regards,
RadDude89

Gopal AgrawalGopal Agrawal
Hi,

Could you please provide full code here with error line?

I have found one issue:

You are referencing CCobj without inserting it.

Here is the line :

  Credit_Committee__c CCobj = new Credit_Committee__c(status__c='Referred');
// You should insert CCobj and then reference
//Insert CCobj;
  CCobj.Comments_For_Credit_Committee__c=r.Comments_For_Credit_Committee__c;

 
RadDude89RadDude89

Hi Gopal,

Thanks for the reply - the full apex class is just over 1000 lines long!

I have submitted the full logic for the credit risk creation logic:

            if(regset!=null){
                listregQry=[Select Comments_For_Credit_Committee__c,Payment_Terms__c, site__r.Contact__r.Email, site__r.Contact__r.Phone from Registrations__c where Id in : lstRegistrations];
               listregQry2=[Select High_Risk_Email__c, High_Risk_Phone_Number__c from High_Risk__c];                               
                if(listregQry!=null){
                    for(Registrations__c r:listregQry){
                        String CreditComReason='';
                        if(sitenames==null||!sitenames.contains(r.site__r.name)){
                            Credit_Committee__c CCobj = new Credit_Committee__c( status__c='Referred');
                            CCobj.Comments_For_Credit_Committee__c=r.Comments_For_Credit_Committee__c;
                            sitenames.add(r.site__r.name);
                            if(listregQry2!=null){                               
                                for(High_Risk__c r1:listregQry2){                                                                      
                                    if(r1.High_Risk_Email__c == r.site__r.contact__r.email)  {                                     
                                        System.debug('high risk email');
                                        CreditComReason=CreditComReason+'High Risk Email Found;';
                                    }
                                }
                               
                                if(r.site__r.contact__r.Phone != NULL){
                                    for(High_Risk__c r2:listregQry2){
                            if(r2.High_Risk_Phone_Number__c == r.site__r.contact__r.Phone){ 
                                System.debug('high risk contact');
                                CreditComReason=CreditComReason+'High Risk Phone Number Found;';
                            }
                            }
                            }
                        }
                                                      
                            if(r.Payment_Terms__c!='14'){
                                CreditComReason=CreditComReason+'Payment Terms;';
                            }                          
                            if(CreditComReason!=''){
                                CCobj.Comments_For_Credit_Committee__c = r.Comments_For_Credit_Committee__c;
                                CCobj.Credit_Risk_Reason__c=CreditComReason;
                                CCobj.ownerid=r.Offer_Site__r.offer__r.ownerid;
                                ListCreditCom.add(CCobj);
                            }
                        }
                        if(CreditComReason!=''){
                            r.Registration_Status__c='Pending Credit Risk Check';
                            r.Credit_Status__c='Submitted for Approval';                               
                            if(SitenamRegMap!=null){
                                if(SitenamRegMap.get(r.site__r.name)!=null)
                                    SitenamRegMap.get(r.site__r.name).add(r);
                                else{
                                    list<Registrations__c> rlist = new list<Registrations__c>();
                                     rlist.add(r);
                                     SitenamRegMap.put(r.site__r.name,rlist);
                                }
                            }
                            else{
                                list<Registrations__c> rlist = new list<Registrations__c>();
                                 rlist.add(r);
                                 SitenamRegMap.put(r.site__r.name,rlist);
                            }
                        }
                    }
                    if(ListCreditCom!=null)
                        insert ListCreditCom;                      
                    if(ListCreditCom!=null){
                        for(Credit_Committee__c cc:ListCreditCom){                         
                            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
                            req.setComments('Submitted request for approval.');
                            req.setObjectId(cc.id); 
                            Approval.ProcessResult result = Approval.process(req);
                            if(SitenamRegMap!=null && SitenamRegMap.get(cc.site_name__c)!=null)
                            for(Registrations__c rr :SitenamRegMap.get(cc.site_name__c)){
                                rr.Credit_Committee__c=cc.id;
                                ReglistRejected.add(rr);
                            }
                        }               
                    }
                }
            }

 

If that helps.

RadDude89RadDude89
The field 'Credit_Risk_Reason' that we are inserting into is a multi-picklist field - forgot to mention that