function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SriramR14SriramR14 

can any one help me in this after update trigger?

Hi all,
User-added image

its problem is, in after update, the fields of description__c, field__C nor updating.,

rest of first name, last name, required fields of updating.,

why?

anyone can help me.,

Thanks, 
Sriram.R
Santosh Kumar 348Santosh Kumar 348
Can you plese post your code in code sample option given.
SriramR14SriramR14
Hi Santhosh,
its problem is, in after update, the fields of description__c, field__C nor updating.,

rest of first name, last name, required fields of updating.,

why?

 
 
trigger custdetailedtrigger on Customer_Detailed_status__c (before insert, after insert, before update, after update, before delete, after delete) 
{

//before insert

if(trigger.isbefore && trigger.isinsert)
{
for(Customer_Detailed_status__c cds : trigger.new)
{
cds.First_Name__c ='Michael';
cds.Last_Name__c = 'Fernandaes';
}
}


// after insert
if(trigger.isafter && trigger.isinsert)
{
set<id> setaccountid = new set<id>();

list<Customer_Detailed_status__c> cdslist = new list<Customer_Detailed_status__c>();

for(Customer_Detailed_status__c cds1 : Trigger.new)
{
setaccountid.add(cds1.id);
}

list<Customer_Detailed_status__c> cdst = [select id, description__c, field__c from Customer_Detailed_status__c where ID IN: setaccountid];

for(Customer_Detailed_status__c cds2: cdst)
{
cds2.description__c='Who is this?';
cds2.field__c='i am a man';
cdslist.add(cds2);
update cdslist;
}
if(cdslist.size()>0)
{
update cdslist;
}
}

 
// before update
if(trigger.isbefore && trigger.isupdate)
{
for(Customer_Detailed_status__c cdsup: Trigger.new)
{
cdsup.description__c='This is Me';
cdsup.field__c='i am a bad man';
}
} 

// after update
if(Trigger.isAfter && Trigger.isupdate)
    {

if(stoprecursivedetails.stopcustomerdetailsupdate)
    {
stoprecursivedetails.stopcustomerdetailsupdate=false;

set<id> setaccountid = new set<id>();

list<Customer_Detailed_status__c> cdslist = new list<Customer_Detailed_status__c>();

for(Customer_Detailed_status__c cds1 : Trigger.new)
{
setaccountid.add(cds1.id);
}

list<Customer_Detailed_status__c> cdst = [select id,description__c, field__c, Required__c from Customer_Detailed_status__c where ID IN: setaccountid];

for(Customer_Detailed_status__c cds2: cdst)
{
//cds2.Required__c='He is worst man';
cds2.description__c='His name is N.Ram';
cds2.field__c='i am a bad worst man';

cds2.First_Name__c ='Michaeline';
cds2.Last_Name__c ='Disousa';
cdslist.add(cds2);
}

if(cdslist.size()>0)
{
update cdslist;
}
}
}

Thanks, 
Sriram.R
Santosh Kumar 348Santosh Kumar 348
Hi Sriram,
First of all if you need to update the same object then the best way is to perform the operation in before trigger. 
Place the same code in before update trigger  it will work. As well as it will save your SOQL and trigger won't run into recussrion..

Coming back to your original code:
Basic excution flow of trigger is when a record is inserted, updated or deleted the trigger will fire.
In your code you have wriiten a statement to initialise the description__c and field__c  in both before as well as after update, so whatever changes you are making in after update is getting overwritten when trigger is getting fired by before update code.
Your First_Name__c and Last_Name__c is not used in before trigger so the values are not getting overwritten and it is holding the value you have provided in after trigger.

If you find the above solution helpful. Please mark as Best Answer to help others too.

Thanks and Regards,
 Santosh Kumar