You need to sign in to do that
Don't have an account?
nikkey
Trigger syntax
Hi Folks ,
can any one help me
What is the difference in this syntax below :
list<Student__c> newstud = trigger.new;
for(Student__c st: trigger.new)
if(trigger.new[].fee__c>500)
Thanks in Advance
Hi,
1. list<Student__c> newstud = trigger.new;
This will create a List which is collection in Salesforce of Students Custom Object Records , All of which are coming through new versions.
2. for(Student__c st: trigger.new)
This iterates over the Student sObject and takes those inside the loop which are coming as a new version. This is only declaration , Now you can enter logic after this in braces {}. You are not allowed give DML statements inside the loop.
This is creating a looping variable over which you can iterate. It can be taken equivalent to the 1. The differnce is you cannot check any more conditions when you are inserting values in newstud there.
3. if(trigger.new[].fee__c>500)
This check the value of the Fee Field in the records which come through trigger.new.
Check Trigger.new Docs
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You
All Answers
Hi,
1. list<Student__c> newstud = trigger.new;
This will create a List which is collection in Salesforce of Students Custom Object Records , All of which are coming through new versions.
2. for(Student__c st: trigger.new)
This iterates over the Student sObject and takes those inside the loop which are coming as a new version. This is only declaration , Now you can enter logic after this in braces {}. You are not allowed give DML statements inside the loop.
This is creating a looping variable over which you can iterate. It can be taken equivalent to the 1. The differnce is you cannot check any more conditions when you are inserting values in newstud there.
3. if(trigger.new[].fee__c>500)
This check the value of the Fee Field in the records which come through trigger.new.
Check Trigger.new Docs
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You
I think this:
if(trigger.new[].fee__c>500)
should give you compile error.
trigger.new is a list. so you should write which element in the list you approaching.
e.g.:
if(trigger.new[1].fee__c>500)