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
XIOXIO 

Line -1 Expression cannot be assigned

Hello Developers,

I have the test class below that is receiving this error: "Line -1 Expression cannot be assigned​"

Your assistance is greatly appreciated!
@isTest
public class testClassSuccessPlan
{
    static testMethod void test()
    {      
                  
            //Create success plan record
            test.startTest();
            Success_Plan__c Success_Plan = new Success_Plan__c();
            Success_Plan__c.Name = 'Test Plan';
            Success_Plan__c.Account__c = '0015000000SsYnN';
            Success_Plan__c.Member_Success_Manager__c = '00550000006Rkqu';
            insert Success_Plan;  

            //Create initiative record
            Initiatives__c Initiative = new Initiatives__c();
            Initiatives__c.Name = 'Test Int';
            Initiatives__c.Service_Discipline__c = 'a035000000BdWzV';
            insert Initiative;           
         
          
                
            test.stopTest();
    }
}

 
Lokesh KumarLokesh Kumar
Hi Harmens,
Seems like you are new to Apex Development No issue you are missing incorrect object name in your code.

Please find the updated code below and let me know if this helps yo.
 
@isTest
public class testClassSuccessPlan
{
    static testMethod void test()
    {      
                  
            //Create success plan record
            test.startTest();
            Success_Plan__c Success_Plan = new Success_Plan__c();
            Success_Plan.Name = 'Test Plan';
            Success_Plan.Account__c = '0015000000SsYnN';
            Success_Plan.Member_Success_Manager__c = '00550000006Rkqu';
            insert Success_Plan;  

            //Create initiative record
            Initiatives__c Initiative = new Initiatives__c();
            Initiative.Name = 'Test Int';
            Initiative.Service_Discipline__c = 'a035000000BdWzV';
            insert Initiative;           
         
          
                
            test.stopTest();
    }
}

 Thanks,
Lokesh




 
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Harmens,

You have written these two lines , 

Success_Plan__c.Account__c = '0015000000SsYnN';
Success_Plan__c.Member_Success_Manager__c = '00550000006Rkqu';

Here, test class cannot find these two ids as test class only deals with those reccords which have been created inside the test class asa test data. you have not created neither the account or the succes Manager in sidde the test class.

So, actually there is two option, 
  1. Create an Account like,
    Acccount acc = new Account(Name='test'); // fill other mandatory field also,
    
    Success_Plan__c.Account__c = acc.Id;

    and do the same for success manager. I am seeing Succes Manager is for Users. So, for these first SOQL the proper Profile and create a user like this, 
    Profile p = [SELECT Id FROM Profile WHERE Name='Your Required Profile name']; 
          User u = new User(Alias = 'standt', Email='standarduser@testorg.com', 
          EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
          LocaleSidKey='en_US', ProfileId = p.Id, 
          TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');
    Please do the same thing for Service Disipline also. 
  2. Put isTest(seeAlldata = true) instead of isTest (Not a best practise at all)
Thanks & Regards, 
Prosenjit.
Harshit Garg 6Harshit Garg 6
Hi G,
 
@isTest(SeeAllData=true)
public class testClassSuccessPlan
{
    static testMethod void test()
    {      
                  
            //Create success plan record
            test.startTest();
            Success_Plan__c Success_Plan = new Success_Plan__c();
            Success_Plan__c.Name = 'Test Plan';
            Success_Plan__c.Account__c = '0015000000SsYnN';
            Success_Plan__c.Member_Success_Manager__c = '00550000006Rkqu';
            insert Success_Plan;  

            //Create initiative record
            Initiatives__c Initiative = new Initiatives__c();
            Initiatives__c.Name = 'Test Int';
            Initiatives__c.Service_Discipline__c = 'a035000000BdWzV';
            insert Initiative;           
         
          
                
            test.stopTest();
    }
}
@isTest(SeeAllData=true) from this annotation is used to open up data access when applied at the class or method level. with the isTest(SeeAllData=true) annotation. In this case, the method will still have access to all the data in the organization.

Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.

You are using hard cord ids in your test class.acutely it is not the best practic but @isTest(SeeAllData=true) you can fetch all org data.

Thanks,
Harshit Garg
harshitgarg2591@gmail.com