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
himanshu huske 7himanshu huske 7 

basic triggers

Whenever a new transaction is performed successfully then update the customer object balance field based on 
     If Transaction Type=Deposit, Balance= balance +amount ;  withdraw balance= balance-amount;
     Note: Customers and Transaction has lookup Detail Relation.
abhishek singh 497abhishek singh 497
Hi Himashu,
Before helping you out.Please correct me if I am wrong,
the customer object field which you are referring to update are balance and withdraw balance correct?

Thank You,
Abhishek Singh.
himanshu huske 7himanshu huske 7
yes... 
Customer is a parent object with Balance field.
Transaction_type is child object with fields customer(lookup), Diposit, Withdrawal.
with every deposit or withdrawal, balance field in customer object gets updated.
 
abhishek singh 497abhishek singh 497
ohk got it ,Give me sometime I will get back to you.
NehaDabas16NehaDabas16
Hi Himanshu,

This can be achieved using Process Builder, there is no need to write trigger. Follow below mentioned steps to create one:
  1. Go to process builder under Workflows and Approvals. Create a new process and select start criteria as "When a record Changes".
  2. Click on Add Object and select Transaction__c. Also select the option "only when a record is created". Click save.
  3. Click on Add Criteria and select "No criteria—just execute the actions!", give it a name and click Save.
  4. Click on Add Action next to the condition. Action Type = " update records". In select a recod to update, select "Select a record related to the Transation". Then select "Customer".
  5. Select "Amount" field and then select type = "Formula". Paste this formula in the editor :
    IF([Transaction__c].Transaction_Type__c ="Deposit" ,  [Transaction__c].Customer.Balance__c+[Transaction__c].Customer.Amount__c , [Transaction__c].Customer.Balance__c-[Transaction__c].Customer.Amount__c)

    Click save.
  6. Activate the process.
Please use the field names, Object names and relationship names which apply to your org. These are just assumptions.