• Cameron Houser
  • NEWBIE
  • 10 Points
  • Member since 2017
  • Salesforce Consultant
  • Offprem Technologies

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 9
    Replies
I get the following error for only two user names. One is Active on is Inactive.
I have 30 ussers can test this mass transfere app on and only two of them threw up the error below.
 
core.apexpages.exceptions.ApexPagesHandledException: Object type not accessible. Please check permissions and make sure the object is not in development mode: and (CreatedDate > null) ^ ERROR at Row:3:Column:6 invalid operator. Original queryString was: 'SELECT name,StageName,Ownerid,CloseDate from Opportunity WHERE ( ((Owner.LastName = 'Chavarria') and ((StageName != 'No Sale') AND (StageName != 'Converted') AND (StageName != 'No Sale - Do Not Contact')) and (CreatedDate > null) and (CreatedDate < null)) ) ORDER BY Name ASC LIMIT 10000'
How to build an XML file fior Twilio through a URL in a formula field:

Use Case: 
You need to build a dynamic text-to-voice concatinated with different audio urls (audion hosted on a website). To accomplish this you need to dynamically build a XML url in a formlua field with audio or voice to text.
  •  What I did was anaylize how Twilio was doing with thier Twimlets https://www.twilio.com/labs/twimlets
  • Create field for voice-to-text message (will represent Say)
  • Create field for audio url (will represent Play)
Key factors to consider in your formula
  • No blank spaces alowed in the url 
    • Use %20 to represent a blank space
  • audio urls always are treated as "Play"
  • Message%5B0%5D=[text or url here] is template for seperating the text and audio urls (more on this later)
  • text is always treated as "Say"
  • %3A = :
  • %2F = /
Example Working Formula:
'http://twimlets.com/message?Message%5B0%5D='&SUBSTITUTE(Subject, " ", ",%20")&'.%20'&Contact.LastName&'.&Message%5B1%5D='&SUBSTITUTE(SUBSTITUTE(Url__c,':', '%3A'),'/', '%2F')&'&Message%5B2%5D=%20'&Id&'&'
Formula result:
http://twimlets.com/message?Message%5B0%5D=Thanks,%20for,%20checking,%20this,%20out.%20Houser.&Message%5B1%5D=https%3A%2F%2Fpink-dog-6501.twil.io%2Fassets%2FSampleAudio_0.4mb.mp3&Message%5B2%5D=%205001I000004ffiT&
XML created:
<Response>
<Say>Thanks, for, checking, this, out. Houser.</Say>
<Play>
https://pink-dog-6501.twil.io/assets/SampleAudio_0.4mb.mp3
</Play>
<Say>5001I000004ffiT</Say>
</Response>

What this formula does:
  • 'http://twimlets.com/message?Message%5B0%5D='&SUBSTITUTE(Subject, " ", ",%20")&
    • twimlets.com check it out
    • Message%5B0%5D=
      • ​Notice the '0', this indicates first position
    • '&SUBSTITUTE(Subject, " ", ",%20")&
      • Replaces blank spaces with an URL acceptable term = %20
    • '.&Message%5B1%5D='&SUBSTITUTE(SUBSTITUTE(Audio_URL__c,':', '%3A'),'/', '%2F')&
      • (.) pauses 
      • SUBSTITUTE(SUBSTITUTE(Audio_URL__c,':', '%3A'),'/', '%2F')
        • the audio url 
        • This replaces ";" and "/"  with the acceptable url terms
    • '&Message%5B2%5D=%20'&Id&'&'
      • I ended the call with another text field called Id
Other notes: 
Message%5B1%5D = Message[1]
Message[0] The URL of a media file to <Play>, or a string to <Say>

Check out the Twimlets from Twilio here --> https://www.twilio.com/labs/twimlets
 
I have working Code the sends an SMS or Voice call via Apex and Twilio, Great stuff. The trouble I am having is writing the Tests (maybe because its Friday?) and I just need a little help. I don't do near enough Apex for my liking and I am feeling it here. 

I know I should be writing a Http mock someplace in my test...Any help/pointers would be most appreciated. 

Working SMS:
public class TwilioSMSInvocable {
        @InvocableMethod
        public static void callPhoneService(List<ID> caseIDs) {
            List<Twilio_SMS__c> SelectTwilio_SMS = [Select Id, MobileNumber__C, Message__c from Twilio_SMS__c Where ID in :caseIDs] ;
        for (Twilio_SMS__c t : SelectTwilio_SMS){
               Map<String,String> params = new Map<String,String> {
                 'To'   => t.MobileNumber__c,
                 'From' => '13176666666',                
                 'Body' => t.Message__c
             };
              
                DoCallout(params);      
         }
            }
        
        @future(callout=true)
        
        private static void DoCallout(Map<String, String> params){
            String account = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
            String token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
            TwilioRestClient client = new TwilioRestClient(account, token);
            TwilioSMS sms = client.getAccount().getSMSMessages().create(params);
             System.Debug('TwilioSMS ' + sms) ;
        }
    }
   
Working Voice:

   
public class TwilioCallInvocable {
    
        @InvocableMethod
        public static void callPhoneService(List<ID> caseIDs) {
            List<Twilio_Voice__c> SelectTwilio_Voice = [Select Id, Say__c, URL_Build__c from Twilio_Voice__c Where ID in :caseIDs] ;
        for (Twilio_Voice__c t : SelectTwilio_Voice){
               Map<String,String> params = new Map<String,String> {
            'To'   => t.MobileNumber__c,
            'From' => '+13176666666',               
                'Url' => t.URL_Build__c
            };
              
                DoCallout(params);      
           }
        }
        
        @future(callout=true)
        
        private static void DoCallout(Map<String, String> params){
            String account = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
            String token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
            TwilioRestClient client = new TwilioRestClient(account, token);
            TwilioCall call = client.getAccount().getCalls().create(params);
                system.debug('TwilioCAL' + call);
        }
    }


Test Class:

   
@isTest
    private class TwilioSMSTest 
    {
        static testmethod void testTwilioSMSInvocable() 
        {
            Map<String,String> params = new Map<String,String> {
                 'To'   => '+17602444355',
                 'From' => '13176664444',               
                 'Body' => 'test message'
             };
                String account = 'AC6a217d8adb3460b5870c05bc6c666666';
            String token = '397c3f614cd3cf783154dc2383234444';
            TwilioRestClient client = new TwilioRestClient(account, token);
            TwilioSMS sms = client.getAccount().getSMSMessages().create(params);
            test.startTest();
                 Test.setMock(HttpCalloutMock.class, new TwilioSMSTest());
            test.stopTest();
        }
    }



I am getting 0 error messages, and 0 test coverage
I am getting a Attempting to dereference a null object in my test. I am new to Test writing and have not ficured out how to pass the test account into the test controller. 
 
public class CustomerInfoSheet {
    public String PrintOut { get; set; }
    public String LookupID;
    public String LookupType;
    
    
     public CustomerInfoSheet() {
        LookupID = ApexPages.currentPage().getParameters().get('id');
        LookupType = ApexPages.currentPage().getParameters().get('l');
        List<Account> a;
        
        PrintOut = '';      
        
                  
        if (LookupType == 'a' ){
            a = [select Name,  Industry, Type from Account where Id = :LookupID];
        } 
        if (LookupType == 'z' ) {
            a = [select Name, Industry, Type from Account where Zone__c = :LookupID];
        }
 
       //Industry
         {myPicklist.clear();
             Schema.DescribeFieldResult field = Account.Industry.getDescribe();
            for (Schema.PicklistEntry f : field.getPicklistValues()){
             myPicklist.add(f.getLabel());}
             }
         string test104 = '';
         for (String str : myPicklist)
         {test104 += str + ' -/- ';}
         test104 = test104.removeEnd(' -/- ');
         String Industrylist = String.valueOf('No Value Selected - Please Select one now: '+ test104);
         
         
               
        String CustomerName = '';
        
        String Industry = '';
      
        if (!a.isEmpty()){
            for (Account CustomerInfo : a) {
                
                CustomerName = CustomerInfo.Name;
                              
                 if (!(CustomerInfo.Industry == null)) { Industry = CustomerInfo.Industry; } else { Industry = Industrylist;}
                              
                PrintOut += '<div style="page-break-after:always;">';
                PrintOut += '<strong>Company: </strong>';
                PrintOut += CustomerName;
                 PrintOut += '<br/>';
                PrintOut += '<br/>';
                PrintOut += '<strong>Industry: </strong>';
                PrintOut += Industry;
              }
        }
    }    
}
​@IsTest
    public class CustomerInfoSheetTest {
        
     static testMethod void testCustomerInfoSheet() {

                          Account acct = (Account)Account.sObjectType.newSObject(null, true);
                         acct.Name='TestAccount';                 
                         acct.Industry = 'AG';
                          insert acct;
                         system.debug('account inserted '+acct.Id);
                     ApexPages.currentPage().getParameters().put('id', acct.Id);
                 system.debug('Account Fields '+acct);

                  CustomerInfoSheet ac = new CustomerInfoSheet(); // attempting to dereference a null object here. 
    system.debug('CustomerInfoSheet'+ac);
 }    
}

 
I am getting 56% coverage, I am also getting an Attempt to de-reference a null object with this line of code 'CustomerInfoSheet ac = new CustomerInfoSheet();'

@IsTest
public class CustomerInfoSheetTest {

 static testMethod void testCustomerInfoSheet() {

     Account a = new Account();
      a.Name='TestAccount';
      a.Industry='AG';
     a.Region__c = 'Delta';
      insert a;
     
     a =[SELECT Id, Name, Industry, Region__c FROM Account testAccount WHERE Name=:a.Name];
     system.assert(true, a.Id);
     if (a != null) {
            
            }
     
       
     PageReference pageRef = Page.CustomerInfoSheet;
   pageRef.getParameters().put('id',a.id);
     test.setCurrentPage(pageRef);
     
     CustomerInfoSheet ac = new CustomerInfoSheet();
     
   
    test.startTest();  
     ac.PrintOut=a.Id;
        pageRef = ac.CustomerInfoSheet();
     System.assertEquals(pageRef.getUrl(), '/'+a.Id);
    test.stopTest();
     
 }    
}
Bug with process Builder, wont total sum of fields on parent object unless a new record is created on child object. 

I am tying to sum totals of records with a specific date onto a Account Field from an Order object records. My apex works, the only catch is I have to create 2 order records inorder to see the 1st records amount added to the field on the Account object. 

Any help would be greatly appriciated. 
I get the following error for only two user names. One is Active on is Inactive.
I have 30 ussers can test this mass transfere app on and only two of them threw up the error below.
 
core.apexpages.exceptions.ApexPagesHandledException: Object type not accessible. Please check permissions and make sure the object is not in development mode: and (CreatedDate > null) ^ ERROR at Row:3:Column:6 invalid operator. Original queryString was: 'SELECT name,StageName,Ownerid,CloseDate from Opportunity WHERE ( ((Owner.LastName = 'Chavarria') and ((StageName != 'No Sale') AND (StageName != 'Converted') AND (StageName != 'No Sale - Do Not Contact')) and (CreatedDate > null) and (CreatedDate < null)) ) ORDER BY Name ASC LIMIT 10000'
I have working Code the sends an SMS or Voice call via Apex and Twilio, Great stuff. The trouble I am having is writing the Tests (maybe because its Friday?) and I just need a little help. I don't do near enough Apex for my liking and I am feeling it here. 

I know I should be writing a Http mock someplace in my test...Any help/pointers would be most appreciated. 

Working SMS:
public class TwilioSMSInvocable {
        @InvocableMethod
        public static void callPhoneService(List<ID> caseIDs) {
            List<Twilio_SMS__c> SelectTwilio_SMS = [Select Id, MobileNumber__C, Message__c from Twilio_SMS__c Where ID in :caseIDs] ;
        for (Twilio_SMS__c t : SelectTwilio_SMS){
               Map<String,String> params = new Map<String,String> {
                 'To'   => t.MobileNumber__c,
                 'From' => '13176666666',                
                 'Body' => t.Message__c
             };
              
                DoCallout(params);      
         }
            }
        
        @future(callout=true)
        
        private static void DoCallout(Map<String, String> params){
            String account = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
            String token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
            TwilioRestClient client = new TwilioRestClient(account, token);
            TwilioSMS sms = client.getAccount().getSMSMessages().create(params);
             System.Debug('TwilioSMS ' + sms) ;
        }
    }
   
Working Voice:

   
public class TwilioCallInvocable {
    
        @InvocableMethod
        public static void callPhoneService(List<ID> caseIDs) {
            List<Twilio_Voice__c> SelectTwilio_Voice = [Select Id, Say__c, URL_Build__c from Twilio_Voice__c Where ID in :caseIDs] ;
        for (Twilio_Voice__c t : SelectTwilio_Voice){
               Map<String,String> params = new Map<String,String> {
            'To'   => t.MobileNumber__c,
            'From' => '+13176666666',               
                'Url' => t.URL_Build__c
            };
              
                DoCallout(params);      
           }
        }
        
        @future(callout=true)
        
        private static void DoCallout(Map<String, String> params){
            String account = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
            String token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
            TwilioRestClient client = new TwilioRestClient(account, token);
            TwilioCall call = client.getAccount().getCalls().create(params);
                system.debug('TwilioCAL' + call);
        }
    }


Test Class:

   
@isTest
    private class TwilioSMSTest 
    {
        static testmethod void testTwilioSMSInvocable() 
        {
            Map<String,String> params = new Map<String,String> {
                 'To'   => '+17602444355',
                 'From' => '13176664444',               
                 'Body' => 'test message'
             };
                String account = 'AC6a217d8adb3460b5870c05bc6c666666';
            String token = '397c3f614cd3cf783154dc2383234444';
            TwilioRestClient client = new TwilioRestClient(account, token);
            TwilioSMS sms = client.getAccount().getSMSMessages().create(params);
            test.startTest();
                 Test.setMock(HttpCalloutMock.class, new TwilioSMSTest());
            test.stopTest();
        }
    }



I am getting 0 error messages, and 0 test coverage
I am getting a Attempting to dereference a null object in my test. I am new to Test writing and have not ficured out how to pass the test account into the test controller. 
 
public class CustomerInfoSheet {
    public String PrintOut { get; set; }
    public String LookupID;
    public String LookupType;
    
    
     public CustomerInfoSheet() {
        LookupID = ApexPages.currentPage().getParameters().get('id');
        LookupType = ApexPages.currentPage().getParameters().get('l');
        List<Account> a;
        
        PrintOut = '';      
        
                  
        if (LookupType == 'a' ){
            a = [select Name,  Industry, Type from Account where Id = :LookupID];
        } 
        if (LookupType == 'z' ) {
            a = [select Name, Industry, Type from Account where Zone__c = :LookupID];
        }
 
       //Industry
         {myPicklist.clear();
             Schema.DescribeFieldResult field = Account.Industry.getDescribe();
            for (Schema.PicklistEntry f : field.getPicklistValues()){
             myPicklist.add(f.getLabel());}
             }
         string test104 = '';
         for (String str : myPicklist)
         {test104 += str + ' -/- ';}
         test104 = test104.removeEnd(' -/- ');
         String Industrylist = String.valueOf('No Value Selected - Please Select one now: '+ test104);
         
         
               
        String CustomerName = '';
        
        String Industry = '';
      
        if (!a.isEmpty()){
            for (Account CustomerInfo : a) {
                
                CustomerName = CustomerInfo.Name;
                              
                 if (!(CustomerInfo.Industry == null)) { Industry = CustomerInfo.Industry; } else { Industry = Industrylist;}
                              
                PrintOut += '<div style="page-break-after:always;">';
                PrintOut += '<strong>Company: </strong>';
                PrintOut += CustomerName;
                 PrintOut += '<br/>';
                PrintOut += '<br/>';
                PrintOut += '<strong>Industry: </strong>';
                PrintOut += Industry;
              }
        }
    }    
}
​@IsTest
    public class CustomerInfoSheetTest {
        
     static testMethod void testCustomerInfoSheet() {

                          Account acct = (Account)Account.sObjectType.newSObject(null, true);
                         acct.Name='TestAccount';                 
                         acct.Industry = 'AG';
                          insert acct;
                         system.debug('account inserted '+acct.Id);
                     ApexPages.currentPage().getParameters().put('id', acct.Id);
                 system.debug('Account Fields '+acct);

                  CustomerInfoSheet ac = new CustomerInfoSheet(); // attempting to dereference a null object here. 
    system.debug('CustomerInfoSheet'+ac);
 }    
}

 
I am getting 56% coverage, I am also getting an Attempt to de-reference a null object with this line of code 'CustomerInfoSheet ac = new CustomerInfoSheet();'

@IsTest
public class CustomerInfoSheetTest {

 static testMethod void testCustomerInfoSheet() {

     Account a = new Account();
      a.Name='TestAccount';
      a.Industry='AG';
     a.Region__c = 'Delta';
      insert a;
     
     a =[SELECT Id, Name, Industry, Region__c FROM Account testAccount WHERE Name=:a.Name];
     system.assert(true, a.Id);
     if (a != null) {
            
            }
     
       
     PageReference pageRef = Page.CustomerInfoSheet;
   pageRef.getParameters().put('id',a.id);
     test.setCurrentPage(pageRef);
     
     CustomerInfoSheet ac = new CustomerInfoSheet();
     
   
    test.startTest();  
     ac.PrintOut=a.Id;
        pageRef = ac.CustomerInfoSheet();
     System.assertEquals(pageRef.getUrl(), '/'+a.Id);
    test.stopTest();
     
 }    
}
Bug with process Builder, wont total sum of fields on parent object unless a new record is created on child object. 

I am tying to sum totals of records with a specific date onto a Account Field from an Order object records. My apex works, the only catch is I have to create 2 order records inorder to see the 1st records amount added to the field on the Account object. 

Any help would be greatly appriciated.