• Robert Lange 6
  • NEWBIE
  • 70 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 9
    Replies
User-added imageI am trying to create a joined report.  The initial report is Opportunities by the related object Property (which returns 2 records).  The "add block" joined report I added is Opportunities by the related object Job (which should return the same 2 Opportunities).  I do not know why the Opportunities by Job columns are blank and do not display any data.
I know how to add an Activity Timeline to a Lead or Opportunity.  How would I add it to my org's home page?  Also, I am trying to figure out how to add Quick Actions like the ones shown here to my org's home page.

User-added image
I have written a trigger where if the user attempts to make a 2nd related contact on the account object a Primary Contact too, an error is thrown.  I am trying to add syntax to my trigger so if the user adds a related contact to an Account that currently has 0 related contacts, this new contact will automatically become the primary contact.  This is the code I have so far:
Trigger PrimaryContactTrigger on Contact (Before Insert, Before Update) {

    List<Id> actIds = New List<Id>();
    List<Contact> comingCons = New List<Contact>();
    List<Id> conIds = New List<Id>();

    If (Trigger.IsBefore && (Trigger.IsInsert || Trigger.IsUpdate)) {
        For (Contact Con : Trigger.New) {
            If (Con.IsPrimary__c == TRUE) {
                actIds.add(Con.AccountId);
                conIds.add(Con.Id);
                comingCons.add(Con);
            }
            }
        }
        List<Account> allRelatedAccounts = [
                Select Id, (
                        Select Id, IsPrimary__c
                        FROM Contacts
                        WHERE IsPrimary__c = TRUE
                        AND Id != :conIds
                )
                FROM Account
                WHERE Id = :actIds
        ];
        For (Contact EveryCon : comingCons) {
            For (Account EveryAccount : allRelatedAccounts) {
                If (EveryCon.AccountId == EveryAccount.Id && EveryAccount.Contacts.size() > 0) {
                    EveryCon.addError('THERE is already a primary contact for this account');
                }
            }
        }
    }

 
I am trying to write Apex code for the following:

Covid 19 Info

Area-Holds info about all covid19 patients in an area
Patient - A person infected with covid 19.  It has a field called state (mild/critical/cured/fatal)

Area and Patient share a lookup relationship

Find out-
1. Avg days to recover in that area (Cured date - CreatedDate)
2. Avg days of fatality (Fatal data - CreatedDate)

Trigger and helper class are below.  I don't have any errors with the code, but I can't get it working.  Any help would be appreciated.  Thank you.
 
trigger CoronaCountyTrigger on Patient__c (after insert, after update, after delete) {

    if (Trigger.isInsert || Trigger.isAfter || Trigger.isDelete) {
        if (Trigger.isAfter) {
            CoronaCountyHelper.avgFatal();
        }
    }
}
 
public with sharing class CoronaCountyHelper {
    public static void avgFatal() {
        Set<Id> countyIds = new Set<Id>();
        List<County__c> countyList = new List<County__c>();
        List<Patient__c> patientList = Trigger.isInsert || Trigger.isUpdate ? Trigger.new : Trigger.old;
        for (Patient__c pat1 : patientList) {
            countyIds.add(pat1.County__c);
        }

        for (AggregateResult ag : [
                SELECT County__c, AVG(Days_Until_Fatal__c) avg1
                FROM Patient__c
                GROUP BY County__c
        ]) {
            countyList.add(new County__c(
                    Id = (Id) ag.get('County__c'),
                    AVG_Days_Until_Fatal__c = (Integer) ag.get('avg1')));
        }

        if (countyList.size() > 0) {
            update countyList;
        }
    }
}

 
Just a general question, lets say I post a question that gets 3 replies.  The replies are from Person A, B and C.  If I then reply to Person B's comment, do all three people get notified of my reply or does Person B get notified of my reply?
I have an org with a custom object call Property.  I wish to put a lwc map on the Property record page that shows the location of the Property on the map.  Haven't quite been able to find what I'm looking for.
I am trying to write a trigger and helper class for an Account that has the Type as "Prospect".  If the Account is updated and has no related Opportunities, two new Opportunities are added to the Account.  I have not had any luck getting the code to work.

Here is my Trigger:

trigger ResComOpportunityTrigger on Account (after update) {
    if(Trigger.isAfter && Trigger.isUpdate){
        ResComOpportunityHelper.UpdateOpps(Trigger.new);
    }
}

Here is my helper class:

public with sharing class ResComOpportunityHelper {

    static public void UpdateOpps(List<Account> acctList) {

        List<Opportunity> updateOppsList = new List<Opportunity>();

        acctList = [
                SELECT Id, Name, OwnerId, (SELECT Name, Id FROM Opportunities)
                FROM Account
                WHERE Type = 'Prospect'
        ];

        for (Account accUp : acctList) {
            for (Opportunity opp : accUp.Opportunities) {
                if (opp.Name == null) {
                    Opportunity opp1 = new Opportunity();
                    opp1.Name = 'Default Residential Opp';
                    opp1.AccountId = accUp.Id;
                    opp1.CloseDate = System.today().addMonths(3);
                    opp1.StageName = 'Prospecting';
                    updateOppsList.add(opp1);

                    Opportunity opp2 = new Opportunity();
                    opp2.Name = 'Default Commercial Opp';
                    opp2.AccountId = accUp.Id;
                    opp2.CloseDate = System.today().addMonths(3);
                    opp2.StageName = 'Prospecting';
                    updateOppsList.add(opp2);
                }
            }
        }
        insert updateOppsList;
    }
}

Any assistance would be appreciated!
I have the following trigger that inserts an Invoice as a related object to the Contact.  The Invoice has a number field that is auto-generated.  Is there a way to code this so that the each Invoice will have the name "Invoice" plus it's number (0001, 0002, etc.)?


trigger contactGenInvoice on Contact (after insert, after update) {
    List<Invoice__c> invoiceList = new List<Invoice__c>();
    for (Contact con : Trigger.new) {
        if (con.Status__c == 'Inactive') {

            Invoice__c i = new Invoice__c();

            i.Name = 'Invoice ';
            i.Date__c = System.today();
            i.Amount__c = 100;
            i.ContactId__c = con.Id;
            invoiceList.add(i);

        }
        insert invoiceList;
    }
}
I have written this trigger which adds and opportunity to any new account insertions and account updates (where the account does not have an existing related opportunity).  My current test class provides 76% coverage.  Any advice would be appreciated!

APEX TRIGGER:
trigger AddRelatedRecord on Account(after insert, after update) {

    if (Trigger.isInsert) {
        for (Account a : Trigger.new) {
            Opportunity opp = new Opportunity();
            opp.Name = a.Name + ' Opportunity';
            opp.StageName = 'Prospecting';
            opp.CloseDate = System.today().addMonths(1);
            opp.AccountId = a.Id;
            insert opp;

        }
    }

    if (Trigger.isUpdate) {
        List<Opportunity> oppList = new List<Opportunity>();

        List<Account> accountsWithoutOppsAndGotUpdated = [
                SELECT Id, Name
                FROM Account
                WHERE Id NOT IN (SELECT AccountId FROM Opportunity) AND Id IN :Trigger.new];

 
        for (Account a : accountsWithoutOppsAndGotUpdated) {
            oppList.add(new Opportunity(Name = a.Name + ' Opportunity',
                    StageName = 'Prospecting',
                    CloseDate = System.today().addMonths(1),
                    AccountId = a.Id));
        }
        insert oppList;
    }
}

HERE IS MY CURRENT TEST CLASS:
@IsTest
private class AddRelatedRecordTest {

    @IsTest public static void addRelatedRecordTestonInsert() {

        Account testAcc = new Account(Name = 'My Account Test');
        insert testAcc;
        update testAcc;
        
        System.assert(true, 'Account Updated');

    }

}
I am getting the error in my Developer Console:
Failed to load data File from Salesforce.com.  The requested resource does not exist.  Any idea what the issue is?
User-added image
I have written the following formula field:
(YEAR(TODAY())-YEAR(Purchase_Date__c))*Annual_Depreciation__c

I am trying to find out how to change the formula so that if the Purchase Date were 9/26/2018 and we are using 3/26/2020 as today's date, it would return a value of 1.5 (and not a value of 2).  Any thoughts?
I have 3 custom fields for my Property object: Purchase Date, Annual Depreciation and Total Depreciation.  I am writing a formula and here is a draft for the Total Depreciation field:
ABS(YEAR(TODAY())-YEAR(Purchase_Date__c))  * Annual_Depreciation__c

I want to revise the formula so that if the purchase date were 12/23/2018 and we were using 3/23/2020 as the current date, the time calculation would be more precise.  Under my current formula ABS(YEAR(TODAY())-YEAR(Purchase_Date__c)), the value returned is 2 years.  I would like it to be a more exact number (in this case 1.25 years).  Any help with the revised formula would be appreciated.

 
For the Case object field "Date/Time Opened" it lists field-level security as for the System Admin as visible and read-only.  However on the field accessibility setting for this field, it says read-only.  When I go to create a new Case under the System Admin profile, I do not see the field for Date/Time Opened.  This field IS selected when I look at the page layout info for the Case Layout.  Any thoughts?
The trigger should relate the Contact to the Account record.  I have tried the following code.  I am getting an error message on the line, "WhatID = acc.ID;"

trigger CreateContact on Account (after insert) {
    for (Account acc : Trigger.new){
        Contact c = new Contact();
        c.FirstName = 'Jo Jo';
        c.LastName = 'Murphy';
        WhatID = acc.ID;
        insert c;        
    }

}
I have written a trigger where if the user attempts to make a 2nd related contact on the account object a Primary Contact too, an error is thrown.  I am trying to add syntax to my trigger so if the user adds a related contact to an Account that currently has 0 related contacts, this new contact will automatically become the primary contact.  This is the code I have so far:
Trigger PrimaryContactTrigger on Contact (Before Insert, Before Update) {

    List<Id> actIds = New List<Id>();
    List<Contact> comingCons = New List<Contact>();
    List<Id> conIds = New List<Id>();

    If (Trigger.IsBefore && (Trigger.IsInsert || Trigger.IsUpdate)) {
        For (Contact Con : Trigger.New) {
            If (Con.IsPrimary__c == TRUE) {
                actIds.add(Con.AccountId);
                conIds.add(Con.Id);
                comingCons.add(Con);
            }
            }
        }
        List<Account> allRelatedAccounts = [
                Select Id, (
                        Select Id, IsPrimary__c
                        FROM Contacts
                        WHERE IsPrimary__c = TRUE
                        AND Id != :conIds
                )
                FROM Account
                WHERE Id = :actIds
        ];
        For (Contact EveryCon : comingCons) {
            For (Account EveryAccount : allRelatedAccounts) {
                If (EveryCon.AccountId == EveryAccount.Id && EveryAccount.Contacts.size() > 0) {
                    EveryCon.addError('THERE is already a primary contact for this account');
                }
            }
        }
    }

 
I have an org with a custom object call Property.  I wish to put a lwc map on the Property record page that shows the location of the Property on the map.  Haven't quite been able to find what I'm looking for.
I have written this trigger which adds and opportunity to any new account insertions and account updates (where the account does not have an existing related opportunity).  My current test class provides 76% coverage.  Any advice would be appreciated!

APEX TRIGGER:
trigger AddRelatedRecord on Account(after insert, after update) {

    if (Trigger.isInsert) {
        for (Account a : Trigger.new) {
            Opportunity opp = new Opportunity();
            opp.Name = a.Name + ' Opportunity';
            opp.StageName = 'Prospecting';
            opp.CloseDate = System.today().addMonths(1);
            opp.AccountId = a.Id;
            insert opp;

        }
    }

    if (Trigger.isUpdate) {
        List<Opportunity> oppList = new List<Opportunity>();

        List<Account> accountsWithoutOppsAndGotUpdated = [
                SELECT Id, Name
                FROM Account
                WHERE Id NOT IN (SELECT AccountId FROM Opportunity) AND Id IN :Trigger.new];

 
        for (Account a : accountsWithoutOppsAndGotUpdated) {
            oppList.add(new Opportunity(Name = a.Name + ' Opportunity',
                    StageName = 'Prospecting',
                    CloseDate = System.today().addMonths(1),
                    AccountId = a.Id));
        }
        insert oppList;
    }
}

HERE IS MY CURRENT TEST CLASS:
@IsTest
private class AddRelatedRecordTest {

    @IsTest public static void addRelatedRecordTestonInsert() {

        Account testAcc = new Account(Name = 'My Account Test');
        insert testAcc;
        update testAcc;
        
        System.assert(true, 'Account Updated');

    }

}
I am getting the error in my Developer Console:
Failed to load data File from Salesforce.com.  The requested resource does not exist.  Any idea what the issue is?
User-added image
I have written the following formula field:
(YEAR(TODAY())-YEAR(Purchase_Date__c))*Annual_Depreciation__c

I am trying to find out how to change the formula so that if the Purchase Date were 9/26/2018 and we are using 3/26/2020 as today's date, it would return a value of 1.5 (and not a value of 2).  Any thoughts?
The trigger should relate the Contact to the Account record.  I have tried the following code.  I am getting an error message on the line, "WhatID = acc.ID;"

trigger CreateContact on Account (after insert) {
    for (Account acc : Trigger.new){
        Contact c = new Contact();
        c.FirstName = 'Jo Jo';
        c.LastName = 'Murphy';
        WhatID = acc.ID;
        insert c;        
    }

}