0

I have been trying to successfully compile a Test Class for triggers that auto-insert a DML_Log__c upon a specific sObject type being deleted, and an error keeps getting thrown:

Expression cannot be assigned at line -1 column -1

Here's the unit test code:

//Test class for testing DML Logging
@isTest 
public class testDmlLogger {
static testMethod void testDmlLogging() {

Account testAccount = new Account();
testAccount.Name = 'TrylerTest';
insert testAccount;


Opportunity newTestOpp = new Opportunity();

//setting all Required fields
newTestOpp.Name = 'Master Program Test Opp';
newTestOpp.Sales_Owner_Field_Updater__c = 'Tryhard McTrevor';
newTestOpp.AccountId = testAccount.ID;
newTestOpp.Primary_Media_Opportunity__c = 'Incremental Budget';
newTestOpp.CloseDate = date.parse('10/12/2015');
newTestOpp.StageName = 'Prospecting';
newTestOpp.Type = 'New Business';
//insert the Opportunity sObject
insert newTestOpp;

//Creating new Program record
Program__c testProgram = new Program__c();
Program__c.Name = 'Radagast Records';
//insert Program- default record type is Provisioned, only one field required
insert testProgram;

//Create new Media Placement, a child/Detail object of Program and Opportunity
Media_Placement__c testMedPlc = new Media_Placement__c();
Media_Placement__c.Opportunity_Associated__c = newTestOpp.Id;
Media_Placement__c.Program_Placement__c = testProgram.Id;
//and insert!
insert testMedPlc;

//grabbing testMedPlc Id and Name as a string
String testMedPlcId = testMedPlc.Id;
String testMedPlcName = testMedPlc.Name;
System.debug(testMedPlcName);


//...and now we delete the Media Placement
delete testMedPlc;

//This should insert a DML_Log__c storing the sObject 'Name' and sObject Id values

//Time to SOQL Query! DML Logs
DML_Log__c queriedDmlLog = [SELECT Id,Name,SObject_Type__c FROM DML_Log__c WHERE SObject_Id__c = :testMedPlcId LIMIT 1];
System.assertEquals('Media_Placement__c', queriedDmlLog.SObject_Type__c);

//grab the Program record's Name
String testVerProgName = testProgram.Name;

//Time to delete Program record!
delete testProgram; 

//Time to SOQL! New DML Log
DML_Log__c queriedDmlProgLog = [SELECT Id,Name,SObject_Type__c FROM DML_Log__c WHERE Name__c = :testProgName LIMIT 1];
//sObject type was Program__c, so should be written to field as string
System.assertEquals('Program__c', queriedDmlProgLog.SObject_Type__c);

    }
}

Notes:

Media_Placement__c object is a detail of Opportunity and Program__c objects

The Media_Placement__c sObject name is an 'Auto-Number' data type, but when the DML_Log__c sObject is inserted in Sandbox upon either a Program__c or Media_Placement__c deletion, this Auto-Number is successfully written to a string field

Is assigning the Auto-Number data type to a string variable causing the compile error?

P.S. When I tried executing in Dev Console, executing returned this Dialog error:

Only top-level class methods can be declared static

I have successfully tested in the past, so I am not sure what is causing these issues (I am using v 36.0)

2

Looks like simple syntax error to me in below lines

/Creating new Veritone Program record
  Program__c testProgram = new Program__c();
 Program__c.Name = 'Radagast Records';///// WRONG WRONG
//insert Program- default record type is Provisioned, only one field required
insert testProgram;

You have to use Sobject variable for assignment and not sObject directly

/Creating new Veritone Program record
Program__c testProgram = new Program__c();
 testProgram .Name = 'Radagast Records';//Check this here ..
//insert Program- default record type is Provisioned, only one field required
 insert testProgram;

Correct the assignment syntax everywhere and you should be good .

  • Doh, rookie mistake! Good eye, I did fix that and tried compiling again, but it's still throwing a 'Expression cannot be assigned at line -1 column -1'. Any idea what that could refer to? – GPP Apr 28 '16 at 5:10
  • 1
    Also realized that my Media_Placement__c sObject was incorrectly assigned...thanks again! – GPP Apr 28 '16 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.