You need to sign in to do that
Don't have an account?
Devendra 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;
}
{
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;
}
you used colon(:) instead of equal symbol(=)
All Answers
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]
you used colon(:) instead of equal symbol(=)
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;
}
that error has solved but the new error got
expecting a semi-colon, found 'par.Roll_No__c' at line no 9
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.)
one again thanks thanks