You need to sign in to do that
Don't have an account?
DannyTK
Expression cannot be assigned at line -1 column -1 error on Test Class
Good morning everyone,
I have a trigger that will assign a lookup value from a custom object (data_center_location__c) to an Opportunity based on a picklist field (location__c) on the Opportunity. The trigger works okay, but i'm having trouble with my test class. I'm receiving the Expression error when trying to save. I also have to state that i'm not a developer so I don't have a great understanding of basic concepts when it comes to test classes:
Trigger is:
trigger UpdateDataCenterLocation on Opportunity (before insert, before update){
Set<String> locationSet = new Set<String>();
Map<String,Id> mapLocationSetwithDataCntr = new Map<String,Id>();
for (Opportunity obj: trigger.new){
if(!String.isBlank(obj.Location__c)){
locationSet.add(obj.Location__c);
}
}
if(!locationSet.isEmpty()){
for(Data_Center_Location__c dataCenter : [SELECT Id,Opportunity_Location_Code__c FROM Data_Center_Location__c WHERE Opportunity_Location_Code__c IN :locationSet]){
mapLocationSetwithDataCntr.put(dataCenter.Opportunity_Location_Code__c,dataCenter.Id);//Expecting there will be one record for each location, otherwise this map will have last Data_Center_Location__c Id
}
}
for (Opportunity obj: trigger.new){
if(!String.isBlank(obj.Location__c) && mapLocationSetwithDataCntr != null && mapLocationSetwithDataCntr.get(obj.Location__c) != null){
obj.Data_Center_Location__c = mapLocationSetwithDataCntr.get(obj.Location__c);
}
else{
obj.Data_Center_Location__c = null;
}
}
}
________
Again, the trigger works as should, the test class on the other hand doesn't:
@isTest
Private class UpdateDataCenterLocationTestClass {
static testMethod void UpdateDataCenterLocation () {
List <Opportunity> OpportunityLst = new List <Opportunity>();
Opportunity Opp = new Opportunity ();
Opportunity.Name = 'test Opportunity';
Opportunity.Location__c = 'TX-DAL-03LEW' ;
Opportunity.Stagename = 'Stage 1: Qualified Prospect';
Opportunity.Closedate = '2015, 2, 26';
OpportunityLst.add(opp);
insert Opp;
}
}
--------------------------
For the test class, i'm just trying to create an Opportunity with the location__c field populated with a value, seems easy enough. Any guidance would be much appreciated.
Thanks everyone
-d
I have a trigger that will assign a lookup value from a custom object (data_center_location__c) to an Opportunity based on a picklist field (location__c) on the Opportunity. The trigger works okay, but i'm having trouble with my test class. I'm receiving the Expression error when trying to save. I also have to state that i'm not a developer so I don't have a great understanding of basic concepts when it comes to test classes:
Trigger is:
trigger UpdateDataCenterLocation on Opportunity (before insert, before update){
Set<String> locationSet = new Set<String>();
Map<String,Id> mapLocationSetwithDataCntr = new Map<String,Id>();
for (Opportunity obj: trigger.new){
if(!String.isBlank(obj.Location__c)){
locationSet.add(obj.Location__c);
}
}
if(!locationSet.isEmpty()){
for(Data_Center_Location__c dataCenter : [SELECT Id,Opportunity_Location_Code__c FROM Data_Center_Location__c WHERE Opportunity_Location_Code__c IN :locationSet]){
mapLocationSetwithDataCntr.put(dataCenter.Opportunity_Location_Code__c,dataCenter.Id);//Expecting there will be one record for each location, otherwise this map will have last Data_Center_Location__c Id
}
}
for (Opportunity obj: trigger.new){
if(!String.isBlank(obj.Location__c) && mapLocationSetwithDataCntr != null && mapLocationSetwithDataCntr.get(obj.Location__c) != null){
obj.Data_Center_Location__c = mapLocationSetwithDataCntr.get(obj.Location__c);
}
else{
obj.Data_Center_Location__c = null;
}
}
}
________
Again, the trigger works as should, the test class on the other hand doesn't:
@isTest
Private class UpdateDataCenterLocationTestClass {
static testMethod void UpdateDataCenterLocation () {
List <Opportunity> OpportunityLst = new List <Opportunity>();
Opportunity Opp = new Opportunity ();
Opportunity.Name = 'test Opportunity';
Opportunity.Location__c = 'TX-DAL-03LEW' ;
Opportunity.Stagename = 'Stage 1: Qualified Prospect';
Opportunity.Closedate = '2015, 2, 26';
OpportunityLst.add(opp);
insert Opp;
}
}
--------------------------
For the test class, i'm just trying to create an Opportunity with the location__c field populated with a value, seems easy enough. Any guidance would be much appreciated.
Thanks everyone
-d
@isTest
Private class UpdateDataCenterLocationTestClass {
static testMethod void UpdateDataCenterLocation () {
List <Opportunity> OpportunityLst = new List <Opportunity>();
Opportunity Opp = new Opportunity ();
Opp.Name = 'test Opportunity';
Opp.Location__c = 'TX-DAL-03LEW' ;
Opp.Stagename = 'Stage 1: Qualified Prospect';
Opp.Closedate = '2015, 2, 26';
OpportunityLst.add(opp);
insert OpportunityList;
}
}
All Answers
@isTest
Private class UpdateDataCenterLocationTestClass {
static testMethod void UpdateDataCenterLocation () {
List <Opportunity> OpportunityLst = new List <Opportunity>();
Opportunity Opp = new Opportunity ();
Opp.Name = 'test Opportunity';
Opp.Location__c = 'TX-DAL-03LEW' ;
Opp.Stagename = 'Stage 1: Qualified Prospect';
Opp.Closedate = '2015, 2, 26';
OpportunityLst.add(opp);
insert OpportunityList;
}
}
-d