You need to sign in to do that
Don't have an account?

when i am trying to execute this trigger ............ System.SObjectException: DML statment cannot operate on trigger.new or trigger.old
trigger custom1 on student__c (before insert)
{
list <student__c>st1= new list <student__c>();
for(student__c st:trigger.new)
{
if(st.sport__r.name=='rugby')
{
st.stdno__c=12345;
}
insert st;
}
}
{
list <student__c>st1= new list <student__c>();
for(student__c st:trigger.new)
{
if(st.sport__r.name=='rugby')
{
st.stdno__c=12345;
}
insert st;
}
}
is not getting true. Use debugs and check what you are getting in "st.sport__r.name". It should exactly matches 'rugby' and this check is case sensitive.
All Answers
What is error you are geeting
in this??
Thanks.
Check if there is any validation rule,
Else deactivate this trigger and check.
Thanks
is not getting true. Use debugs and check what you are getting in "st.sport__r.name". It should exactly matches 'rugby' and this check is case sensitive.
The problem is since we are using relationship field in the condition, which always null when we use the trigger.New in the before trigger, eventhough your are have proper value in the object. Hope below will resolve your issue