• Mark Thomas 49
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
I needed to add a validation rule to opportunities to prevent a specific type of contact from being added to the opportunity upon lead conversion.
The validation rule works as expected, but I need help cleaing up the error message. Currently it looks like this.

Validation error on Lead: LeadTrigger: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0060d00001y6mn8AAA; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, ***SORRY. THE CONTACT YOU HAVE SELECTED IS INACTIVE IN JIVA. PLEASE SELECT A DIFFERENT CONTACT OR CREATE A NEW CONTACT***: [] Trigger.LeadTrigger: line 44, column 1

I really only need the text between the asterisks.

This is the lead conversion trigger:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
trigger LeadTrigger on Lead (after update, after insert) 
{

    //JWAHLERS/FF 12/22/2016
    //Added if after update  to existing logic:
    if(trigger.isUpdate)
    {
        //List<Lead> convertedLeadsToProcess = new List<Lead>();

        Map<Id, Id> oppIdToConIdMap = new Map<Id, Id>();

        for (Lead l : (List<Lead>)Trigger.new){

            if (((Lead)trigger.oldMap.get(l.Id)).isConverted == false && l.isConverted == true
                && l.ConvertedOpportunityId != null && l.ConvertedContactId != null)
            {
                //convertedLeadsToProcess.add(l);
                oppIdToConIdMap.put(l.ConvertedOpportunityId, l.ConvertedContactId);
            }
        }



        //JW@ff: query for opportunities in opptIdSet
        if(!oppIdToConIdMap.isEmpty())
        {
            List<Opportunity> oppList = [Select Id From Opportunity Where Id IN: oppIdToConIdMap.keySet()];

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

            for(Opportunity opp: oppList)
            {
                if(oppIdToConIdMap.containsKey(opp.Id))
                {
                    opp.Contact__c = oppIdToConIdMap.get(opp.Id);
                    updatedOppList.add(opp);
                }
            }



            if(!updatedOppList.isEmpty())
            {
                update updatedOppList;
            }
        }
    }



    //JWAHLERS/FF   12/22/2016
    //Call handler for inserts EAGSC2-51
    //DISABLED UNTIL DEVELOPMENT IS COMPLETE
    if(trigger.isInsert)
    {
        LeadTriggerHandler.handleAfterInsert(trigger.newMap);
    }





    /*if (convertedLeadsToProcess.size() > 0){

        Set<Id> OpptyIdSet = new Set<Id>();

        Set<Id> ContactIdSet = new Set<Id>();

        for(Lead l: convertedLeadsToProcess){

            OpptyIdSet.add(l.ConvertedOpportunityId);

            ContactIdSet.add(l.ConvertedContactId);

        }

        // Map<OpportunityId, Map<ContactId, OpportunityContactRole>>
        Map<Id, Map<Id, OpportunityContactRole>> oCRMap = new Map<Id, Map<Id, OpportunityContactRole>>();

        for(OpportunityContactRole oCR :[SELECT Id,IsPrimary,OpportunityId,ContactId FROM OpportunityContactRole WHERE OpportunityId IN :OpptyIdSet AND ContactId IN :ContactIdSet]){
                            
            if (oCR.IsPrimary == false){

                if(!oCRMap.containsKey(oCR.OpportunityId))
                {
                    oCRMap.put(oCR.OpportunityId, new Map<Id, OpportunityContactRole>());
                }                   

                oCRMap.get(oCR.OpportunityId).put(oCR.ContactId,oCR);
            }
        }

        Map<Id, Id> oppIdToConIdMap = new Map<Id, Id>();

        List<OpportunityContactRole> oCRToUpdate = new List<OpportunityContactRole>();

        for(Lead l: convertedLeadsToProcess){

            if (oCRMap.ContainsKey(l.ConvertedOpportunityId) && oCRMap.get(l.ConvertedOpportunityId).containsKey(l.ConvertedContactId)){

                OpportunityContactRole oCR = oCRMap.get(l.ConvertedOpportunityId).get(l.ConvertedContactId);

                oCR.IsPrimary = true;

                oCRToUpdate.add(oCR);

                //JW@ff generate map of opportunityId => contactId
                oppIdToConIdMap.put(oCR.OpportunityId, oCR.ContactId);

            }
        }

        if (oCRToUpdate.size() > 0){

            update oCRToUpdate;
        }
    }*/
}

Or do I need to update the Lead Trigger Class?

I'm getting the following error when I run a debug log on an update to an APEX Class, FATAL_ERROR|System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Account_Owner_For_Jiva__c
The field is a formula text field that brings in the account owners email address. We use this to pass the email to our external system. I added the field the existing APEX Class like this:

 //json container for Account
    private class AccountCompany{
        private Id SalesforceID; //required
        private String Name; //required
        private String AccountOwner; //required
        private String PrimaryCountry; //required
        //private String EAGRelationshipID;
        private String UnicodeName;
        private String IndustrySectorID;
        private String ManufacturingTypeID;
       

        public AccountCompany(Sobject record)
        {
            Account account = (Account)record;

            this.SalesforceID = account.Id;
            this.Name = account.Name;
            this.PrimaryCountry = account.Primary_Country__c;
            this.AccountOwner = account.Account_Owner_For_Jiva__c;
            //this.EAGRelationshipID = EAGRelationshipID; //no related field in salesforce
            this.UnicodeName = account.Account_Name_Unicode__c;
            this.IndustrySectorID = account.Industry_Sector_ID__c;
            this.ManufacturingTypeID = account.Manufacturing_Type_ID__c;
            
        }
    }


The updated Class saves with no errors, but was not communicating correctly which is when I ran the code debug log. I saw where I need to add it to the query, but I don't see anything else in the class that includes the existing fields.

 

We have an existing Apex Class that syncs information between Salesforce and our ERP system. We would like to start pulling the Account Owner from Salesforce. I'm getting an error when adding Account Owner to this string in the existing APEX class,    

this.SalesforceID = account.Id;
            this.Name = account.Name;
            this.PrimaryCountry = account.Primary_Country__c;
            //this.EAGRelationshipID = EAGRelationshipID; //no related field in salesforce
            this.UnicodeName = account.Account_Name_Unicode__c;
            this.IndustrySectorID = account.Industry_Sector_ID__c;
            this.ManufacturingTypeID   =account.Manufacturing_Type_ID__c;
            this.[Select Id, Name ,OwnerId from Account where id in : relatedAccountId]){
        }

Any thoughts about how I might structure this?
I recently took ownership of my companies Salesforce org. It was never set up with MyDomain, which I need to do prior to moving to Lightning. We have a Boomi connector that sends data from our internally bulid project management system to Salesforce. I'm not familiar with Boomi, but do know that our Boomi connector can only point to our production environment. I haven't been able to determine if we add My Domain to Salesforce, do we need to change the Boomi connection at the same time? 

I'm getting the following error when I run a debug log on an update to an APEX Class, FATAL_ERROR|System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Account_Owner_For_Jiva__c
The field is a formula text field that brings in the account owners email address. We use this to pass the email to our external system. I added the field the existing APEX Class like this:

 //json container for Account
    private class AccountCompany{
        private Id SalesforceID; //required
        private String Name; //required
        private String AccountOwner; //required
        private String PrimaryCountry; //required
        //private String EAGRelationshipID;
        private String UnicodeName;
        private String IndustrySectorID;
        private String ManufacturingTypeID;
       

        public AccountCompany(Sobject record)
        {
            Account account = (Account)record;

            this.SalesforceID = account.Id;
            this.Name = account.Name;
            this.PrimaryCountry = account.Primary_Country__c;
            this.AccountOwner = account.Account_Owner_For_Jiva__c;
            //this.EAGRelationshipID = EAGRelationshipID; //no related field in salesforce
            this.UnicodeName = account.Account_Name_Unicode__c;
            this.IndustrySectorID = account.Industry_Sector_ID__c;
            this.ManufacturingTypeID = account.Manufacturing_Type_ID__c;
            
        }
    }


The updated Class saves with no errors, but was not communicating correctly which is when I ran the code debug log. I saw where I need to add it to the query, but I don't see anything else in the class that includes the existing fields.

 

We have an existing Apex Class that syncs information between Salesforce and our ERP system. We would like to start pulling the Account Owner from Salesforce. I'm getting an error when adding Account Owner to this string in the existing APEX class,    

this.SalesforceID = account.Id;
            this.Name = account.Name;
            this.PrimaryCountry = account.Primary_Country__c;
            //this.EAGRelationshipID = EAGRelationshipID; //no related field in salesforce
            this.UnicodeName = account.Account_Name_Unicode__c;
            this.IndustrySectorID = account.Industry_Sector_ID__c;
            this.ManufacturingTypeID   =account.Manufacturing_Type_ID__c;
            this.[Select Id, Name ,OwnerId from Account where id in : relatedAccountId]){
        }

Any thoughts about how I might structure this?