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
MILKMILK 

Apex trigger

I have two object : Account_Entitlement_Used__c and Account_Entitlement__c repectively.

master object is Account.

 

field:Acctt.Related_Entitlement_Used__c (object Account_Entitlement__c)

 

If insert a record OF OBJECT Related_Entitlement_Used__c in Account (i.e, Peter), then  the trigger need to find the eariler Account Entitlement record (object Account_Entitlement__c) in Account Peter,then put the id of record(Related_Entitlement_Used__c )into  field of Related_Entitlement_Used__c (object Account_Entitlement__c) in Account Peter.If delete the record of  object  Account_Entitlement_Used__c in Account Peter ,then the Related_Entitlement_Used__c of object (object Account_Entitlement__c) =null

 

 

below is my trigger: the deletion part  seems is done but i dun know how to wrtie afterinsert.............

 

 

 

AccountEntitlementUsedTrigger on Account_Entitlement_Used__c (afterdelete, afterinsert) {

 

if(Trigger.isDelete){

List<id> LAcctID =

newList<id>();

 

for(Account_Entitlement_Used__cAE : Trigger.old){

LAcctID.add(AE.Customer_Name__c);

}

 

List<Account_Entitlement__c> LAcctUpdd = new List<Account_Entitlement__c>();

 

for(Account_Entitlement__c Acctt : [Selectid

 

fromAccount_Entitlement__cwhere id IN:LAcctID]){

Acctt.Related_Entitlement_Used__c=

'';

LAcctUpdd.add(Acctt);

}

if(LAcctUpdd != null&& LAcctUpdd.size()>0)

 

updateLAcctUpdd;

 

}

else

if(Trigger.inSert){

.....

....................

}