You need to sign in to do that
Don't have an account?
DiegoT.
Update field in a relationship(lookup) with trigger
i have two objects Account(Standard object)---House(Custom Object) update the price of all Houses of the same type, with The following logic: when the price of a house is changed, the price all the others Houses of the same type must change the proportional percentage increased over the updated record.
field Account: Account_Type__c, Account_Price__c
field House: House_Type__c, House_Price__cMy trigger is very wrong,What is the right way to do it?
trigger PricePercentual on Account (after insert) { . for (Account a : [SELECT Acconut_Type__c FROM Account WHERE (SELECT House.Type FROM House__c) AND Account.Type = House.Type) //here query update price house same type ); } }
In after update trigger, search for other House records of same type in as below:
List<String> types = new List<String>();
List<house__c> housesToUpdate = new List<house__c>();
for(house__c houseobj : trigger.new){
types.add(houseobj.type__c);
}
for(house__c houseobj : [SELECT Id, price__c FROM house__c WHERE Type__c IN :types]{
//add your logic of proportional percentage increased over the updated record
housesToUpdate .add(houseobj);
}
if(!housesToUpdate.isEmpty()) update housesToUpdate;
Please let me know what is the Propotional percentage increased over the updated record is according to your business requirements?
example
price 200
Increase_price =30
total = 100%
(increase_price x price) / total = (30x200) / 100
new = Returns a list of the new versions of the sObject records.
I think I should use old and new, since the price variable is only one
The new value is 230 or 30?
for example the price = 200$
i wanna update 30$ more to 200$
if 200$----- 100%
30$------- x %
(30$ x 100) / 200 = 15%
200$--- 100%
30$----- 15% = 100% + 15% = 200$ + 30$ = the new value is 230$
Please try this: