You need to sign in to do that
Don't have an account?
Query / Insert to a Reference Field/Lookup Field.
How do you querry a reference/lookup field and then read what that ID is and based on that ID, populate another reference/lookup field. I know what the values of both Id's are I am just having trouble getting it to insert and read correctly.
This is the code I am having problems with.
Equip2 = [SELECT Name, Modality__c, Modality_Name__c, CT_Models__c, CT_Modality_Picklist__c FROM Equipment__c WHERE Modality__c != NULL ORDER BY Name ASC];
for(Equipment__c Eqp : Equip2) {
if(Eqp.Modality__c = 'a0a30000004XQiKAAW') { // If lookup field modality = this id, then insert below
Eqp.Modality_Name__c = 'a0a30000004XQiKAAW'; //Populate the other lookup field
Eqp.CT_Modality_Picklist__c = 'CT Unknown'; // Specify Picklist Value
Eqp.CT_Models__c = 'Unknown'; // Specify Picklist Value
}
....
.....
....
else {
system.debug('No modalities match');
}
}
insert Equip2;
....
.....
....
I wouldn't really recommending hard-coding a salesforce id - couldn't you match on the name of the Modality or something - something which is more likely to remain consistent across environments.
What's the exact error / problem you're encountering?
The name of the Modality is a lookup field which when you query it you you only recieve the id. Our organization is starting from scratch with a new Modalities section called "CT Modalities", but we want to maintain the connections from the old section called "Modalities". We therefore are migrating all the old section's field information to the new sections fields. We have a full sandbox populated with our organizations data that we are using to create and test the apex code.
You could use the Salesforce default Name field, if the Modality_Name__c is a lookup. Anyways, what's the problem you're facing?
Here is my code. Currently I am recieving "Expression cannot be assigned" on line 0.
I was under the impression that when you querry lookup fields you don't get the name you get the id. Am I incorrect?