You need to sign in to do that
Don't have an account?
snehal waghmare 3
hi exports i need help to write a trigger facing issue
on Lead creation and updation if lead status is qualified or unqualified want current date . i have written below trigger but its not working
trigger LeadTrigger on Lead (before insert,Before update) {
if(trigger.isBefore && trigger.isUpdate){
LeadTriggerHandler.befUpdt(trigger.new , trigger.oldMap);
}
}
------------------------------------------------------------------------------------
public class LeadTriggerHandler {
public static void befUpdt(List<Lead> newLd, map<Id,Lead> oldMapLd){
for(Lead ld : newLd){
if (oldMapLd != Null && ld.status != oldMapLd.get(ld.Id).status ){
if(ld.status == 'qualified' && ld.status ==' unqualified'){
ld.CreatedDate = system.now() ;
}
}
}
}
}
thank you,
snehal
trigger LeadTrigger on Lead (before insert,Before update) {
if(trigger.isBefore && trigger.isUpdate){
LeadTriggerHandler.befUpdt(trigger.new , trigger.oldMap);
}
}
------------------------------------------------------------------------------------
public class LeadTriggerHandler {
public static void befUpdt(List<Lead> newLd, map<Id,Lead> oldMapLd){
for(Lead ld : newLd){
if (oldMapLd != Null && ld.status != oldMapLd.get(ld.Id).status ){
if(ld.status == 'qualified' && ld.status ==' unqualified'){
ld.CreatedDate = system.now() ;
}
}
}
}
}
thank you,
snehal
Yes CreatedDate is a audit field and you cannot update it directly or with code but you can raise a case wuth salesforce support for getting the permission to edit these fields.
Please find the below article (https://blog.webnersolutions.com/salesforce-how-to-edit-salesforce-created-date-and-last-modified-date-field-values/) for the same.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
I guess your requirment is to tag the DateTime informtion on the lead when it was moved to status qualified or unqualified. I am not why you want ot manipulate the CreatedDate field which is already mentioned to you is controlled by Salesforce and you cannot make any updates there.
Please confirm.