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
satish waghsatish wagh 

Cross Object Trigger?

How to write cross object trigger in salesforce?
I have one checkbox in one of my custom object and 'Instalment field' in another custom object, if that checkbox is checked in then first object then take sum of all instalments in another object
Best Answer chosen by satish wagh
Adilson Arcoverde JrAdilson Arcoverde Jr
Satish,

Now you have to create a new custom object called Project Members. This object has at least four custom fields:
  1. A master detail field related to your Project object
  2. A lookup field to related to User object 
  3. A picklist field with values: Tester, Developer, Architect, Delivery Manager 
  4. A percent field to store rating data
By default, when you create a new object related to other object, Salesforce automatically adds the related list on your Project page layout.

If stills not clear to you on how to implement, I could record a video for you. It will take a while, because I'll be with my notebook in couple hours.

Let me know if the video is necessary.
 

All Answers

Adilson Arcoverde JrAdilson Arcoverde Jr
Hi  satish wagh,

Why don't you use this first object as detail of the later? With this relationship, you can create a roll-up summary field, using a count roll-up type and filtering children objects only when your checkbox field is setted to true.

If this is not possible, you can try the code below:
 
trigger ChildObjectTrigger on Child_Object__c (after update) {
    if( Trigger.isAfter && Trigger.isUpdate ) {
        Set<String> parentIdsToUpdate = new Set<String>();
        for( Child_Object__c child : Trigger.new ) {
            // Check if Checkbox_Field__c has changed.
            if( child.Checkbox_Field__c != Trigger.oldMap.get( child.Id ).Checkbox_Field__c ) {
                parentIdsToUpdate.add( child.Parent_ID_Field__c );
            }
        }

        if( parentIdsToUpdate.size() > 0 ) {
            List<Parent_Object__c> parentObjectsToUpdate = [Select Id, Instalment__c, (Select Id from Children_Relationship_Name__r where Checkbox_Field__c = true ) from Parent_Object__c where Id in :parentObjectsToUpdate];
            for( Parent_Object__c parentObject : parentObjectsToUpdate ) {
                parentObject.Instalment__c = parentObject.Children_Relationship_Name__r.size();
            }

            update parentObjectsToUpdate;
        }
    }
}

Hope you find this solution useful. If it does please check as Best Answer to help others too.

Regards.
satish waghsatish wagh
Best Answer!
Adilson Arcoverde JrAdilson Arcoverde Jr
Hi Satish,

Would you mind to mark my answer as Best Answer? This is help other developers.

Regards.
 
satish waghsatish wagh
Hi Adison Arcoverde Jr,
Would Please Help me in this problem if you dont mind:
The project manager (Project’s owner) should have a way to add team members to the
project. These team members would be internal users of the Salesforce org. While
assigning team member, project manager would select a role for each team member.
Project Manager should be able to define the hourly rate for each team member.
○ Tester
○ Developer
○ Architect
○ Delivery Manager
Adilson Arcoverde JrAdilson Arcoverde Jr
Hi Satish,

You have to create a custom object called Project Team with this fields:
  1. A master detail field to project object 
  2. A lookup field to user
  3. A picklist field with those roles
  4. A percent/number field to store the rating
Add the Project Team related list to Project layout.

Is this a good solution for your problem?

Let me know if I can help with anything else.

Regards.
satish waghsatish wagh
Hi Adison Arcoverde Jr,
First of all, I would like to thank you for taking your time to answer these questions. Actually i dont understand the meaning of this statement in the question:
"These team members would be internal users of the Salesforce org."
What i did is that i created users and create role in role hierarchy but i dont understatnd what should do next. 
 
satish waghsatish wagh
Hi Adilson Arcoverde Jr, First of all, I would like to thank you for taking your time to answer these questions. Actually i have below small project. Please find the attachment. And i already created custom object Project.
satish waghsatish wagh
User-added image
Adilson Arcoverde JrAdilson Arcoverde Jr
Satish,

Now you have to create a new custom object called Project Members. This object has at least four custom fields:
  1. A master detail field related to your Project object
  2. A lookup field to related to User object 
  3. A picklist field with values: Tester, Developer, Architect, Delivery Manager 
  4. A percent field to store rating data
By default, when you create a new object related to other object, Salesforce automatically adds the related list on your Project page layout.

If stills not clear to you on how to implement, I could record a video for you. It will take a while, because I'll be with my notebook in couple hours.

Let me know if the video is necessary.
 
This was selected as the best answer
satish waghsatish wagh
Hi Adison Arcoverde Jr,
Thank you for your prompt reply! Now this is clear to me. There is no need to video.Personally you are vert good man.
Thanks Once again!
Adilson Arcoverde JrAdilson Arcoverde Jr
Thanks Satish.

Hope the best of luck to you. If you need any kind of help, you can send me a direct message on Twitter. My user is @AdilsonArcoverd

Regards.
satish waghsatish wagh
Thanks Adison Arcoverde Jr.
satish waghsatish wagh
Hi Adison Arcoverde Jr,
How to implement below task Please help me?

Timesheet is a child object of Project. It will have following fields
○ Autonumber
○ Relationship with Project
○ Billing Date
○ Hours
○ Hourly Rate
○ Description
○ Approved?
● A user should not be able to log more than 24 hours in timesheet for any billing date.
● Once a user logs in the hours for a day, he should be able to submit it for approval. The
approval will go to Project Manager. Once approved, the timesheet should have the
“Approved?” checkbox to true. In case of rejection, the submitter should get an email
with reason for rejection.
● For hourly type, Project should have auto calculate “Total Amount” field. This should be
derived from timesheet records and only consider the timesheets which are approved.