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
Devendra Hirulkar 3Devendra Hirulkar 3 

Error: Compile Error: unexpected token: ':'

trigger CopyChildtoParent on class__c (after insert)
{

Child con = [Select Name from class__c where ID=:trigger.id];
Hi all
 a am trying to create a trigger that copy chield obj to parent .  but  i keep getting the following error: compile error :unexpected token: ':' at line no 8
here is my code
// SOQL to get the exact account with matching name as child

 Parent par : [select Id, Roll_No__c from Student__c where Student__c.name in :Trigger.new.Name](here is error)
 par.Roll_No__c = con.Roll_No__c
 update con; 
    
}
Best Answer chosen by Devendra Hirulkar 3
Naveen Rahul 3Naveen Rahul 3
trigger CopyChildtoParent on class__c (after insert)
{

Child con = [Select Name from class__c where ID=:trigger.id];
 
//Parent par : [select Id, Roll_No__c from Student__c where Student__c.name in :Trigger.new.Name](here is error)
 Parent par = [select Id, Roll_No__c from Student__c where Student__c.name in :Trigger.new.Name];
 par.Roll_No__c = con.Roll_No__c;
 update con; 
    
}

you used colon(:) instead of equal symbol(=)

All Answers

NekosanNekosan
You need to create set for Trigger.new.Name and then use that set.
set<String> nameSet = new Set<String>();
for (Account a : Trigger.new) 
nameSet.add(a.Name);

 Parent par : [select Id, Roll_No__c from Student__c where Student__c.name in :nameSet]

 
Naveen Rahul 3Naveen Rahul 3
trigger CopyChildtoParent on class__c (after insert)
{

Child con = [Select Name from class__c where ID=:trigger.id];
 
//Parent par : [select Id, Roll_No__c from Student__c where Student__c.name in :Trigger.new.Name](here is error)
 Parent par = [select Id, Roll_No__c from Student__c where Student__c.name in :Trigger.new.Name];
 par.Roll_No__c = con.Roll_No__c;
 update con; 
    
}

you used colon(:) instead of equal symbol(=)
This was selected as the best answer
Devendra Hirulkar 3Devendra Hirulkar 3
hellow nekosan
sir please tell me what i need to change here my total code



trigger CopyChildtoParent on class__c (after insert)
{

Child con = [Select Name from class__c where ID=:trigger.id];

// SOQL to get the exact account with matching name as child

 Parent par : [select Id, Roll_No__c from Student__c where Student__c.name in :Trigger.new.Name]
 par.Roll_No__c = con.Roll_No__c
 update con; 
    
}
Devendra Hirulkar 3Devendra Hirulkar 3
thanks  Naveen Rahul 3
that error has solved but the new error got 
expecting a semi-colon, found 'par.Roll_No__c' at line no 9
NekosanNekosan
par.Roll_No__c = con.Roll_No__c 
this line is missing semi-colon.
The solution which I mentioned is for bulkification. Let me know if you need to bulkify trigger. (It is always recommended to bulkify trigger.)
Devendra Hirulkar 3Devendra Hirulkar 3
thanks both i has soved the problem 
one again thanks thanks