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
Siva Krishna KondapalliSiva Krishna Kondapalli 

accountcontroller issue, i couldn't find where the problem is i have written the code well

User-added imageUser-added image
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Siva,

Can you share the code as content not as screenshot as it would be diffiuclt to check the code if shared as screenshot.

Please add the code as comment and also if possible can you add the exact requirement and vfpage for the same.

Thanks,
 
Siva Krishna KondapalliSiva Krishna Kondapalli
Okay Praveen 
public class AccountController {

    Public String AccName{set;get;}
    Public String AccNumber{set;get;}
    Public String AccRating{set;get;}
    Public String AccPhone{set;get;}
    
    Public PageReference SaveAccount(){
        Account Acc = New Account();
        Acc.Name = AccName;
        Acc.phone = AccPhone;
        Acc.Rating = AccRating;
        Acc.AccountNumber = AccNumber;
       PageReference pageRef;
        If(Acc.Name == null || Acc.Name ==''){ 
        ApexPages.Message myMsg =New ApexPages.Message(ApexPages.Severity.ERROR, 'Account Name is Mandatory');
        ApexPages.addMessage(myMsg);
       
            
            }else{
                insert acc; 
        pageRef = new PageReference('/'+acc.Id);
        pageRef.setRedirect(True);
                 
        }
       
          return pageRef;    
        
      
  }
 }
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Shiva,

I tried to save the above mentioned class and did not face any errors while saving it.

I hope Earlier you did not define Account acc in the method I guess which caused the issue.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,