• John King20
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 6
    Replies
Hi guys.
I have a requirement I'd like some help with. Open to any suggestions.

Currently: we have a custom Relationship object. Currently on a Contact, a New Relationship can be created to Accoount, containing information such as Role etc. 

The requirement is that we can create multiple relationships in one go.
So Contact A could be related to Account A, Account B and Account C with the same role. Currently the user has to create 3 separate relationships.

Looking for some sort of 'multi-select' option.

Open to creative ideas.
Hi, 
I have a new field I created. This field is only included in one trigger and nowhere else. The field updates fine, but immediately after, the value of the field changes back to the previous value. The field is not referenced anywhere else so I'm thinking there must be some process that is updating all fields on the object. Is there a way to find this? 

The field is definitely not referenced anywhere else in our code. 
Hi,
I have a formula field for Attachment as follows
HYPERLINK('/servlet/servlet.FileDownload?file=' + Id, 'View',"_blank")

When the Attachment is of type .docx it downloads however when it is a PDF it opens in a new tab. Is it possible to make this happen. I've tried the settings in File Upload and Download Security also.

Thanks for any assistance.
Hi,
Appreciate any help here. New to Apex
I have code which updates on Contacts when Account is updated. I put the code together with the assistance of some code snippets I found online and put the rest of it together based off the requirements.

I'm trying to understand the reason for the use of Trigger.New and Trigger.oldMap. They are concepts I'm not fully familiar with and want to make sure I understand them.

Thanks for any help
for(Account account : [SELECT Id, Total__c, (SELECT Id FROM Contacts) FROM Account WHERE Id IN :Trigger.new]){
        if(account.Total__c != Trigger.oldMap.get(account.id).Total__c){
            Integer numContacts = account.Contacts.size();
            Decimal shareOfTotal = account.Total__c.divide(numberOfContacts,2)

 
Hi,
So I have a trigger to share an amount among Contacts when when Account is updated. I'm trying to evaluate where if the "split" amount is 0.00 to show to 3 decimal places rather than 2, but I can't get the code
if (shareEachContact == 0.00) to evaluate.
Basically if 0.02 was to be split among 3 contacts I'd want it split 0.007, 0.007, 0.006.
I have functionality that works for 2 decimnal places but want to cater for 3 in the above scenarion. Code below.
trigger updateShareFromTotal on Account (after update) {
    List<Contact> childContacts = new List<Contact>();
    
    for(Account account : [SELECT Id, Total__c, (SELECT Id FROM Contacts) FROM Account WHERE Id IN :Trigger.new]){
        if(account.Total__c != Trigger.oldMap.get(account.id).Total__c){
            Integer contactNumber = account.Contacts.size();
            Decimal shareEachContact = 0;
            shareEachContact = account.Total__c.divide(contactNumber,2);           
            if (shareEachContact == 0.00){
                shareEachContact = account.Total__c.divide(contactNumber,3);
            }     
            for (Integer i = 0; i < account.Contacts.size(); i++) {
                if (i == (contactNumber - 1)) {
                    account.Contacts[i].Share__c = account.Total__c - (shareEachContact * (contactNumber - 1));
                } else {
                    account.Contacts[i].Share__c = shareEachContact;
                }
                childContacts.add(account.Contacts[i]);
            }
        }
    }
    update childContacts;
}

 
Hi, 
I have a new field I created. This field is only included in one trigger and nowhere else. The field updates fine, but immediately after, the value of the field changes back to the previous value. The field is not referenced anywhere else so I'm thinking there must be some process that is updating all fields on the object. Is there a way to find this? 

The field is definitely not referenced anywhere else in our code. 
Hi,
I have a formula field for Attachment as follows
HYPERLINK('/servlet/servlet.FileDownload?file=' + Id, 'View',"_blank")

When the Attachment is of type .docx it downloads however when it is a PDF it opens in a new tab. Is it possible to make this happen. I've tried the settings in File Upload and Download Security also.

Thanks for any assistance.
Hi,
Appreciate any help here. New to Apex
I have code which updates on Contacts when Account is updated. I put the code together with the assistance of some code snippets I found online and put the rest of it together based off the requirements.

I'm trying to understand the reason for the use of Trigger.New and Trigger.oldMap. They are concepts I'm not fully familiar with and want to make sure I understand them.

Thanks for any help
for(Account account : [SELECT Id, Total__c, (SELECT Id FROM Contacts) FROM Account WHERE Id IN :Trigger.new]){
        if(account.Total__c != Trigger.oldMap.get(account.id).Total__c){
            Integer numContacts = account.Contacts.size();
            Decimal shareOfTotal = account.Total__c.divide(numberOfContacts,2)

 
Hi,
So I have a trigger to share an amount among Contacts when when Account is updated. I'm trying to evaluate where if the "split" amount is 0.00 to show to 3 decimal places rather than 2, but I can't get the code
if (shareEachContact == 0.00) to evaluate.
Basically if 0.02 was to be split among 3 contacts I'd want it split 0.007, 0.007, 0.006.
I have functionality that works for 2 decimnal places but want to cater for 3 in the above scenarion. Code below.
trigger updateShareFromTotal on Account (after update) {
    List<Contact> childContacts = new List<Contact>();
    
    for(Account account : [SELECT Id, Total__c, (SELECT Id FROM Contacts) FROM Account WHERE Id IN :Trigger.new]){
        if(account.Total__c != Trigger.oldMap.get(account.id).Total__c){
            Integer contactNumber = account.Contacts.size();
            Decimal shareEachContact = 0;
            shareEachContact = account.Total__c.divide(contactNumber,2);           
            if (shareEachContact == 0.00){
                shareEachContact = account.Total__c.divide(contactNumber,3);
            }     
            for (Integer i = 0; i < account.Contacts.size(); i++) {
                if (i == (contactNumber - 1)) {
                    account.Contacts[i].Share__c = account.Total__c - (shareEachContact * (contactNumber - 1));
                } else {
                    account.Contacts[i].Share__c = shareEachContact;
                }
                childContacts.add(account.Contacts[i]);
            }
        }
    }
    update childContacts;
}