• Shivani Kolhe 11
  • NEWBIE
  • 30 Points
  • Member since 2023
  • Salesforce Developer
  • Cymetrix software pvt ltd


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 8
    Replies

I have a doozy of a user story, and I'm stuck.  I will try to explain as best as I can. 

Objects in Question:
Account (Standard)  
Project (Custom) - Master Detail relation to Account.  
Project Services (Custom) -  Junction object between Service & Project.  
Service (Custom) - Just a list of services we offer that need to be linked to multiple other records.   
Current Services (Custom) - Junction object between service & account.

Each 'Account' can have multiple 'Projects' (Master Detail).  Each 'Project' can have multiple 'Services' (Junction Object).  Therefore each 'Account' can have multiple 'Services' (Junction Object).  

What I desperately need: When I relate a 'Service' record to a 'Project', through junction object 'Project Services', I need an identical relation to be created between 'Account' and 'Service', on junction object 'Current Services'.  Is this doable though a Flow or a Trigger?

EX:  'Account A' has just become an active client. User goes to create the new record 'Project 1' associated with 'Account A' on the custom 'Project' object.  While creating 'Project 1', user relates 'Service 1' & 'Service 2' to that project through junction object 'Project Services'.  At the same time a new record needs to be created on the junction object 'Current Services' relating that service to 'Account A'. Each 'Service' only need be added to 'Account A' once.

Think of this as a rollup of related 'Services' to the related 'Account' listed on a 'Project' record. End result being 'Account A' will always have a list of current services in a related list.

Help please?  I've been thinking about this for 3 straight days, and my brain hurts.  Feel free to ask clarifying questions if I make absolutely zero sense.

I've never written a trigger, so if that's my path, any advice or help would be much appreciated. 

I have a doozy of a user story, and I'm stuck.  I will try to explain as best as I can. 

Objects in Question:
Account (Standard)  
Project (Custom) - Master Detail relation to Account.  
Project Services (Custom) -  Junction object between Service & Project.  
Service (Custom) - Just a list of services we offer that need to be linked to multiple other records.   
Current Services (Custom) - Junction object between service & account.

Each 'Account' can have multiple 'Projects' (Master Detail).  Each 'Project' can have multiple 'Services' (Junction Object).  Therefore each 'Account' can have multiple 'Services' (Junction Object).  

What I desperately need: When I relate a 'Service' record to a 'Project', through junction object 'Project Services', I need an identical relation to be created between 'Account' and 'Service', on junction object 'Current Services'.  Is this doable though a Flow or a Trigger?

EX:  'Account A' has just become an active client. User goes to create the new record 'Project 1' associated with 'Account A' on the custom 'Project' object.  While creating 'Project 1', user relates 'Service 1' & 'Service 2' to that project through junction object 'Project Services'.  At the same time a new record needs to be created on the junction object 'Current Services' relating that service to 'Account A'. Each 'Service' only need be added to 'Account A' once.

Think of this as a rollup of related 'Services' to the related 'Account' listed on a 'Project' record. End result being 'Account A' will always have a list of current services in a related list.

Help please?  I've been thinking about this for 3 straight days, and my brain hurts.  Feel free to ask clarifying questions if I make absolutely zero sense.

I've never written a trigger, so if that's my path, any advice or help would be much appreciated. 

We have a lightning data table built in LWC, which has 2 columns - start date and end date. Start Date is going to be the first date of any month and the End Date would be the last date of the same month. However, we expect that as soon as the first start date has been entered manually, the rest of the start and end dates be calculated automatically in the same fashion. And the calculation should happen for next 12 months. The values in the data table are later being stored in the databaseUser-added image
I've built a record-triggered Flow which updates a custom field on the Case object named Reporting Status whenever an email is sent from a Salesforce user to a customer from the case record.

Unfortunately, it's not working consistently. When users send a fresh email from the case record using the email action on the case feed, the field update occurs as it should. However, if the users clicks Reply against the email from the customer and replies that way, the Flow doesn't seem to trigger to update the field.

I'm not receiving the automated FlowApplication email to indicate an issue with the Flow, but I can't understand why it's working in the one instance and not in others.

User-added imageUser-added imageUser-added image
I am trying to send transactional emails from Salesforce by using the SendGrid API (via External Services) and Flow Builder.

Here is what I've done so far:
  • Added the SendGrid auth credentials to Salesforce (Setup > Named Credentials)
  • Imported the SendGrid v3 OpenAPI spec to Salesforce (Setup > External Services)
We now have over 300 SendGrid API operations we can conduct from within any Salesforce Flows.

We want to use the 'POST_Mail-Send' Flow Action to send an email, but I don't know how to setup the flow to accept the payload that SendGrid is looking for.

The only parameter I see in the Invokable Action is "Body" and I'm not sure how to pass values to it. The SendGrid API needs a 'from', 'to', 'dynamic_template_data', and 'template_id' according to their docs (https://docs.sendgrid.com/ui/sending-email/how-to-send-an-email-with-dynamic-templates).

How do I construct a payload body to pass to the invokable action within my flow?
I'm quite new to SF nad started with learn with trailhead. For that purpose I created developer account. Sofar so good. Now I wanted to create a simple HR tool for vacation requests for employees as learn by doing. Then I realized there is something like that already ( e.g. WorkflowX ). So I wanted to try it out. Installed it and looks good, but there is only one employee in the app ... me. So I created another user, gave him  name, role etc. But it does not appear as an employee. I saw in some forum you need to open "Employees" from App Launcher and match new Employee with an user ... but I can't see "Employees" app anywhere. And there is no employee object (which I read should be default object). Do I miss something? How can I impl. any (HR) App if I can't create any additional employee in my dev/sandbox organization?   
Our Org is new to creating and editing Apex code. We have run into an issue where the below Apex Class (4 years old) is preventing validation and deployment of any change packages that contain Apex. Based on what we know, this Apex Class is not tied to any Apex Triggers or automation and is purely a validation that was written when our Org was first created. We have checked for any related metadata to this Apex Class and the only related items are the 4 custom fields towards the bottom of the class and they are on the Contract object.

/**
* @author Conga Services
* @date
* @version 1.00
* @description ContractTest  - Test class for the [Name of class being tested] class
*/
@isTest
public with sharing class ContractTest {
    ///////////// ADD JAVA DOC AUTHOR, DATE, AND/OR VERSION TAGS TO METHODS WHEN THE VALUES DIFFER THAN THE CLASS LEVEL TAGS
    /**
    * @description setup - Test data setup method
    */
    @testSetup
    public static void setup(){
        /////// Create your test data here using TestingUtility helper methods
        List<Account> accounts = new List<Account>();
        Account acc = new Account();
        acc.Name = 'Test Account';
        acc.BillingStreet = '1234 Test Street';
        acc.BillingCity = 'Broomfield';
        acc.BillingState = 'CO';
        acc.BillingPostalCode = '80021';
        acc.BillingCountry = 'USA';
        accounts.add(acc);
        Account acc1 = new Account();
        acc1.Name = 'Account Test';
        acc1.BillingStreet = '4321 Test Street';
        acc1.BillingCity = 'Superior';
        acc1.BillingState = 'CO';
        acc1.BillingPostalCode = '80027';
        acc1.BillingCountry = 'USA';
        accounts.add(acc1);
        insert accounts;
        List<Contact> contacts = new List<Contact>();
        Contact contact = new Contact();
        contact.FirstName = 'Test';
        contact.LastName = 'Contact';
        contact.Email = 'test@contact.com';
        contacts.add(contact);
        Contact contact1 = new Contact();
        contact1.FirstName = 'Contact';
        contact1.LastName = 'Test';
        contact1.Email = 'contact@test.com';
        contacts.add(contact1);
        insert contacts;
    }
   
    /**
    * @description testMethod1 - Test Happy Path of code
    */
    public static testMethod void testMethod1() {
        // Get test data
        List<Account> accs = [SELECT Id FROM Account WHERE Name = 'Test Account'];
        List<Contact> cons = [SELECT Id FROM Contact WHERE Email = 'test@contact.com'];
        Contract contract = new Contract();
        contract.Contractor_Consultant_Name__c = 'Test Account';
        contract.BillingStreet = '1234 Test Street';
        contract.BillingCity = 'Broomfield';
        contract.BillingState = 'CO';
        contract.BillingPostalCode = '80021';
        contract.BillingCountry = 'USA';
        contract.Other_Party_Contact_Name__c = 'Test Contact';
        contract.Other_Party_Contact_Email__c = 'test@contact.com';
       
        //ApexPages.StandardController sc = new ApexPages.StandardController(td.Accounts[0]);
        //SubProjectViewController cn = new SubProjectViewController(sc);
        Test.startTest();
        insert contract;
        Contract c = [SELECT AccountId, Other_Party_Contact_Name_Lookup__c FROM Contract WHERE Id = :contract.Id][0];
        System.assertEquals(true, c.AccountId == accs[0].Id,'The fuzzy match did not find the appropriate account');
        System.assertEquals(true, c.Other_Party_Contact_Name_Lookup__c == cons[0].Id,'The fuzzy match did not find the appropriate contact');
        Test.stopTest();//will sync back up with async operations if future/batch called before this
    }  
}


We plan to comment out this code in Production so it will pass validation. The error message we are currently receiving is the following: 

System.UnexpectedException: No more than one executeBatch can be called from within a test method. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.
Stack Trace: External entry point


Given all of this information, are there any obvious concerns we should have before deploying the commented out version in Production? Additionally, are there any tests we should run pre and post update? 

Thanks!
I have Created two Objects say Teacher__c(Parent) and Student__c(Child) having similar fields such as name, email, mobile and Address. and they have two unique fields on both objects such as teacherid__c on teacher object and id__c on student object On deleting record of Teacher__c, associated Student__c record should be deleted and vice versa.
here in my code insertion and updation is working but deletion is not working can anyone help me doing that
code:
trigger TeacherTrigger on Teacher__c (after insert, after update, before delete) {
    if (Trigger.isAfter) {
        if (Trigger.isInsert) {
            List<Student__c> studentsToInsert = new List<Student__c>();
            for (Teacher__c teacher : Trigger.new) {
                if(triggerCount.runonce()){
                    Student__c student = new Student__c();
                    student.Name = teacher.Name;
                    student.Email__c = teacher.Email__c;
                    student.Mobile__c = teacher.Mobile__c;
                    student.Address__c = teacher.Address__c;
                    student.id__c = teacher.Id;
                    studentsToInsert.add(student);
                }
            }
            if (!studentsToInsert.isEmpty()) {
                insert studentsToInsert;
            }
        }
        if (Trigger.isUpdate) {
            List<Student__c> studentsToUpdate = new List<Student__c>();
            for (Teacher__c teacher : Trigger.new) {
                if(triggerCount.runonce()){
                    List<Student__c> existingStudents = [SELECT Id, Name, Email__c, Mobile__c, Address__c, id__c FROM Student__c WHERE id__c = :teacher.Id LIMIT 1];
                    if (!existingStudents.isEmpty()) {
                        Student__c student = existingStudents[0];
                        student.Name = teacher.Name;
                        student.Email__c = teacher.Email__c;
                        student.Mobile__c = teacher.Mobile__c;
                        student.Address__c = teacher.Address__c;
                        studentsToUpdate.add(student);
                    }
                }
            }
            if (!studentsToUpdate.isEmpty()) {
                update studentsToUpdate;
            }
        }
        if (Trigger.isDelete) {
            list<String> teacherIds=new list<String>();
            for(Teacher__c teacher:trigger.old)
            {
                teacherIds.add(teacher.id);
            }
            list<Student__c> listOfStudents=[select id,id__c from Student__c where id__c in:teacherIds];
            System.debug('Number of students found: ' + listOfStudents.size());
            system.debug('listOfstudents'+listOfStudents);
            if (!listOfStudents.isEmpty()) {
                delete listOfStudents;
            }
        }
    }
}


trigger StudentTrigger on Student__c (after insert, after update, before delete) {
    if (Trigger.isAfter) {
        if (Trigger.isInsert) {
            List<Teacher__c> teachersToInsert = new List<Teacher__c>();
            
            for (Student__c student : Trigger.new) {
                if(triggerCount.runonce()){
                    Teacher__c teacher = new Teacher__c();
                    teacher.Name = student.Name;
                    teacher.Email__c = student.Email__c;
                    teacher.Mobile__c = student.Mobile__c;
                    teacher.Address__c = student.Address__c;
                    teacher.teacherid__c = student.Id;
                    teachersToInsert.add(teacher);
                }
            }
            
            if (!teachersToInsert.isEmpty()) {
                insert teachersToInsert;
            }
        }
        
        if (Trigger.isUpdate) {
            List<Teacher__c> teachersToUpdate = new List<Teacher__c>();
            for (Student__c student : Trigger.new) {
                if(triggerCount.runonce()){
                    List<Teacher__c> existingTeachers = [SELECT Id, Name, Email__c, Mobile__c, Address__c, teacherid__c FROM Teacher__c WHERE teacherid__c = :student.id LIMIT 1];
                    if (!existingTeachers.isEmpty()) {
                        Teacher__c teacher = existingTeachers[0];
                        teacher.Name = student.Name;
                        teacher.Email__c = student.Email__c;
                        teacher.Mobile__c = student.Mobile__c;
                        teacher.Address__c = student.Address__c;
                        teachersToUpdate.add(teacher);
                    }
                }
            }
            
            if (!teachersToUpdate.isEmpty()) {
                update teachersToUpdate;
            }
        }
        if (Trigger.isDelete) {
            list<String> studentIds=new list<String>();
            for(Student__c student:trigger.old)
            {
                studentIds.add(student.id);
            }
            list<Teacher__c> listOfTeachers=[select id,teacherid__c from Teacher__c where teacherid__c in:studentIds];
            system.debug('listOfTeachers'+listOfTeachers);
            if (!listOfTeachers.isEmpty()) {
                delete listOfTeachers;
            }
        }
    }
}
Thanks
Hi Team, 
I have a similar problem, pdf is getting saved twice in attachment section

This is my First Page- 9calling 'SaveAttach' method in first page
<apex:page standardController="Proforma_Invoice__c" extensions="TemplateController" action="{!saveAttach}" renderAs="pdf">

This is my second page- <apex:page standardController="Proforma_Invoice__c" extensions="TemplateController" renderAs="pdf">

and this is my controller class-  Public void saveAttach() {
        try {
            System.debug('Inside saveAttach');
            
            // Check if the attachment already exists
        if (hasAttachment()) {
            System.debug('Attachment already exists. Skipping saveAttach.');
            return;
        }
            PageReference pdfPage = Page.Proforma_InvoiceV2;
            pdfPage.getParameters().put('id',profInv.id);
            Blob pdfBlob = pdfPage.getContent();
            Attachment a = new Attachment(parentId = profInv.id, name=profInv.name + '-ProformaInvoice.pdf', body = pdfBlob);
            insert a;
        } catch (Exception e) {
            system.debug('an error occured: '+e.getMessage());
        }
    }
    private Boolean hasAttachment() {
    // Query attachments with the same parent ID
    List<Attachment> attachments = [SELECT Id FROM Attachment WHERE ParentId = :profInv.id LIMIT 1];
    return !attachments.isEmpty();
}