• Travis Malle
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
I have a class that is called by a before trigger. The class is designed to loop through records and evaluate who it belongs to and the datetime. there are a few things happen with this logic that are outside of this post. I now have a need to present a user friendly error message if there are more than one record with the same owner and same datetime. I am able to successfully throw the error and prevent a save (exactly what I want). However, I would like a more user friendly error message. Here is a snip of how my error is triggered and the resulting message. Any way to clean this up??? Something more akin to validation message
 
else if(officer == prevOfficer && StartDate == prevDate){ 
                // same officer and exact same time (throw error)
                if(initialTime == prevDateTime){
                    throw new CustomException('Cannot have two events start at the same time');
                }
User-added image
 
Hello Community,
 
Looking for some assistance with loading test data via CSV files. I’m attempting to generate test data using the Test.LoadData method. In this circumstance, I’m loading, Users, Accounts and Campaigns. Users and Accounts load fine but when I attempt to load Campaign records, I get an error stating “Validation Errors While Saving Record(s)”. I have turned off all validation rules on the Campaign object and have taken my Campaign CSV data down to bare bones for experimentation purposes (inserting only one record with minimal fields).
 
The Campaign object has two Account lookup field and two user lookup fields. Although I have not been able to validate it, I’m thinking that the foreign id’s I’m using as references are only being considered directly after the insert. For example.
 
Step 1:
Load Users with numerically sequential ID’s i.e. 1,2,3,4,5,6. When loaded, the users are assigned actual 15 charter SF id’s .
 
Step 2:
Load Account data with numerically sequential ID’s i.e. 1,2,3,4,5,6. I also have a user lookup field that I have assigned via the foreign key (numerically sequential ID’s from step 1)
 
Step 3:
Load Campaign data and reference the users and Accounts via the assigned foreign id’s from step 1 & 2.
 
Step 3 will not work and throws a validation error described above. I am unable to get any further information from the logs and feel a bit stuck.
 
Anyone have an idea on the issue here?

Here is my code:
@isTest
public class TestUtilityClass {
    
    public static void CreateTestAccountsAndCampaigns() {
        list<SObject> dataList = new list<SObject>();
        dataList.addAll(Test.loadData(User.sObjectType,'TestData_User_MDO'));  
        dataList.addAll(Test.loadData(Account.sObjectType,'TestData_Accounts_Districts'));
        dataList.addAll(Test.loadData(Campaign.sObjectType,'TestData_Campaign_MD'));
    }        
}
 
@isTest
private class Test_OfficerStats_CampaignUpdate {
    
@testSetup static void setup() {
        id UserId = system.UserInfo.getUserId();
        user CurrentUser = [Select id from user where id = :UserId];
        
        system.runAs(currentUser){
            TestUtilityClass.CreateTestAccountsAndCampaigns();     
        }
        
    }
}
Here are my CSV files
User-added image
User-added image
User-added image

 
I have a class that is called by a before trigger. The class is designed to loop through records and evaluate who it belongs to and the datetime. there are a few things happen with this logic that are outside of this post. I now have a need to present a user friendly error message if there are more than one record with the same owner and same datetime. I am able to successfully throw the error and prevent a save (exactly what I want). However, I would like a more user friendly error message. Here is a snip of how my error is triggered and the resulting message. Any way to clean this up??? Something more akin to validation message
 
else if(officer == prevOfficer && StartDate == prevDate){ 
                // same officer and exact same time (throw error)
                if(initialTime == prevDateTime){
                    throw new CustomException('Cannot have two events start at the same time');
                }
User-added image
 
Hello Community,
 
Looking for some assistance with loading test data via CSV files. I’m attempting to generate test data using the Test.LoadData method. In this circumstance, I’m loading, Users, Accounts and Campaigns. Users and Accounts load fine but when I attempt to load Campaign records, I get an error stating “Validation Errors While Saving Record(s)”. I have turned off all validation rules on the Campaign object and have taken my Campaign CSV data down to bare bones for experimentation purposes (inserting only one record with minimal fields).
 
The Campaign object has two Account lookup field and two user lookup fields. Although I have not been able to validate it, I’m thinking that the foreign id’s I’m using as references are only being considered directly after the insert. For example.
 
Step 1:
Load Users with numerically sequential ID’s i.e. 1,2,3,4,5,6. When loaded, the users are assigned actual 15 charter SF id’s .
 
Step 2:
Load Account data with numerically sequential ID’s i.e. 1,2,3,4,5,6. I also have a user lookup field that I have assigned via the foreign key (numerically sequential ID’s from step 1)
 
Step 3:
Load Campaign data and reference the users and Accounts via the assigned foreign id’s from step 1 & 2.
 
Step 3 will not work and throws a validation error described above. I am unable to get any further information from the logs and feel a bit stuck.
 
Anyone have an idea on the issue here?

Here is my code:
@isTest
public class TestUtilityClass {
    
    public static void CreateTestAccountsAndCampaigns() {
        list<SObject> dataList = new list<SObject>();
        dataList.addAll(Test.loadData(User.sObjectType,'TestData_User_MDO'));  
        dataList.addAll(Test.loadData(Account.sObjectType,'TestData_Accounts_Districts'));
        dataList.addAll(Test.loadData(Campaign.sObjectType,'TestData_Campaign_MD'));
    }        
}
 
@isTest
private class Test_OfficerStats_CampaignUpdate {
    
@testSetup static void setup() {
        id UserId = system.UserInfo.getUserId();
        user CurrentUser = [Select id from user where id = :UserId];
        
        system.runAs(currentUser){
            TestUtilityClass.CreateTestAccountsAndCampaigns();     
        }
        
    }
}
Here are my CSV files
User-added image
User-added image
User-added image

 
I am trying to send $http request to salesforce for submitting a ticket.
I enabled in security setting cors while adding my site to the withlist.
The probelm is that i am still getting the famous error:
XMLHttpRequest cannot load https://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://mystie.com' is therefore not allowed access.

Code:
$http({
                method: 'POST',
                url: 'https://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8',
                headers: { 'Content-Type': 'application/json' },
                data: param2
            }).
Thanks in advance for your help.
Dan