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
Surender reddy SalukutiSurender reddy Salukuti 

Argument 1 cannot be null An unexpected error has occurred. Your development organization has been notified.

i written this in appex class 
public class Soql_Example3 {
    public List<Account> accounts      {set;get;}
    public List<selectoption> options  {set;get;}
    
    public Soql_Example3(){
        accounts = [select id,Name,phone from account];
        options = new List<selectoption>();
        
       selectoption n = new selectoption('none','-None-');
        options.add(n);
        
        for(account a:accounts){
            selectoption op = new selectoption (a.Phone,a.name);
            options.add(op);
            
        }
        
        
        
        
        
        
    }
     
    

}

i written this in visual force
<apex:page controller="Soql_Example3" >
    <apex:form>
    <apex:selectList size="1">
        <apex:selectOptions value="{!options}"/>
        
        
        </apex:selectList>
    
    </apex:form>
</apex:page>

when i execute this program iots getting error message 
Error-
Argument 1 cannot be null 
An unexpected error has occurred. Your development organization has been notified.
Best Answer chosen by Surender reddy Salukuti
Khan AnasKhan Anas (Salesforce Developers) 
Hi Surender,

Greetings to you!

You should make sure you don't have any null elements. The real problem lies in these lines:
for(account a:accounts){
            selectoption op = new selectoption (a.Phone,a.name);
            options.add(op);            
}

If the a.Phone or a.name field is NULL, options is added with NULL.

So change those lines as below:
for(account a:accounts){
            if(a.Phone!=null && a.Name!=null){
                selectoption op = new selectoption (a.Phone,a.name);
                options.add(op);
            }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Surender,

Greetings to you!

You should make sure you don't have any null elements. The real problem lies in these lines:
for(account a:accounts){
            selectoption op = new selectoption (a.Phone,a.name);
            options.add(op);            
}

If the a.Phone or a.name field is NULL, options is added with NULL.

So change those lines as below:
for(account a:accounts){
            if(a.Phone!=null && a.Name!=null){
                selectoption op = new selectoption (a.Phone,a.name);
                options.add(op);
            }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Surender reddy SalukutiSurender reddy Salukuti
Hi Thanks Boss,

its working .