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
kallam salesforce1kallam salesforce1 

Can some one please explain why there is error in this program?

User-added image
Best Answer chosen by kallam salesforce1
Shubham Raj 29Shubham Raj 29

Hi @kallam salesforce1,

You are using recordResults variable which is of non-static type inside the static method -CreateAcc.

So, you have to just add the static keyword in the declaration of recordResults variable.

i.e--->  public static string recordResults {get;set;}

 

Let me know if this was helpful. If it does, please mark it as Best Answer to help others too.

Thanks,
Shubham Raj

All Answers

Shubham Raj 29Shubham Raj 29

Hi @kallam salesforce1,

You are using recordResults variable which is of non-static type inside the static method -CreateAcc.

So, you have to just add the static keyword in the declaration of recordResults variable.

i.e--->  public static string recordResults {get;set;}

 

Let me know if this was helpful. If it does, please mark it as Best Answer to help others too.

Thanks,
Shubham Raj

This was selected as the best answer
Naveen KNNaveen KN
Declare static for the recordReslts variable.
Suraj Tripathi 47Suraj Tripathi 47
Hi @Kallam salesforce1,
public class CreateNewAccountRecordHandler {
    public static string recordResults{get; set;}
    
    public static void CreateAcc(){
        Account acc =  new Account();
        acc.Name = 'ABC';
        acc.Industry = 'Banking';
        acc.Phone = '1234';
        
        insert acc;
        
        if(acc.Id != null){
            CreateNewAccountRecordHandler.recordResults = 'Inserted Successfully  '+acc.Id;
        }
        else{
            CreateNewAccountRecordHandler.recordResults = 'Not inserted  ';
        }
    }
}
Thanks!!

If you found this helpful,
Please mark it as the best answer.

Regards
Suraj Tripathi
Shubham Raj 29Shubham Raj 29

Hi @Kallam salesforce1,

Hope your issue has been resolved and please mark it as Best Answer and close the Ticket.

Thanks
Shubham Raj