You need to sign in to do that
Don't have an account?
Trigger Help - After Insert and After Update
Hello, I've written the following trigger to create a Payment__c record when a Deal_Participation__c record is created where RecordType = 'Seller Participation.' The trigger is behaving correctly for after insert BUT when an existing Deal_Participation__c record is updated, it creates another new Payment__c record instead of updating the Payment__c record. I think I need to rewrite the payments.add(new.Payments__c)... bit but I'm not sure how to do it. Any help is greatly appreciated!
trigger createSellerPayments on Deal_Participation__c (after Insert, after Update) {
List<Payments__c> payments = new List<Payments__c>();
ID rtId = [SELECT Id FROM RecordType WHERE Name = 'Seller Participation'].Id;
List<RecordType> PmntRecordType = [Select Id from recordType where Name = 'Outgoing Seller Payment' AND SobjectType= 'Payments__c'];
for (Deal_Participation__c newPayment: Trigger.New) {
if (newPayment.Deal_Relationship__c != null) {
if(newpayment.RecordTypeId == rtId){
payments.add(new Payments__c(
RecordTypeId = PmntRecordType[0].id,
Deal_Participation_Relationship__c = newPayment.Id));
}
}
}
insert payments;
}
Hi,
Could you please try below:-
You can fix if any syntax error.
Let me know if you still have any problem.