You need to sign in to do that
Don't have an account?

Trigger on contract not working
trigger TriggerOnContract on Contract (after insert, after update, after delete, after undelete) {
switch on Trigger.operationType{
when AFTER_INSERT{
//creating a new set of account Ids from contract whose status is active
set<Id> accountIds = new set<Id>();
for(Contract contract:Trigger.new ){
if(contract.Status == 'Activated'){
accountIds.add(contract.AccountId);
}
}
//creating a list of contract of the selected account Ids of the set
List<Contract> contracts=[SELECT Id, AccountId, Status, Productc, Property_Rentc FROM Contract
WHERE Status='Activated' AND AccountId IN:accountIds];
//build final list of account to update
List<Account> accountsToUpdate = new List<Account>();
for(Contract contract:contracts){
Account acct= new Account(Id = contract.AccountId,
Property_Namec = contract.Productc,
Rent_Amountc = contract.Property_Rentc);
accountsToUpdate.add(acct);
}
//update the final list of account
update accountsToUpdate;
this is the trigger, i would like to update Property and rent field on Account form the active contract. account and contract are standard object . property and rent field on both the objects are custom field. this is not working, how can i fix it. need help...Thanks!
switch on Trigger.operationType{
when AFTER_INSERT{
//creating a new set of account Ids from contract whose status is active
set<Id> accountIds = new set<Id>();
for(Contract contract:Trigger.new ){
if(contract.Status == 'Activated'){
accountIds.add(contract.AccountId);
}
}
//creating a list of contract of the selected account Ids of the set
List<Contract> contracts=[SELECT Id, AccountId, Status, Productc, Property_Rentc FROM Contract
WHERE Status='Activated' AND AccountId IN:accountIds];
//build final list of account to update
List<Account> accountsToUpdate = new List<Account>();
for(Contract contract:contracts){
Account acct= new Account(Id = contract.AccountId,
Property_Namec = contract.Productc,
Rent_Amountc = contract.Property_Rentc);
accountsToUpdate.add(acct);
}
//update the final list of account
update accountsToUpdate;
this is the trigger, i would like to update Property and rent field on Account form the active contract. account and contract are standard object . property and rent field on both the objects are custom field. this is not working, how can i fix it. need help...Thanks!
Please try with below code.
If this helps, Please mark it as best answer.
Regards,
Ankaiah Bandi
All Answers
Please try with below code.
If this helps, Please mark it as best answer.
Regards,
Ankaiah Bandi