• DiegoT.
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 14
    Replies
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__c
My 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

        );
    }

}

 
Hi everyone, i am new with Apex and i have a question.
I want to update the Contact object field location_boat__c and that the location__c fields of the Boat object be updated also be updated My test is incompleted. i want test my trigger UpdateLocationand i dont know how do it
the object Boat field name Contac__c have relationship lookup with the Contact (Object standard)
My test is wrong but i can not how resolve this problem
trigger UpdateLocation on Contact (after update) { if (trigger.isAfter
&& Trigger.isUpdate) {
     List<Boat__c> boats = new List<Boat__c>();
     for (Contact c : [
                 SELECT location_boat__c, (SELECT Id FROM Boats__r)
                 FROM Contact
                 WHERE Id = :trigger.new
             ]) {
         for (Boat__c b : c.Boats__r) {
             b.location__c = c.location_boat__c;
             boats.add(b);
         }
     }
     update(boats); }}
 
@isTest
public class PruebaBotes {
@isTest static void TestActualizar() {

            Boat__c b1  = new Boat__c(Name='bote uno' ,Price__c=20, Type__c='Velero', location__c='Argentina');
            Boat__c b2  = new Boat__c(Name='bote dos' ,Price__c=50, Type__c='Yate', location__c='Brasil');
            Boat__c b3  = new Boat__c(Name='bote tres' ,Price__c=125, Type__c='Catamaran', location__c='España');
            Boat__c b4  = new Boat__c(Name='bote cuatro' ,Price__c=700, Type__c='Velero', location__c='India');

            insert b1;
            insert b2;
            insert b3;
            insert b4;   

            Contact a1 = new Contact(Lastname='Pepe',  location_boat__c = 'Brasil');
            Contact a2 = new Contact(Lastname='Jose',  location_boat__c = 'Argentina');
            Contact a3 = new Contact(Lastname='Maria', location_boat__c = 'India');
            Contact a4 = new Contact(Lastname='Ana',   location_boat__c = 'Argentina');

            insert a1;
            insert a2;
            insert a3;
            insert a4;    

            Contact updateLocation;
            updateLocation = [SELECT location_boat__c FROM Contact WHERE location_boat__c = 'Argentina' LIMIT 1];
            updateLocation.location_boat__c = 'India';
            update updateLocation;

Test.startTest();
    Contact afterUpdate = [SELECT  location_boat__c FROM Contact WHERE 
    Id=:updateLocation.Id];
    System.assertEquals('India', afterUpdate.location_boat__c);

    Test.stopTest();


    }
    }

 
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__c
My 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

        );
    }

}

 
Hi everyone, i am new with Apex and i have a question.
I want to update the Contact object field location_boat__c and that the location__c fields of the Boat object be updated also be updated My test is incompleted. i want test my trigger UpdateLocationand i dont know how do it
the object Boat field name Contac__c have relationship lookup with the Contact (Object standard)
My test is wrong but i can not how resolve this problem
trigger UpdateLocation on Contact (after update) { if (trigger.isAfter
&& Trigger.isUpdate) {
     List<Boat__c> boats = new List<Boat__c>();
     for (Contact c : [
                 SELECT location_boat__c, (SELECT Id FROM Boats__r)
                 FROM Contact
                 WHERE Id = :trigger.new
             ]) {
         for (Boat__c b : c.Boats__r) {
             b.location__c = c.location_boat__c;
             boats.add(b);
         }
     }
     update(boats); }}
 
@isTest
public class PruebaBotes {
@isTest static void TestActualizar() {

            Boat__c b1  = new Boat__c(Name='bote uno' ,Price__c=20, Type__c='Velero', location__c='Argentina');
            Boat__c b2  = new Boat__c(Name='bote dos' ,Price__c=50, Type__c='Yate', location__c='Brasil');
            Boat__c b3  = new Boat__c(Name='bote tres' ,Price__c=125, Type__c='Catamaran', location__c='España');
            Boat__c b4  = new Boat__c(Name='bote cuatro' ,Price__c=700, Type__c='Velero', location__c='India');

            insert b1;
            insert b2;
            insert b3;
            insert b4;   

            Contact a1 = new Contact(Lastname='Pepe',  location_boat__c = 'Brasil');
            Contact a2 = new Contact(Lastname='Jose',  location_boat__c = 'Argentina');
            Contact a3 = new Contact(Lastname='Maria', location_boat__c = 'India');
            Contact a4 = new Contact(Lastname='Ana',   location_boat__c = 'Argentina');

            insert a1;
            insert a2;
            insert a3;
            insert a4;    

            Contact updateLocation;
            updateLocation = [SELECT location_boat__c FROM Contact WHERE location_boat__c = 'Argentina' LIMIT 1];
            updateLocation.location_boat__c = 'India';
            update updateLocation;

Test.startTest();
    Contact afterUpdate = [SELECT  location_boat__c FROM Contact WHERE 
    Id=:updateLocation.Id];
    System.assertEquals('India', afterUpdate.location_boat__c);

    Test.stopTest();


    }
    }