• David @ Configero
  • NEWBIE
  • 120 Points
  • Member since 2017

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 41
    Replies
I'm using the after update trigger to update the "BillingCity" field in the Account object and make the field in proper case.
 
trigger on Account (after update) {

            String billingCity = Account.billingCity;

            toTitleCase(billingCity);
}

And the code in the invoked toTitleCase(billingCity) method:
 
//converts a given string to Title Case where the
//first letter of every word is capitalised and the rest are small
public String toTitleCase(String billingCity) {
   System.debug('billingCity ' + billingCity);
   String titlePhrase = '';
   //a set of words that should always be in lower case when in Title Case
   Set<String> forceLower = new Set<String>{'of', 'the', 'for', 'and', 'a', 'to', 'at' ,'an', 'but', 'if', 'or', 'nor'};

   if(billingCity != null && billingCity.length() > 0){
      String[] splitPhrase = billingCity.trim().split(' ');

      for(integer i = 0; i < splitPhrase.size(); i++){
          if(!forceLower.contains(splitPhrase[i].toLowerCase()) || i == 0 || i == (splitPhrase.size()-1) ) {
             titlePhrase += (splitPhrase[i].substring(0,1).toUpperCase())+(splitPhrase[i].substring(1).toLowerCase())+' ';

          } else {
               titlePhrase += splitPhrase[i].toLowerCase()+' ';

               }
          }
       }

       return titlePhrase.trim();
}
In the debug log I can see that the "BillinCity" field is updated with the proper case:
 
17:00:57:945 USER_DEBUG [40]|DEBUG|billingCity San Marino
but on a record level the field remains with upper case: "SAN MARINO"

Please advise an appropriate solution.

 
for (Database.SaveResult sr : srList)..can somebody expalin the syntax?
what does the 'semi colon' in the bracket mean?
in
Database.SaveResult[] srList = Database.insert(conList, false); // Iterate through each returned result for (Database.SaveResult sr : srList) { if (sr.isSuccess()) { // Operation was successful, so get the ID of the record that was processed System.debug('Successfully inserted contact. Contact ID: ' + sr.getId()); } else { // Operation failed, so get all errors for(Database.Error err : sr.getErrors()) { System.debug('The following error has occurred.'); System.debug(err.getStatusCode() + ': ' + err.getMessage()); System.debug('Contact fields that affected this error: ' + err.getFields()); } }
Hello,

I am trying to use AggregateResult to build a controller for a VF page.  This is the fist time that I am using this function and am recieving the error: 
Error: Compile Error: Missing '<EOF>' at 'public' at line 10 column 1

I have googled this like crazy, and seem to understand that it is because I have markup outside of the wrapper but I still can't understand how to fix it?  Can anyone help?

Here is my class: 
 
public class CurrentWeekDY{
    String Campaign {get; set;}
    String Delivery {get; set;}
        public DelSum(string c, string d){
        this.Campaign=c;
        this.Delivery=d;
        
    }
}
public List<DelSum> DelSumList = new List<DelSum>();

public List<DelSum> getDelSumOut(){

    AggregateResult[] AgR = [SELECT Campaign_TL__c, SUM(Spend__c) FROM TL_Client__c WHERE CWDelivery__c = TRUE GROUP BY Campaign_TL__c ORDER BY Campaign_TL__c]; 
    for (AggregateResult DYList : AgR) { 
        DelSumList.add(new DelSum(String.valueOf(DYList.get('Campaign_TL__c')), String.valueOf(DYList.get('expr0')), String.valueOf(DYList.get('expr1'))));
    }
    return DelSumList;
}

Thank you so much for any help!

John 
Hello, 
I am new with Apex and tried to create an inbound email service in salesforce. 
First of all, I receive an email. I need to look for a serial number on the email content to match the serial name which is already a record in Salesforce. If email bady contains "FULL OUT", it updates field Status (API: Status__c) on a custom object "Container(API: Container__c)".
How can I write the Apex code? Please help.

I don't know how to write code to look for tried to write a simple code to insert the record, received 2 error messages: 
1. line 5: invalid type: Container
2. line 6: Method does not exist or incorrect signature: void containder() from the type UpdateContainer()
global class UpdateContainer implements Messaging.InboundEmailHandler{
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope){
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        string containerName = email.fromName;
        Container container = new Container(Name=containerName);
        insert container();
        return null;
    }
}

 
The Idea is when i create a new opportunity and change the stage to Prospecting it should run this trigger and check if any old opportunities with stage Prospecting and which was created 90 days ago and convert that to closelost.
trigger UpdateRiskStatus1 on opportunity (after insert,after update) {
        
    List<opportunity> fvr = new List<opportunity>();
    
    for (opportunity  objvr :[select Id , stagename from opportunity where stagename='pending' and createddate < LAST_90_DAYS])
    {
        for(Opportunity op :trigger.new){
        
        if(op.stagename  == 'prospecting')
        {
        objvr.stagename='closed lost';
        fvr.add(objvr);
        }
        
        }
    }
   upsert fvr;

}
  • January 19, 2018
  • Like
  • 0
I'm using the after update trigger to update the "BillingCity" field in the Account object and make the field in proper case.
 
trigger on Account (after update) {

            String billingCity = Account.billingCity;

            toTitleCase(billingCity);
}

And the code in the invoked toTitleCase(billingCity) method:
 
//converts a given string to Title Case where the
//first letter of every word is capitalised and the rest are small
public String toTitleCase(String billingCity) {
   System.debug('billingCity ' + billingCity);
   String titlePhrase = '';
   //a set of words that should always be in lower case when in Title Case
   Set<String> forceLower = new Set<String>{'of', 'the', 'for', 'and', 'a', 'to', 'at' ,'an', 'but', 'if', 'or', 'nor'};

   if(billingCity != null && billingCity.length() > 0){
      String[] splitPhrase = billingCity.trim().split(' ');

      for(integer i = 0; i < splitPhrase.size(); i++){
          if(!forceLower.contains(splitPhrase[i].toLowerCase()) || i == 0 || i == (splitPhrase.size()-1) ) {
             titlePhrase += (splitPhrase[i].substring(0,1).toUpperCase())+(splitPhrase[i].substring(1).toLowerCase())+' ';

          } else {
               titlePhrase += splitPhrase[i].toLowerCase()+' ';

               }
          }
       }

       return titlePhrase.trim();
}
In the debug log I can see that the "BillinCity" field is updated with the proper case:
 
17:00:57:945 USER_DEBUG [40]|DEBUG|billingCity San Marino
but on a record level the field remains with upper case: "SAN MARINO"

Please advise an appropriate solution.

 
Hi, 

   String Alpha = ' A; B; C; D'; 
   String SearchString = 'A'
   I want to split the above string value as 

     A
     B
     C
     D

    Also Please suggest me how to search a string in list. 

Thanks
Sudhir
   

   

I have a batch process that prevents two different "concurrent" executions of the batch for a given user by maintaining some state (in the databse) that is set in start and cleared in finish (actually using the user for the created AsyncApexJob instances). During start processing, the state is queried from the database; if there is an entry already for the current user the batch is aborted, using System.abortJob, and an empty query locator is returned.

I am trying to test that two different users can successfully execute the batch via the use of the following:

Id profileId = UserInfo.getProfileId();

List<User> fakeUsers = new List<User> {
        new User(Alias = 'X', Email='X@testorg.com', EmailEncodingKey='UTF-8', FirstName = 'Jim', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = profileId, TimeZoneSidKey='Europe/London', UserName='X@testorg.com'),
        new User(Alias = 'Y', Email='Y@testorg.com', EmailEncodingKey='UTF-8', FirstName = 'Fred', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = profileId, TimeZoneSidKey='Europe/London', UserName='Y@testorg.com')
};

Test.startTest();

// Simulate running both together under different user accounts
Id id1;
Id id2;

System.runAs(fakeUsers[0]) {
    MyBatch b1 = new MyBatch();

    id1 = Database.executeBatch(b1);
}

System.runAs(fakeUsers[1]) {
    MyBatch b2 = new MyBatch();

    id2 = Database.executeBatch(b2);
}

Test.stopTest();

Unfortunately it seems that both of the batches still get run with the same user (the actual user running the test rather than either of the fake users). I suspect this is because of the way batches are actually executed during the Test.stopTest method invocation, rather than at some asynchronous time.

Have I come across a bug in the way batches are run in a given user context during testing? Is there a workaround I can use?
  • January 18, 2018
  • Like
  • 0
for (Database.SaveResult sr : srList)..can somebody expalin the syntax?
what does the 'semi colon' in the bracket mean?
in
Database.SaveResult[] srList = Database.insert(conList, false); // Iterate through each returned result for (Database.SaveResult sr : srList) { if (sr.isSuccess()) { // Operation was successful, so get the ID of the record that was processed System.debug('Successfully inserted contact. Contact ID: ' + sr.getId()); } else { // Operation failed, so get all errors for(Database.Error err : sr.getErrors()) { System.debug('The following error has occurred.'); System.debug(err.getStatusCode() + ': ' + err.getMessage()); System.debug('Contact fields that affected this error: ' + err.getFields()); } }
I'm getting this message and our sales team cant log in the calls they make. Does anybody know how to fix this? 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger SalesforceIsTerrible caused an unexpected exception, contact your administrator: SalesforceIsTerrible: execution of BeforeInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 00Tf100002NostKEAR; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TasksToOpps: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.TasksToOpps: line 40, column 1: []: Trigger.SalesforceIsTerrible: line 27, column 1
Hello,

I am trying to use AggregateResult to build a controller for a VF page.  This is the fist time that I am using this function and am recieving the error: 
Error: Compile Error: Missing '<EOF>' at 'public' at line 10 column 1

I have googled this like crazy, and seem to understand that it is because I have markup outside of the wrapper but I still can't understand how to fix it?  Can anyone help?

Here is my class: 
 
public class CurrentWeekDY{
    String Campaign {get; set;}
    String Delivery {get; set;}
        public DelSum(string c, string d){
        this.Campaign=c;
        this.Delivery=d;
        
    }
}
public List<DelSum> DelSumList = new List<DelSum>();

public List<DelSum> getDelSumOut(){

    AggregateResult[] AgR = [SELECT Campaign_TL__c, SUM(Spend__c) FROM TL_Client__c WHERE CWDelivery__c = TRUE GROUP BY Campaign_TL__c ORDER BY Campaign_TL__c]; 
    for (AggregateResult DYList : AgR) { 
        DelSumList.add(new DelSum(String.valueOf(DYList.get('Campaign_TL__c')), String.valueOf(DYList.get('expr0')), String.valueOf(DYList.get('expr1'))));
    }
    return DelSumList;
}

Thank you so much for any help!

John 
I am getting error as 
System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] while executing my test class for trigger Please suggest:

Trigger:
trigger selectOneCheckbox on Survey_Mcd__c (before update) {
for(Survey_Mcd__c sms : Trigger.New){
  if(Trigger.isUpdate){
  if((sms.Yes_No__c && sms.X5_Scale_Rating__c && sms.Comment__c)  || (sms.Yes_No__c && sms.X5_Scale_Rating__c)  
  || (sms.Yes_No__c && sms.Comment__c) || (sms.X5_Scale_Rating__c && sms.Comment__c)){
  sms.addError('Please select only one checkbox');
   }
  }
 }
}

Test Class:
@isTest
public class TestselectOneCheckbox {

    static testMethod  void myUnitTest() {
        system.test.startTest();
            
            Survey_Mcd__c sms= new Survey_Mcd__c();
                 sms.Yes_No__c=true;
            sms.X5_Scale_Rating__c=true;
            sms.Comment__c=true;
               update sms;
        List <Survey_Mcd__c> sm= [select id,Comment__c,X5_Scale_Rating__c,Yes_No__c from Survey_Mcd__c where id=:sms.id];
         for ( Survey_Mcd__c v:sm)
        {
            v.Comment__c=true;
        } 
        insert sm;
            system.test.stopTest();
        
    }
}


 

I'm new to SF Developement. I'm trying to get Account Name in the Opportunity for some scenario.
I'm getting Null value when I'm trying this code
 

for(Opportunity opp:trigger.New){
                if(opp.Quote_Category__c != 'Choose One'){
                    oppJobList.add(opp.AccountId.Name);
                }
            }
 

Help me on this. Thank you.

  • January 17, 2018
  • Like
  • 0
Hello, 
I am new with Apex and tried to create an inbound email service in salesforce. 
First of all, I receive an email. I need to look for a serial number on the email content to match the serial name which is already a record in Salesforce. If email bady contains "FULL OUT", it updates field Status (API: Status__c) on a custom object "Container(API: Container__c)".
How can I write the Apex code? Please help.

I don't know how to write code to look for tried to write a simple code to insert the record, received 2 error messages: 
1. line 5: invalid type: Container
2. line 6: Method does not exist or incorrect signature: void containder() from the type UpdateContainer()
global class UpdateContainer implements Messaging.InboundEmailHandler{
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope){
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        string containerName = email.fromName;
        Container container = new Container(Name=containerName);
        insert container();
        return null;
    }
}

 
I need to write a trigger code: Need to add the related contact to a specific campaign every time an account is created or edited. (Need to check for duplicate entry as well which cannot be done through a process builder). 
Hi
We need to save the first email address (from address) of an email, that is created in / related to a case where the field ‘first from address’ is empty into this field.
How is this possible? Unfortunatly I can’t use Email2Case. Do someone have an Apex code for this?
Thank you for your support.
BR
Mike
I have a script here that  I found and is almost perfect for what I need.. although when pressing the button "add competition" i need it to be added to a different object "Test Competitors" which is a related list shown in page of  "Account" (related list).
Could anybody "tweak"/ adjust this script accordingly!? ]

public class AccountSelectClassController{
 
    //Our collection of the class/wrapper objects wrapAccount
    public List<wrapAccount> wrapAccountList {get; set;}
    public List<Account> selectedAccounts{get;set;}
 
    public AccountSelectClassController(){
        if(wrapAccountList == null) {
            wrapAccountList = new List<wrapAccount>();
            for(Account a: [select Id, Name,BillingState, Website, Phone from Account limit 50]) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapAccountList.add(new wrapAccount(a));
            }
        }
    }
 
    public void processSelected() {
    selectedAccounts = new List<Account>();
 
        for(wrapAccount wrapAccountObj : wrapAccountList) {
            if(wrapAccountObj.selected == true) {
                selectedAccounts.add(wrapAccountObj.acc);
            }
        }
    }



<apex:page controller="AccountSelectClassController" sidebar="false">
    <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Add to Competition" action="{!processSelected}" rerender="table2"/>
            </apex:pageBlockButtons>
 
            <apex:pageblockSection title="All Accounts" collapsible="false" columns="2">
 
                <apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" id="table" title="All Accounts">
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                        <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                    </apex:column>
                    <apex:column value="{!accWrap.acc.Name}" />
                    <apex:column value="{!accWrap.acc.BillingState}" />
                    <apex:column value="{!accWrap.acc.Phone}" />
                </apex:pageBlockTable>
 
                <apex:pageBlockTable value="{!selectedAccounts}" var="c" id="table2" title="Selected Accounts">
                    <apex:column value="{!c.Name}" headerValue="Account Name"/>
                    <apex:column value="{!c.BillingState}" headerValue="Billing State"/>
                    <apex:column value="{!c.Phone}" headerValue="Phone"/>
                </apex:pageBlockTable>
 
            </apex:pageblockSection>
        </apex:pageBlock>
    </apex:form>
 
</apex:page> 


Also I need this VF page to be popping up when clicking "new test competition" on the related list as picture below
[User-added image]

If need anymore info please let me know.. I really appreciate the help!!

Thanks Vincent