+ Start a Discussion
Vijay@sfdcVijay@sfdc 

Empty debug statement

Hello All,


Public Class AccountCreation
{
Public List<Account> CreateAccount(String s, String p){
List<Account> a = new List<Account>();
for(Account acc:a)
{
acc.Name=s;
acc.phone=p;
insert all;
}
return a;
}

In the above programm , can crete account , but i am not getting rerun values after i executed bellow code in developer console
AccountCreation ac= new AccountCreation();
ac.CreateAccount('sss','1234');
System.debug("debug"+ ac);
in this debug statement not displaying any created records.
would any one please explain bit more what might be the reason .
 
Best Answer chosen by Vijay@sfdc
veda Hebbarveda Hebbar
Hi Vijay,

1. Why you are using for loop to insert account. As there is no value in 'a'(list your initializing just before for loop a.size() will be zero). 
2. if you want to display return value in debug, first you have to store it. 

Please see below code of Apex class:
Public Class AccountCreation
{
	Public Account CreateAccount(String s, String p)
	{
		Account acc = new Account();
		acc.Name=s;
		acc.phone=p;
		insert acc;
		return acc;
	}
}


Developer Console :
AccountCreation ac= new AccountCreation();
Account objAccoutInterted = ac.CreateAccount('sss','1234');
System.debug('debug'+ objAccoutInterted);

Please check.

Thanks,
Vedashri

All Answers

veda Hebbarveda Hebbar
Hi Vijay,

1. Why you are using for loop to insert account. As there is no value in 'a'(list your initializing just before for loop a.size() will be zero). 
2. if you want to display return value in debug, first you have to store it. 

Please see below code of Apex class:
Public Class AccountCreation
{
	Public Account CreateAccount(String s, String p)
	{
		Account acc = new Account();
		acc.Name=s;
		acc.phone=p;
		insert acc;
		return acc;
	}
}


Developer Console :
AccountCreation ac= new AccountCreation();
Account objAccoutInterted = ac.CreateAccount('sss','1234');
System.debug('debug'+ objAccoutInterted);

Please check.

Thanks,
Vedashri
This was selected as the best answer
Abhishek BansalAbhishek Bansal
Hi Vijay,

You are initializing the list "a" just above the for loop so this list will never contain any records in it and hence the code written inside the for loop will never execute because the "a" list is empty.
I have updated your code. Please try with below code :
Public Class AccountCreation {
	public Account CreateAccount(String s, String p){
		Account acc = new Account;
		acc.Name = s;
		acc.phone = p;
		insert acc;
		return acc;
	}
}

//Script to be used in Developer console
AccountCreation ac= new AccountCreation();
Account newAccount = ac.CreateAccount('sss','1234');
System.debug("debug"+ newAccount);


Please let me know if you need more information or help on this.

Thanks,
Abhishek Bansal

Vijay@sfdcVijay@sfdc
Thanks for Quick reply:)