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
Sabah FarhanaSabah Farhana 

Error in simple trigger to populate lookup field


Hi all,

Iam getting an error in the line highlighted below.Is this the correct way to write it

trigger updateGroupLookup on Case (before insert) {
for (Case c : Trigger.new) {
   
      if(c.groupid__c!= null){
      
                
         
          c.group_Account__c = [select id from account where Group_ID__c =c.groupid__c];
    }
  }
}
Best Answer chosen by Sabah Farhana
Ramesh KallooriRamesh Kalloori
modify the query as below it will works.

c.group_Account__c = [select id from account where ID=:c.groupid__c].ID;

let me know error if it not works.

All Answers

Ramesh KallooriRamesh Kalloori
modify the query as below it will works.

c.group_Account__c = [select id from account where ID=:c.groupid__c].ID;

let me know error if it not works.
This was selected as the best answer
Sabah FarhanaSabah Farhana
Thanks All,

trigger updateGroupLookup on Case (before insert,before update) {
for (Case c : Trigger.new) {
   
      if(c.groupid__c!= null){
       c.group_Account__c = [select id from account where Group_ID__c=:c.groupid__c].ID;
                
         
         
    }
  }
}

working fine now