• D J Roberts
  • NEWBIE
  • 20 Points
  • Member since 2019
  • Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 11
    Questions
  • 6
    Replies
Hey everyone, I have a summary report that I want to allow users to see the summary data, but not be able to see the detail data. Is there a way to modify permissions or profiles to prevent them from having access to the Toggle Details button on a report? 
Really odd thing happening here. 

1. We are trying to consume a HTTP Request from a vendor. They are sending a POST Request to an APEX method hosted on a Salesforce Site Page. The format they are sending it in is the following 
 
https://sandbox.mysalesforceinstance.force.com/mysite/services/apexrest/myapexClass?key1=value1&key2=value2&key3=value3
Here is the Apex for our class: 
 
@RestResource(urlMapping='/myapexClass/*')
global without sharing class myApexClass {


	@HttpPost
  	global static String myApexMethod() {

        // Code blocks for using data here. 

}
The issue is that when we have the above format, I can hit the class with Postman and works perfectly. However, if I provide the URL to our vendor they are getting a 200 response, but our method is not running. 

2. This is the weird part. If we add a random parameter so our code looks like this: 
 
@RestResource(urlMapping='/myapexClass/*')
global without sharing class myApexClass {


	@HttpPost
  	global static String myApexMethod( String RandomValue) {

        // Code blocks for using data here. 

}
Suddenly, we can see the endpoint we provdided the vendor receiving responses, but the method DOES NOT run. We can literally see all the values that are passed in the URL because the class is running but the Method is not. 

I have 2 questions: 

1. Is it possible to consume x-www-form-urlencoded POST requests in Salesforce? 

2. Why does the addition of a parameter make it possible for the endpoint, but the class runs and the method DOES NOT. 


If you can help me out, that would be incredible! 



 
I have a process builder that has very simpl logic that will update a field AND kick off a flow when the Process Builder criteria evals to true. 

The update of the record to true works, but it will not enter the flow. In other words, the logic is correct, but for some reason the record type will not get processed by the flow.

Anyone have an experience with this? 
I have a method that takes a phone number. For the purposes of this thread, I'll call mySOSLMethod(String phone); 
 It runs this code: 
mySOSLMethod(String phone){
List<List<SObject>> phoneRecords = [
FIND :phone IN PHONE FIELDS
RETURNING
Lead(Id, Name, WHERE IsConverted = false),
Contact(Id)
];
// More code follows here....

return phoneRecords;
}


When I try to run this manually, mySOSLMethod('+333222444') it runs successfully but returns an empty list. When I try to use the exact number off the lead record (i.e. '3332224444') the method fails to run and says: 
 
System.NullPointerException: Attempt to de-reference a null object
Any help would be greatly appreciated. Thanks, 
 
Trying to push an Application to a scratch org and I keep getting an error related to the logo missing. 


I have added the documents tag to the manifest and pulled in the logos from a sandbox. Then after specifying the logo image file in the metadata I get this error when trying to push... 

In field: logo - no ContentAsset named mylocation/myfilename.png found

Any help would be most appreciated... 
 
Hey guys, working on a project to deploy a large amount of Code to a scratch org for a project, but the code uses some fields that are also used by a managed package. When pushing the project to a scratchOrg, I'm getting some nasty errors, and the deployment is failing. Has anyone else dealt with this kind of issue? If so, what did you do to get the code into a scratch org and work on the modifications? 
Trying to check the query results in a Batch Class, but not sure what to call. The code is below. Any help would be great. Again, just trying to log the query result within a batch class. 
 
global class LeadProcessor implements Database.Batchable<sobject>, Database.Stateful  {
    global Database.QueryLocator start(Database.BatchableContext bc){
            String query = 'Select Id, LeadSource  FROM Lead WHERE LeadSource != \'DreamForce\'' ; 
             
            return Database.getQueryLocator(query); 
    }

    global void execute(Database.BatchableContext bc, List<Lead> records){
        System.debug('Query Results = ' + bc()); 
        // process each batch of records
    }        
        

    global void finish(Database.BatchableContext bc){
        // execute any post-processing operations
    }    

    
}

 
I'm looking over the batch apex for Trailhead, and I'm wondering about the Iterable parameter. In the Trailhead it says that simple SOQL queries in the batch start method can return upto 50million records; pretty cool. 

But the Iterable Batch process will revert to standard Salesforce governor limits. So my thought is create a custom object for staging of the records to be processed by the simple query, and have a scheduled APEX class that routinely runs on the target records, does the complex processing that an iterable batch would normally do, and then save them to the custom staging object to be batched up by a simpler SOQL query? 

Am I misunderstanding the Batch APEX and the Iterable parameter? 
Hey everyone, 

Trying to understand the concept of the TestDataFactory. It makes sense for the Creating of records, but do any of you include testmethods for updating a set of records? Second question, do you set the parameter seeAllData = true for the TestDataFactory?
Hey everyone, 

I'm creating a unit test for updating accounts with a total number of contacts, but I'm trying to do this from my Test Class, "TestDataFactory" (CodeSnippet below). The method that I wrote is called queryAccounts(Integer qLimit); 

When I execute the code in anonymously, it will return the expected result, but these values are not being returned to the test class when I call the TestDataFactory.queryAccounts(1); 

Any idea what the issue is? 
AccountProcessorTest() Code Snippet: 
@isTest
private class AccountProcessorTest {

    @isTest public static void singleAccountUpdate() {
      //Get test data for testing
      Test.startTest();
        Id[] acctIds = TestDataFactory.queryAccounts(1); 
        System.debug('Results = ' +TestDataFactory.queryAccounts(1)); 
      	List<Contact> cons = [SELECT Id, AccountId FROM Contact WHERE AccountId IN: acctIds];
        integer numOfContacts = cons.size();
        System.debug('acctIds = ' + acctIds.size()); 
       //test the update of the Contacts record count on Accounts.
        
        Account acctUpdate = new Account(Id = acctIds[0], Number_of_Contacts__c = numOfContacts); 
        update acctUpdate; 
        Test.StopTest(); 
    }
    
    @isTest static void multipleAccountUpdate(){
        //Test multiple accounts. 
    }
}



TestDataFactory() Code Snippet: 
 
@isTest
public class TestDataFactory {
    public static List<Account> createAccountsWithOpps (Integer numAccts, Integer numOppsPerAcct){
        List<Account> accts = new List<Account>(); 
        for(Integer i=0; i<numAccts;i++){
            
            Account a = new Account(Name = 'TestAccount' + i); //assigning incremental name
            accts.add(a); //Adds accounts to accts list. 
        }
        
        insert accts; 
        
        List<Opportunity> opps = new List<Opportunity>(); 
        for(Integer j = 0; j<numAccts; j++){
            Account acct = accts[j]; 
            for (Integer k=0; k<numOppsPerAcct; k++){
            opps.add(new Opportunity(Name = acct.Name + 'Opportunity ' + k, 
                                           StageName = 'Prospecting',
                                           CloseDate=System.today().addMonths(1),
                                           AccountId=acct.Id));
            }
            
           }
        insert opps; 
        return accts; 
    } 
    public static List<Id> queryAccounts(Integer qLimit){
     List<Id> acctIds = new List<Id>(); 
     List<Account> accts = ([SELECT Id FROM Account LIMIT: qLimit]);   
        for(Account a : accts ){
            system.Debug('The ID is added  '+ a.Id );
            acctIds.add(a.Id);
        }
        system.debug('qLimit = ' + qLimit); 
        return acctIds;
    }
}

 
I have a method called getAccountIds, that is successfully returning a set of Account Ids. I second method that is countContacts(List<Id>acctIds). But when I return the acctIds, it doesn't get added picked up by the second method.
I'm calling the class from an execute anonymous window like this --> 
AccountProcessor.getAccountIds(); 
AccountProcessor.countContacts();



Actual Class and methods. 
 
public class AccountProcessor {
    
    public static List<Id> getAccountIds(){
        List<Id> acctIds = new List<Id>(); 
        For(Account a:[SELECT Id FROM Account LIMIT 200] ){
            acctIds.add(a.Id);
        }
        System.debug('The list of Ids = ' + acctIds); 
        System.debug('The size of List = ' +acctIds.size());
        return acctIds; 
        
    }
   
    
    @future
  
    
    public static void  countContacts(List<Id> acctIds){
       	//Declare Variables.
       	Account accountToUpdate; 
        List<Account> accountsToUpdate = new List<Account>(); 
       	Integer totalContacts = 0; 
        System.debug('Size of List =' + acctIds.size());
        List<Contact> cons = [SELECT Id, AccountId FROM Contact WHERE AccountId IN: acctIds]; 
        System.Debug('Contact List = ' + cons.size()); 
		
        //Loop through the contacts and sum the account Id for each contact. 
        for( Id a : acctIds){
            
            System.Debug('Account Ids on Contact = ' + a); 
          	Contact[] contactIdArray = new List<Contact>();  
                   for(Contact c : cons){
                      // System.debug('Enter Contact Loop ');
                      // System.Debug('Account Id = ' + a);
                       Boolean resultType = a.equals(c.AccountId);
                       //System.Debug('ResultType is ? ' + resultType); 
                        
                      	If(a==c.AccountId){
                             contactIdArray.add(c);
                          	
                       		}
                       
					
	        }
             
             
             accountToUpdate = [SELECT Id FROM Account WHERE Id =: a LIMIT 1]; 
             totalContacts = contactIdArray.size();
             accountToUpdate.Number_of_Contacts__c = totalContacts; 
             accountsToUpdate.add(accountToUpdate); 
             System.debug('Total Contacts = ' + totalContacts);
             System.debug('Total Update Accounts = ' + accountsToUpdate.size());
            
        }
       update accountsToUpdate; 
        
    }
	 	
}

 
Trying to push an Application to a scratch org and I keep getting an error related to the logo missing. 


I have added the documents tag to the manifest and pulled in the logos from a sandbox. Then after specifying the logo image file in the metadata I get this error when trying to push... 

In field: logo - no ContentAsset named mylocation/myfilename.png found

Any help would be most appreciated... 
 
Hey everyone, 

I'm creating a unit test for updating accounts with a total number of contacts, but I'm trying to do this from my Test Class, "TestDataFactory" (CodeSnippet below). The method that I wrote is called queryAccounts(Integer qLimit); 

When I execute the code in anonymously, it will return the expected result, but these values are not being returned to the test class when I call the TestDataFactory.queryAccounts(1); 

Any idea what the issue is? 
AccountProcessorTest() Code Snippet: 
@isTest
private class AccountProcessorTest {

    @isTest public static void singleAccountUpdate() {
      //Get test data for testing
      Test.startTest();
        Id[] acctIds = TestDataFactory.queryAccounts(1); 
        System.debug('Results = ' +TestDataFactory.queryAccounts(1)); 
      	List<Contact> cons = [SELECT Id, AccountId FROM Contact WHERE AccountId IN: acctIds];
        integer numOfContacts = cons.size();
        System.debug('acctIds = ' + acctIds.size()); 
       //test the update of the Contacts record count on Accounts.
        
        Account acctUpdate = new Account(Id = acctIds[0], Number_of_Contacts__c = numOfContacts); 
        update acctUpdate; 
        Test.StopTest(); 
    }
    
    @isTest static void multipleAccountUpdate(){
        //Test multiple accounts. 
    }
}



TestDataFactory() Code Snippet: 
 
@isTest
public class TestDataFactory {
    public static List<Account> createAccountsWithOpps (Integer numAccts, Integer numOppsPerAcct){
        List<Account> accts = new List<Account>(); 
        for(Integer i=0; i<numAccts;i++){
            
            Account a = new Account(Name = 'TestAccount' + i); //assigning incremental name
            accts.add(a); //Adds accounts to accts list. 
        }
        
        insert accts; 
        
        List<Opportunity> opps = new List<Opportunity>(); 
        for(Integer j = 0; j<numAccts; j++){
            Account acct = accts[j]; 
            for (Integer k=0; k<numOppsPerAcct; k++){
            opps.add(new Opportunity(Name = acct.Name + 'Opportunity ' + k, 
                                           StageName = 'Prospecting',
                                           CloseDate=System.today().addMonths(1),
                                           AccountId=acct.Id));
            }
            
           }
        insert opps; 
        return accts; 
    } 
    public static List<Id> queryAccounts(Integer qLimit){
     List<Id> acctIds = new List<Id>(); 
     List<Account> accts = ([SELECT Id FROM Account LIMIT: qLimit]);   
        for(Account a : accts ){
            system.Debug('The ID is added  '+ a.Id );
            acctIds.add(a.Id);
        }
        system.debug('qLimit = ' + qLimit); 
        return acctIds;
    }
}

 
I have a method called getAccountIds, that is successfully returning a set of Account Ids. I second method that is countContacts(List<Id>acctIds). But when I return the acctIds, it doesn't get added picked up by the second method.
I'm calling the class from an execute anonymous window like this --> 
AccountProcessor.getAccountIds(); 
AccountProcessor.countContacts();



Actual Class and methods. 
 
public class AccountProcessor {
    
    public static List<Id> getAccountIds(){
        List<Id> acctIds = new List<Id>(); 
        For(Account a:[SELECT Id FROM Account LIMIT 200] ){
            acctIds.add(a.Id);
        }
        System.debug('The list of Ids = ' + acctIds); 
        System.debug('The size of List = ' +acctIds.size());
        return acctIds; 
        
    }
   
    
    @future
  
    
    public static void  countContacts(List<Id> acctIds){
       	//Declare Variables.
       	Account accountToUpdate; 
        List<Account> accountsToUpdate = new List<Account>(); 
       	Integer totalContacts = 0; 
        System.debug('Size of List =' + acctIds.size());
        List<Contact> cons = [SELECT Id, AccountId FROM Contact WHERE AccountId IN: acctIds]; 
        System.Debug('Contact List = ' + cons.size()); 
		
        //Loop through the contacts and sum the account Id for each contact. 
        for( Id a : acctIds){
            
            System.Debug('Account Ids on Contact = ' + a); 
          	Contact[] contactIdArray = new List<Contact>();  
                   for(Contact c : cons){
                      // System.debug('Enter Contact Loop ');
                      // System.Debug('Account Id = ' + a);
                       Boolean resultType = a.equals(c.AccountId);
                       //System.Debug('ResultType is ? ' + resultType); 
                        
                      	If(a==c.AccountId){
                             contactIdArray.add(c);
                          	
                       		}
                       
					
	        }
             
             
             accountToUpdate = [SELECT Id FROM Account WHERE Id =: a LIMIT 1]; 
             totalContacts = contactIdArray.size();
             accountToUpdate.Number_of_Contacts__c = totalContacts; 
             accountsToUpdate.add(accountToUpdate); 
             System.debug('Total Contacts = ' + totalContacts);
             System.debug('Total Update Accounts = ' + accountsToUpdate.size());
            
        }
       update accountsToUpdate; 
        
    }
	 	
}

 
Hello all, 
   Everytime we refresh a sanbbox, there are many little things that need to be done before we consider it "Ready" for development.  One of those things is to set the Email Deliverability settings to "All Email."  I have a wrote a script that automates all of the other little things and the last piece is to change the email deliverability settings.  I am not sure if that setting is available via the API and wanted to check to see if someone can either slap my hand for trying or point me in the right direction.

So just to recap, I want to set the  Email Deliverability Settings (http://help.salesforce.com/apex/HTViewHelpDoc?id=emailadmin_deliverability.htm) using Apex via an anonymous block in the dev console.