• Alaric Wimer
  • NEWBIE
  • 225 Points
  • Member since 2019

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 23
    Questions
  • 54
    Replies
I'm trying to query using a relationship between orders and opportunities.
I'm using opps to creat a job workflow to my agents and using orders to store my e-commerce data. I want to know how many opps become an order and know the conversion rate for that. 
I'm using this SOQL query, but i'm doing something wrong.
SELECT
  Name, Profession__c,
  (SELECT
    LastModifiedDate, CreatedDate, StageName
   FROM 
   Opportunity__r),
   (SELECT
     Date_Payment__c, Discount__c, Status, Final_Amount__c, Amount__c
    FROM
     Order__r)
FROM
  Account 
WHERE
  IsPersonAccount = true

 
I have a new trigger that creates a custom object record when an opportunity is created or updated.

Everything works but I need help with one thing. I only want it to run when a specific opportunity type is created or when that type has its "cloe date" field updated.

Here is my code:
trigger createOq on Opportunity (after insert, after update) {

    List <Open_Quarter__c> createOpenQuarter = new List <Open_Quarter__c> (); 
     for(Opportunity opportunityList : trigger.New){
        
       Open_Quarter__c oq = new Open_Quarter__C();

        oq.Amount_Per_Quarter_oq__c = opportunityList.Amount_per_Quarter_op__c; 
        oq.Close_Date_oq__c = opportunityList.CloseDate;
        oq.Name = opportunityList.Quarter_Created_op__c;
        oq.Opportunity_Name_oq__c = opportunityList.Id;
        oq.Quarters_Spanned_oq__c = opportunityList.Quarters_Spanned_op__c;
        
         createOpenQuarter.add(oq);

     }
 
    try {
            insert createOpenQuarter;
    } 
    catch (system.Dmlexception e) {
        system.debug (e);
    }
}

How do I limit this so it only runs when a "Sales" opp is created or when an existing Sales Opp has the "Close Date" field updated?

New to coding and apex so any help is greatly appreciated.

Best regards,
Steve​​​​​​​
Can I use a workflow and field update to replace a null phone number field with N/A? Something like this? IF (ISBLANK ( Phone__c ),N/A, Phone__c 
A ton of leads are coming over blank and trying to find a way to make it easier to manage this field. 

I am getting an error when I run CLI commands after creating a project: Cannot read property 'getInstance' of undefined

 

I am suddenly unable to do any CLI commands with both existing and new projects. The only thing I can do is create the initial project. Everything else gives me this error.

 

Here's the error in the console:

 

console.ts:137 [Extension Host] {
"status": 1,
"name": "TypeError",
"message": "Cannot read property 'getInstance' of undefined",
"exitCode": 1,
"commandName": "ConfigGetCommand",
"stack": "TypeError: Cannot read property 'getInstance' of undefined\n at ConfigGetCommand.hooksFromLifecycleEvent (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:401:44)\n at ConfigGetCommand.init (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:248:20)\n at async ConfigGetCommand._run (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:92:13)\n at async Config.runCommand (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/config/lib/config.js:172:9)\n at async Main.run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/command/lib/main.js:22:9)\n at async Main._run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/command/lib/command.js:43:20)\n at async Object.run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/dist/cli.js:32:20)\nOuter stack:\n at Function.wrap (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/core/lib/sfdxError.js:151:27)\n at ConfigGetCommand.catch (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/dist/ToolbeltCommand.js:247:46)\n at async ConfigGetCommand._run (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:97:13)\n at async Config.runCommand (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/config/lib/config.js:172:9)\n at async Main.run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/command/lib/main.js:22:9)\n at async Main._run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/command/lib/command.js:43:20)\n at async Object.run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/dist/cli.js:32:20)",
"warnings": []
}

 

Does anyone know how I can fix this?

I am trying to create a package version of a project. The Test class of this project references some required fields in the particular org I am working in, but those fields are not a part of my actual package. In addition, RecordTypeId field is referenced in some validation rules that are a part of this package. 

 

I am getting the following error when running sfdx force:package:create https://prnt.sc/tumblg  (https://prnt.sc/tumblg)

 

Does anyone know how I can create a package version in a situation like this?

I have several Opportunities with no Contact Roles assigned. For the Opportunities with no Contact Roles, that are related to Accounts with Contacts, I need to create Contact Roles to match the related Account's Contacts. I am trying to accomplish this with an anonymous apex code block. 

 

Here's what I have started, can anyone help me to make this work? Thank you.

 

Map<Id, Id> oppIdToAccIdMap = new Map<Id, Id>();
Map<Id, Id> conIdToAccIdMap = new Map<Id, Id>();
Set<Id> oppAccountIdSet = new Set<Id>();
List<OpportunityContactRole> ocrsToInsert = new List<OpportunityContactRole>();

// 1. Get all Opportunities that have no contact roles
 List<Opportunity> myOpps = [
     SELECT Id, AccountId
     FROM Opportunity
     WHERE Id NOT IN (SELECT OpportunityId FROM OpportunityContactRole)
     ORDER BY Name ASC     
 ];

 for (Opportunity opp1 : myOpps) {
     oppAccountIdSet.add(opp1.AccountId);
 }

// 2. Get all Contacts that aren't contact Roles, that share the same Account as Opportunities with no Contact Roles
List<Contact> myCons = [
    SELECT Id, Name, AccountId
    FROM Contact 
    WHERE AccountId IN :oppAccountIdSet
    AND Id NOT IN (SELECT ContactId FROM OpportunityContactRole)
    ORDER BY Name ASC
];

System.debug('***** DEBUG: Contacts with same Account: ' + myCons);

if (!myOpps.isEmpty() && !myCons.isEmpty()) {
// 3. Lopp through Opportunities with no contact roles, store opp Id and account Id in a map
    for (Opportunity myOpp : myOpps) {
        if (myOpp.AccountId != null && myOpp.Id != null) {
            oppIdToAccIdMap.put(myOpp.Id, myOpp.AccountId);
        }
    }
    System.debug('***** DEBUG: Opportunity Id to Account Id: ' + oppIdToAccIdMap);

    // 4. Lopp through Contacts with no contact roles, store contact Id and Account Id in a map
    for (Contact myCon : myCons) {
        if (myCon.AccountId != null && myCon.Id != null) {
            conIdToAccIdMap.put(myCon.Id, myCon.AccountId);
        }
    }
    System.debug('***** DEBUG: Contact Id to Account Id: ' + conIdToAccIdMap);


    // Need to Create a new Opportunity Contact Role for each Opportunity, using Opportunity Id and Contact Id that share the same Account
    // If Account has more than one Contact, both contacts should be contact roles of the Account's Opportunity
    // If Account has more than one Opportunity, both Opportunities should have the Account's contact(s) as their contact roles

}
 

 

I have a standard pre-chat form for Salesforce Embedded Chat that I would like to add some introductory title text to. I know this can be done by changing the pre-chat form to a custom lightning component, but for the sake of simplicity, I'd like to avoid resulting to a custom lightning component if possible.

Here's a screenshot of the text I would like to add to the form, before the fields. Currently, I am using an image for this, the text you see on the blue background is actually an image. 

Screenshot: https://prnt.sc/ss0bcj

 

 

I have an interesting use case. We are using Salesforce's Embedded Chat service, but it needs to also be able to open by the click of a button located somewhere on the page.

This means it opens in two ways:

1. The standard way (clicking the embedded chat in the bottom right of the screen)

2. A separate button on the page that should open that same embedded chat

 

I already know that using Chat Buttons and Embedded Chat on the same page is not compatible with Salesforce. However, is it possible to lauch the Embedded Chat with a button click? Essentially, we just need two ways to launch the embedded chat: button click on page, and standard way

Does anyone know if this is possible, and if so, how to enable it? Right now it appears you can either select an avatar image for all agents, or you just get the letter of the agent's name.

I have Leads converting without the Notes & Attachments being moved over to the new Opportunity, Contact, and Account records. I can see the attachment remains on the Lead record when I query the Attachments object and look at the ParentId. Does anyone know if it's possible to move an attachment on a converted Lead to it's new Opportunity, Contact, and Account records? Or more importantly, why would this not be happening in the first place?

 

Some more information about what is happening:

We use a HelloSign integration. When a customer signs a pdf, it comes back to Salesforce as "Signature Complete" which triggers a process in Process Builder that fires an invocable method that converts the Lead. That pdf does not appear on the newly created Opportunity, Contact, or Account records. Yet it appears to be on the converted Lead record instead.

 

Any help would be greatly appreciated!

 

Here's the code for the auto conversion invocable method if it's helpful:

public without sharing class AutoConvertLeads {
    @InvocableMethod(label='Convert Pre-Qual Leads' description='Converts Leads with Pre-Qualification Signature Request | Keeps running user as the owner of new Opportunity, Contact, and Account | Updates converted Opportunity status to Application In' category='Lead')
    public static void convertLeads(List<Id> leadIds) {
        LeadStatus conLeadStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
        List<Database.LeadConvert> massLeadConvertList = new List<Database.LeadConvert>();
        Id currentUserId               = UserInfo.getUserId();
        String currentUserName         = UserInfo.getName();
        Set<Id> leadIdsSet             = new Set<Id>();
        Set<Id> convOppIds             = new Set<Id>();
        List<Opportunity> oppsToUpdate = new List<Opportunity>();
        String preQualTemplate         = '[V.2] Pre-Qualification'; // name of template to run the trigger
        System.debug('***** DEBUG FIRST | AutoConvertLeads | User Id who auto converted the Lead: ' + currentUserId + 
        ' and Name: ' + currentUserName);

        // Get only the leads that have '[V.2] Pre-Qualification' signature request template
        for (HelloSign__HelloSign_Signature_Request__c signRequest : [SELECT Id, HelloSign__Template__r.Name, HelloSign__Lead__c FROM HelloSign__HelloSign_Signature_Request__c WHERE HelloSign__Lead__c IN :leadIds]) {
            if (signRequest.HelloSign__Template__r.Name == preQualTemplate) {
                leadIdsSet.add(signRequest.HelloSign__Lead__c);
            }
        }

        // Begin Converting Leads
        if (!leadIds.isEmpty() && !leadIdsSet.isEmpty()) {
            for (Id currentlead : leadIdsSet) {
                    Database.LeadConvert leadConvert = new Database.LeadConvert();
                    leadConvert.setLeadId(currentlead);                
                    leadConvert.setConvertedStatus(conLeadStatus.MasterLabel);
                    leadConvert.setOwnerId(currentUserId);
                    massLeadConvertList.add(leadConvert);
            } // end leadIdsSet loop
            
            if (!massLeadConvertList.isEmpty()) {
                List<Database.LeadConvertResult> lcrs = Database.convertLead(massLeadConvertList);
                for (Database.LeadConvertResult lcr : lcrs) {
                    System.debug('***** DEBUG 2 | AutoConvertLeads | Was lead conversion successfull? ' + lcr.isSuccess());
                    convOppIds.add(lcr.getOpportunityId());
                }
                System.debug('***** DEBUG 3 | AutoConvertLeads | Is ConvOppIds set empty? ' + convOppIds.isEmpty());
                if (lcrs.get(0).isSuccess() && !convOppIds.isEmpty()) {
                    // change Opportunity stage to 'Application Sent'
                    List<Opportunity> convertedOpps = [
                        SELECT Id, StageName, OwnerId, Owner.Name
                          FROM Opportunity
                         WHERE StageName != 'Application In'
                           AND Id IN :convOppIds

                    ];
                    System.debug('***** DEBUG 4 | AutoConvertLeads | Is convertedOpps list empty? ' + convertedOpps.isEmpty());
                    if (!convertedOpps.isEmpty()) {
                        for (Opportunity convertedOpp : convertedOpps) {
                            convertedOpp.StageName = 'Application In';
                            System.debug('***** DEBUG 5 | AutoConvertLeads | Converted Opportunity Stage: ' + convertedOpp.StageName);
                            System.debug('***** DEBUG FINAL | AutoConvertLeads | Owner of Converted Opp: ' + convertedOpp.OwnerId);
                            oppsToUpdate.add(convertedOpp);
                        }
                        if (!oppsToUpdate.isEmpty()) {
                            update oppsToUpdate;
                        } // end oppsToUpdate null check
                    } // end convertedOpps null check
                } // end lcrs and convOppIds null check
            } // end massLeadConvertList null check       
        } // end leadIds null check
    } // end leadAssign method
} // end AutoConvertLeads class

Does anyone know why my invocable method is not appearing in my Process Builder's list of Apex Classes?

 

Some extra info: I also have a test class with 100% code coverage as well. Any help is greatly appreciated.

 

Here's my class with the invocable method :

 

public class ContactFunnelToSQL {
    @InvocableMethod(label='Contact Funnel to SQL' description='Updates the Funnel to SQL for Opportunity Contact Roles')
    public static void oppContactsToSql(List<Opportunity> myOppsToUpdate) {
      
        List<Opportunity> myOpps = [
            SELECT Id
              FROM Opportunity 
             WHERE Id IN :new Map<Id, Opportunity>(myOppsToUpdate).keySet()
        ];

        Set<Id> oppIds = new Set<Id>();
            
        // Add Opportunity Ids to a set for querying later
        for (Opportunity opp : myOpps){
            if (opp.Id != null) {
                oppIds.add(opp.Id);
            }
        }

        if (oppIds.size() > 0) {    
            // Get the Contact Ids from the Opportunity Contact Roles
            List <OpportunityContactRole> ocrs = [
                SELECT ContactId
                  FROM OpportunityContactRole
                 WHERE OpportunityId IN :oppIds
            ];
            
            if(ocrs.size() > 0) {       
                
                Set<Id> contactIds = new Set<Id>();

                // Add the Contact Ids to a set for querying later
                for (OpportunityContactRole ocr : ocrs) {
                    if (ocr.ContactId != null && !contactIds.contains(ocr.ContactId)) {
                        contactIds.add(ocr.ContactId); 
                    }
                }

                // Get the Opps' Contacts that are not already in SQL, Won, or Disqualified
                List<Contact> oppContacts = [
                    SELECT Id, Funnel__c, Funnel_Status__c, SQL_Reached__c
                      FROM Contact
                     WHERE Id IN :contactIds 
                       AND Funnel__c != 'SQL'
                       AND Funnel__c != 'Won'
                       AND Funnel__c != 'Disqualified'
                ];

                if (oppContacts.size() > 0) {
                    List<Contact> contactsToUpdate = new List<Contact>();

                    // Set the Contacts' funnels to SQL
                    for (Contact oppCon : oppContacts) {
                        oppCon.Funnel__c      = 'SQL';
                        oppCon.SQL_Reached__c = true;
                        contactsToUpdate.add(oppCon);
                    }

                    if (contactsToUpdate.size() > 0) {
                        update contactsToUpdate;
                    }
                }
            }
        }
    }
}
I'm trying to come up with a SOQL query that displays the following:


Account Name | Opportunity Closed Date (most recent, won) | Product Purchased | Opportunity Amount

So far I've only been able to get as far as this:
 
SELECT Account.Name, CloseDate, Amount, (SELECT Product2.Name FROM OpportunityLineItems) FROM Opportunity WHERE IsClosed = true AND StageName = 'Closed Won'

 


If this is not possible with SOQL, is it possible with Salesforce Reports? Thank you!

I have a Campaign called "My Campaign" where I can see the "Opportunities in Campaign" field. It has a value of 41. However, when I try to query a list of these Opportunities with the following query (see below) I get 0 records found. Does anyone how I can query these Opportunities?

What I'm ultimately trying to do is create a field on the Campaign (using a trigger) that shows how many Opportunities are in a particular stage. So, I'd like to know how to query and filter these Opportunities that make up this count.

SOQL query that returned 0 records:

SELECT Id, Campaign.Name
   FROM Opportunity
WHERE Campaign.Name = 'My Campaign'

I have a custom "Create Project" button for my Opportunity page that lets Users create a Project record directly from the Opportunity.

In the predefined fields, I have a look up field called PO Number that gets defined by the Opportunity's PO Number realted record. However, when I click on "Create Project", the field does not get populated. In the end after saving, a new Project gets created with no PO Number record.

How can I get this predefined field to populate? Why is not working? Here are some screenshots to show you what's happening:

Create Project button
PO Number look up field not populating
User-added image
User-added image

I have a trigger that runs after a PO Number record is created. It finds the record's related Opportunity and updates the PO Number lookup field on the Opportunity with the PO Number that fired the trigger. 

 

Everything works fine except that it's not bulkified. SOQL and DML in a for loop. I'm having difficulty understanding how to bulkify something like this. I know collections are needed but I'm not sure how to use them correctly.

 

Can anyone please help me understand a step by step process of how to bulkify something like this trigger? Any help is greatly appreciated.

 

trigger updateOppPoNumber on PO_Number__c (after insert) {
    for (PO_Number__c poNum : Trigger.new) {
        if (poNum.Id != null && poNum.Opportunity__c != null) {
            // Get related Opportunity
            List<Opportunity> opp = [
                SELECT Id, PO_Number__c
                  FROM Opportunity
                 WHERE Id = :poNum.Opportunity__c
                 LIMIT 1
            ];

            // Update related Opportunity with PO Number
            if (!opp.isEmpty()) {
                opp.get(0).PO_Number__c = poNum.Id;
                update opp;
            }
        }
    }
}

I have a simple rigger that automatically creates a custom PO_Number__c record when an Opportunity is created. This PO_Number__c an Account__c lookup field and an Opportunity__c lookup field that also gets automatically populated by the trigger.

 

In my test class, my first test method singleOpp() succeeds, but I want to test a situation where a builk insert of Opportunities happens. My second test method is bulkOpps(). I'm not sure how to finish this method off to make sure that all the PO_Number__c records that were automatically created have the correct Account__c and Opportunity__c fields.

 

Any help would be greatly appreciated! Here's my code:

 

TRIGGER:
 

trigger createPurchaseOrder on Opportunity (after insert) {
    // Initialize PO Numbers to insert list
    List<PO_Number__c> ponsToInsertList = new List<PO_Number__c>();

    for (Opportunity opp : Trigger.new) {
        if (opp.Id != null && AccountId != null) {
            // Create PO Number records
            PO_Number__c pon   = new PO_Number__c();
            pon.Account__c     = opp.AccountId;
            pon.Opportunity__c = opp.Id;
            ponsToInsertList.add(pon);
        }
        if (!ponsToInsertList.isEmpty()) {
            // Insert PO Number records 
            insert ponsToInsertList;
        }
    }
}


TEST CLASS:
 
@isTest
private class CreatePurchaseOrderTest {
    @isTest static void singleOpp() {
        // Create Account
        Account acc = new Account();
        acc.Name    = 'Test Account';
        insert acc;

        // Create Opportunity
        Opportunity opp = new Opportunity();
        opp.Name        = 'Test Opp';
        opp.CloseDate   = Date.today();
        opp.StageName   = 'Initial Contact';
        opp.AccountId   = acc.Id;
        insert opp;

        // get opp
        List<Opportunity> updatedOpp = [
            SELECT Id, AccountId
              FROM Opportunity
             WHERE Id = :opp.Id
             LIMIT 1
        ];

        // check for PO Number record
        List<PO_Number__c> pon = [
            SELECT Id, Opportunity__c, Account__c
              FROM PO_Number__c
             LIMIT 1
        ];

        System.assertEquals(1, pon.size(), 'pon list size not correct');
        System.assertEquals(updatedOpp.get(0).Id, pon.get(0).Opportunity__c, 'Opportunity on PO Number not correct');
        System.assertEquals(updatedOpp.get(0).AccountId, pon.get(0).Account__c, 'Account on PO Number not correct');
    }

    @isTest static void bulkOpps() {
        // Create multiple Accounts
        List<Account> accList = new List<Account>();
        for (Integer i = 0; i < 500; i++) {
        Account myAcc = new Account();
        myAcc.Name    = 'Test Acc ' + i;
        accList.add(myAcc);
        }
        insert accList;

        // Create multiple Opps
        List<Opportunity> oppList = new List<Opportunity>();
        for (Integer i = 0; i < 500; i++) {
        Opportunity myOpp = new Opportunity();
        myOpp.Name        = 'Test Opp ' + i;
        myOpp.StageName   = 'Initial Contact';
        myOpp.CloseDate   = Date.today();
        myOpp.AccountId   = accList.get(i).Id;
        oppList.add(myOpp);
        }
        insert oppList;

        // Check for PO Number records
        List<PO_Number__c> ponList = [
            SELECT Id, Account__c, Opportunity__c
              FROM PO_Number__c
        ];

        // HOW CAN I DETERMINE IF EACH PO NUMBER HAS THE CORRECT OPPORTUNITY AND ACCOUNT ?????
        // EX: PO Number 1 has Account 1 and Opportunity 1 on it's Account__c and Opportunity__c fields
        // EX: PO Number 1 had Account 2 and Opportunity 2 on it's Account__c and Opportunity__c fields

        System.assertEquals(accList.get(0).Id, ponList.get(0).Account__c, 'Account not correct on PO Number');
        System.assertEquals(oppList.get(0).Id, ponList.get(0).Opportunity__c, 'Opportunity not correct on PO Number');
    }
}

 
I am using Email Services and I'm trying to extract field values (First Name, Last Name, Email, Phone, etc.) from the body of the email. Both the sender address and the subject do not contain the information I need.


In my class, I was able to isolate the the text of the email by using the following: 
String emailText = email.plainTextBody;


But I am struggling using String methods to isolate and get the field values from the text. 


Here's an example of the text I have to work with from the body of the email:

"
Requested by: John Doe
johndoe@example.com
Phone: 5555555555
Address of site: 123 Main St, Anywhere CA 12345
Electric Spend: 100 per month
Utility Company: PacifiCorp
Additional information: System Size (Kw): 7.76
Roof Type: Shingles
Roof Pitch: Slight
Shading: Shaded (can improve)
Credit Score: Over 680 Estimate
"
 

Any help is greatly appreciated! Thank you!

I receive certain email that I always have to manually create leads from. These emails contain certain text in their subject line that helps to uniquely identify them.

 

For example, lets say every email I receive that contains "Test 1" or "Example 1" should be automatically turned into a lead.

 

Does anyone know how to go about this?

I have a custom field called "Consultant" on my Opportunity. I need the BCC email address to automatically equal the Consultant's email address by default. 

Does anyone know how I can accomplish this? Any help is greatly appreciated.
I had to adjust a formula for one of my formula fields. However, I also have a field that is set to match the value of the formula field. The field is set via process builder.
 
After I updated the formula, the second field only updates after an update. (Edit => Save)
 
Is there any way I can perform this action (Edit => Save) on all Opportunities at once?

I need some help with how to approach the following tasks.

1. I need to perform a one time mass update that will change all account and contact owners to match the owner of the opportunities they are related to. 

2. (after the one time mass update is finished) when opp owner is updated also updated related contact and account owner to the new owner

I'm not really sure how to approach these in the most efficient way and safest way. I'm thinking an Apex trigger but would need some guidance with the code. Any help is greatly appreciated. Thank you!

I have a custom checkbox field on Opportunity called “Same as Mailing Address?” that pulls the Accounts mailing address information (all custom fields) to the Opportunity’s custom “Project Address” fields when the user checks it. The issue I have is as follows:

1. The user tries to edit any of the Project Address, they should get a warning telling them that they must uncheck the “Same as Mailing Address?” checkbox before they can edit. I have been able to do this with validation rule BUT:


*** I also want the user to be able to reset the Project address to the Account mailing address by rechecking the checkbox if they want. The problem I’m having is that the validation rule also fires if the user tries to reset the Project Address details by rechecking the box because the box is checked and the address is being edited.

For Example:
1. User checks the “Same as Mailing Address?” box.

2. Project address custom fields are automatically mapped over after Save (via process builder).
2. User tries to edit the Project Address without unchecking the box: validation rule should fire telling them to uncheck the box first.
3. If a user unchecks the box, then edits the address, saves. And later decides to reset Project Address by rechecking the box, this needs to be successful. (right now my validation rule fires again because the address is trying to be changed with the box checked).


Does anyone know how I can get this to work?


Here’s my current validation rule:
Same_as_Mailing_Address__c = True &&
 (
    ISCHANGED(Project_Address__c) ||
    ISCHANGED(Project_City__c)  ||
    ISCHANGED(Project_State__c) ||
    ISCHANGED(Project_Zip_Code__c)
)

 

I trying to create an Opportunity trigger that sets the name of a new Opportunity to "AccountName - AccountCity, AccountState" for example ("Test Corp. - San Franciso, CA").

What's difficult is that I have a custom checkbox field on the Opportunity named "Same as Mailing Address?". When this checkbox is checked, it sets the custom Opportunity address fields "Project Address", "Project City", "Project State" and "Project Zip Code" to the Account's custom fields "Mailing Address", "Mailing City", "Mailing State", "Mailing Zip Code" via process builder. But the Opportunity name doesn't update right away.

The goal is to have the user create an Opportunity, check the box, hit Save, and then The opportunity name is automatically displayed correctly.

However, what happens is that only the Account name shows up as the Opportunity name while the Project Address fields are correctly filled out. Then after one edit of any kind, the name changes to the correct format. 

I want it to show the correct naming convention after the user hits Save for the first time.

Screenshots of Opportunity create screen:

User-added image
After Save, this is what displays in the Opportunity record:

User-added image

Then after any update, it changes to the correct name:

User-added image
 

Here's my trigger I'm working on that doesn't work.

trigger NameOpportunity on Opportunity (before insert) {
     Set<Id> AccountIds = new Set<Id>(); // Initialize a list of Ids
     String accName; // Initialize account name variable
     String newOppName; // Initialize final opportunity name variable

    // Add an account ID to the list for every opportunity caught by trigger
    for (Opportunity op : Trigger.new) {
      AccountIds.add(op.AccountId);
    }

    // Create a map of Ids and account, querying the name from account records whose Id is in the AccountIds list generated earlier
    Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Name FROM Account WHERE Id IN :AccountIds]);
    System.debug(accountMap);

    // Update the Opportunity name for every opportunity entering the trigger that has and Account, and "Same as Mailing Address" checked
    for (Opportunity myOpp : Trigger.new) {
            if (myOpp.AccountId != null && myOpp.Same_as_Mailing_Address__c == true) {
                accName = accountMap.get(myOpp.AccountId).Name;
                // set naming conventions
                newOppName = accountMap.get(myOpp.AccountId).Name + ' - ' + myOpp.Project_City__c + ', ' + myOpp.Project_State__c;
                myOpp.Name = newOppName;
            }
        }
}

Any help is greatly appreciated thank you!

I am getting an error when I run CLI commands after creating a project: Cannot read property 'getInstance' of undefined

 

I am suddenly unable to do any CLI commands with both existing and new projects. The only thing I can do is create the initial project. Everything else gives me this error.

 

Here's the error in the console:

 

console.ts:137 [Extension Host] {
"status": 1,
"name": "TypeError",
"message": "Cannot read property 'getInstance' of undefined",
"exitCode": 1,
"commandName": "ConfigGetCommand",
"stack": "TypeError: Cannot read property 'getInstance' of undefined\n at ConfigGetCommand.hooksFromLifecycleEvent (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:401:44)\n at ConfigGetCommand.init (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:248:20)\n at async ConfigGetCommand._run (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:92:13)\n at async Config.runCommand (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/config/lib/config.js:172:9)\n at async Main.run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/command/lib/main.js:22:9)\n at async Main._run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/command/lib/command.js:43:20)\n at async Object.run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/dist/cli.js:32:20)\nOuter stack:\n at Function.wrap (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/core/lib/sfdxError.js:151:27)\n at ConfigGetCommand.catch (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/dist/ToolbeltCommand.js:247:46)\n at async ConfigGetCommand._run (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:97:13)\n at async Config.runCommand (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/config/lib/config.js:172:9)\n at async Main.run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/command/lib/main.js:22:9)\n at async Main._run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/command/lib/command.js:43:20)\n at async Object.run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/dist/cli.js:32:20)",
"warnings": []
}

 

Does anyone know how I can fix this?

I am trying to create a package version of a project. The Test class of this project references some required fields in the particular org I am working in, but those fields are not a part of my actual package. In addition, RecordTypeId field is referenced in some validation rules that are a part of this package. 

 

I am getting the following error when running sfdx force:package:create https://prnt.sc/tumblg  (https://prnt.sc/tumblg)

 

Does anyone know how I can create a package version in a situation like this?

I have an interesting use case. We are using Salesforce's Embedded Chat service, but it needs to also be able to open by the click of a button located somewhere on the page.

This means it opens in two ways:

1. The standard way (clicking the embedded chat in the bottom right of the screen)

2. A separate button on the page that should open that same embedded chat

 

I already know that using Chat Buttons and Embedded Chat on the same page is not compatible with Salesforce. However, is it possible to lauch the Embedded Chat with a button click? Essentially, we just need two ways to launch the embedded chat: button click on page, and standard way

Hi Team,

Iam having a query in Account 'SELECT Id,Name FROM Account WHERE Name LIKE 'Fireeye%'' and this one we converted into process builder formula as 

AND(
NOT(ISBLANK([Case].AccountId )),
NOT(BEGINS([Case].Account.Name, "FireEye"))

another condtion is 
NOT(CONTAINS([Case].Contact.Email, 'FireEye')

But i want to ignore case in my process builder formula as it is validating only 'FireEye' records but i want to validate irrespective of lower/upper/mixed . I want my formula work as Like funtion in Query.


This is urgent change pls help.

Regards,
ISHA
I'm trying to query using a relationship between orders and opportunities.
I'm using opps to creat a job workflow to my agents and using orders to store my e-commerce data. I want to know how many opps become an order and know the conversion rate for that. 
I'm using this SOQL query, but i'm doing something wrong.
SELECT
  Name, Profession__c,
  (SELECT
    LastModifiedDate, CreatedDate, StageName
   FROM 
   Opportunity__r),
   (SELECT
     Date_Payment__c, Discount__c, Status, Final_Amount__c, Amount__c
    FROM
     Order__r)
FROM
  Account 
WHERE
  IsPersonAccount = true

 
I have a new trigger that creates a custom object record when an opportunity is created or updated.

Everything works but I need help with one thing. I only want it to run when a specific opportunity type is created or when that type has its "cloe date" field updated.

Here is my code:
trigger createOq on Opportunity (after insert, after update) {

    List <Open_Quarter__c> createOpenQuarter = new List <Open_Quarter__c> (); 
     for(Opportunity opportunityList : trigger.New){
        
       Open_Quarter__c oq = new Open_Quarter__C();

        oq.Amount_Per_Quarter_oq__c = opportunityList.Amount_per_Quarter_op__c; 
        oq.Close_Date_oq__c = opportunityList.CloseDate;
        oq.Name = opportunityList.Quarter_Created_op__c;
        oq.Opportunity_Name_oq__c = opportunityList.Id;
        oq.Quarters_Spanned_oq__c = opportunityList.Quarters_Spanned_op__c;
        
         createOpenQuarter.add(oq);

     }
 
    try {
            insert createOpenQuarter;
    } 
    catch (system.Dmlexception e) {
        system.debug (e);
    }
}

How do I limit this so it only runs when a "Sales" opp is created or when an existing Sales Opp has the "Close Date" field updated?

New to coding and apex so any help is greatly appreciated.

Best regards,
Steve​​​​​​​
Can I use a workflow and field update to replace a null phone number field with N/A? Something like this? IF (ISBLANK ( Phone__c ),N/A, Phone__c 
A ton of leads are coming over blank and trying to find a way to make it easier to manage this field. 
Contact has a multi select custom field called Role__c which can have values (Surgeon;Nurse;First Assist;Admin;CSR). Account has a custom field called Total_Score__c which is a number field. Mapping table Role_Score__c looks like this Role__c Score__c
Surgeon 10
Nurse 5
First Assist 10
Admin 0
CSR 20
When a contact is created/updated, get total score of all the UNIQUE roles that exist on all the contacts of the account.
Ex: Account 1
Contact 1 with roles Surgeon;Admin
Contact 2 with roles CSR:Admin
On Account 1 we should store the value as (10 + 0 + 20 = 30) because we only have 3 unique roles.
Hello All, We have a custom field on a lead and a contact that is a checkbox. This checkbox is updated by Pardot. Pardot is checking the box and salesforce is unchecking the box. We have reviewed all Triggers, Workflows and Validation rules, none of them are tied to these custom fields. Have you see anything like this happen before with Pardot or checkbox fields?
 
Thank you!