You need to sign in to do that
Don't have an account?
kavya mareedu
I would recommend you guys to help with triggers concept.
My question is: When ever lead is inserted, with leadsource as web set wilson as owner of record. If the leadsource is other than web then assign it to lifeQueue as owner.
Ans:
public class Lead_Example {
User u= [Select id from User where FirstName LIKE 'wilson'];
group g= [Select id from Group where type='Queue' and name='LifeQueue'];
public static void callMe(List<Lead> leads)
{
for(Lead l: leads)
{
if(l.LeadSource=='web')
{
l.OwnerId= u.id;
}else{
l.OwnerId=g.id;
}
}
}
}
Trigger Callout:
trigger Lead_Example on Lead (before insert) {
List<Lead> leads=Trigger.new;
Lead_Example.callMe(Trigger.new);
}
Ans:
public class Lead_Example {
User u= [Select id from User where FirstName LIKE 'wilson'];
group g= [Select id from Group where type='Queue' and name='LifeQueue'];
public static void callMe(List<Lead> leads)
{
for(Lead l: leads)
{
if(l.LeadSource=='web')
{
l.OwnerId= u.id;
}else{
l.OwnerId=g.id;
}
}
}
}
Trigger Callout:
trigger Lead_Example on Lead (before insert) {
List<Lead> leads=Trigger.new;
Lead_Example.callMe(Trigger.new);
}
Kindly add soql for User & Group inside callMe method in order to resolve this issue as below.
Mark this answer as best answer if it helps you.
Regards,
Sagar
Apex trigger LeadOwnerSetup caused an unexpected exception, contact your administrator: LeadOwnerSetup: execution of AfterInsert caused by: System.FinalException: Record is read-only: Trigger.LeadOwnerSetup: line 19, column 1 ----- THIS IS THE ERROR MESSAGE
Post your LeadOwnerSetup trigger code here.
Or try to change the event from After Insert to Before Insert.
In the After Insert the Trigger.New values will be in Read only. You can't edit the value if you want edit the value then fetch the record from database in after insert then modify those records.
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Maharajan.C