• tharris
  • NEWBIE
  • 50 Points
  • Member since 2010

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 9
    Replies

Hi,

 

I have a String as '[!TEST!]' . Now I wish to replace this string with some other string say "SFDC". I am not able to do so.

I am using the String.replaceAll() function.

 

Below is a eg:

 

String str = 'Hi! How aRE YOU? I hope you are fine. D.';

str = str.replaceAll('[!Test!]','SFDC' );

system.debug(str);

 

Now this code replaces exclamation, T, e, s , t with SFDC. i.e the output is:

 

HiSFDC How aRE YOU? I hopSFDC you arSFDC finSFDC. D

 

which i am not expecting.

 

How can i replace this entire string .i.e [!Test!]

 

Thanks,

Shailesh.

Hi all,

 

I was trying to know where my upsert was failing and which record was making the mistake.

 

After doing some research, I found that Database.Upsert method gives me the information that I need but when I tryied to run it on my batch apex process, where my upsert is, I got this error: "  Not Serializable: LIST<Database.UpsertResult> 

 

  "

 

Does anybody know how can I fix it?

 

This is part of my code:

 

List<Database.UpsertResult> upsertResults;

Schema.SObjectField externalIdField = SalesAgreement__c.Fields.Id;

upsertResults = Database.upsert(salesAgreementDtoList,externalIdField,false)

externalIdField = SalesAgreementLineItem__c.Fields.Id;

upsertResults = Database.upsert(salesAgreementLineItemDtoList,externalIdField,false);

 

Many thanks in advance

Hi,

 

I have a String as '[!TEST!]' . Now I wish to replace this string with some other string say "SFDC". I am not able to do so.

I am using the String.replaceAll() function.

 

Below is a eg:

 

String str = 'Hi! How aRE YOU? I hope you are fine. D.';

str = str.replaceAll('[!Test!]','SFDC' );

system.debug(str);

 

Now this code replaces exclamation, T, e, s , t with SFDC. i.e the output is:

 

HiSFDC How aRE YOU? I hopSFDC you arSFDC finSFDC. D

 

which i am not expecting.

 

How can i replace this entire string .i.e [!Test!]

 

Thanks,

Shailesh.

Hi everyone-

 

I could really use some help with a simple trigger.  When a lead record is saved I need an apex trigger to populate a field called "Lead_Id__c" with the lead record's 18 digit ID.  Can someone please help?  Thanks very much in advance!

 

-Tom

  • August 22, 2011
  • Like
  • 0

Hi Devs,

      I have Trigger and basically it creates new case when a contact is created, below is my code, so when a user creates new contact and if he selects Notification_Type__c (picklist field from contact) == 'New Employee or New Contractor then a case gets created for New hire and after some months if this contact is terminated he goes to the same contact and selects Notification_Type__c == 'Term Employee then a case gets created for termination employee, but since my events are after insert, after update when a user first creates a contact he fills out some details from contact page and when he hits save case gets created but whenever he edits the contact and if he change some contact info again the case gets created since i have after update , i want the case to be created only once , do i have to write a separate trigger for New Employee and Term Employee, can't we include it in one?

 

 

Trigger: trigger ContactTrigger on Contact (after insert, after update) {
 
  ContactTriggerClass ct  = new ContactTriggerClass();
   ct.createCase(Trigger.newMap);  
    
}

 

Class: public class ContactTriggerClass
{
 
    public void createCase(Map<Id,Contact> TriggerNewValues)
   {
   
    List<Case> c = new List<Case>();
    
 for(Contact ct :[select c.Id,c.Name,c.AccountId,c.Notification_Type__c,c.Manager_Name__r.Name,c.EmployeeType__c,c.Location__c,c.Start_Date__c,,c.Special_Instructions_Hire__c,c.Special_Instructions_Term__c,c.Unix_Account__c,c.Termination_Date__c, c.Termination_Time__c from  Contact c where c.Id IN:TriggerNewValues.keyset()])
    {
       if((ct.Notification_Type__c == 'New Employee') || (ct.Notification_Type__c =='New Contractor'))
       {
          c.add(new Case(ContactId = ct.Id,AccountId = ct.AccountId,Type = 'PC SETUP_(New/Reused;Desktops,Laptops)',Status='Assigned',Priority = 'Standard',OwnerId = '00G400000015Yoo',Manager_Name__c = ct.Manager_Name__c,
Subject = 'New PC Setup :'+ct.Name+'- Start Date :'+string.valueof(ct.Start_Date__c),

Description = 'Name :'+ ct.Name+'\r\n\r\nManager :'+ct.Manager_Name__r.Name));

     }

  else if(ct.Notification_Type__c == 'Term Employee')
     {
            c.add(new Case(ContactId = ct.Id,AccountId = ct.AccountId,Type = 'PC SETUP_(New/Reused;Desktops,Laptops)',Status='Assigned',Priority = 'Standard',OwnerId = '00G400000015Yoo',
 Subject = 'PC Termination :'+ct.Name,

Description = 'Name :'+ct.Name+'\r\n\r\nManager :'+ct.Manager_Name__r.Name));
  }
        
     
   }
    insert c;
   }
 
}               
                   

 

 

So with Batch Apex we have to define 3 methods; start, execute, finish.

 

Start = The data source. This is called once

Execute = Callback for each "chunk" of data. This is called N times

Finish = Execute at the end of the batch, and only called once

 

In my execute, I need to keep a running total of counters. Based on how 'execute' works, it will be called over and over, thus "resetting" my counter.

 

So what I am looking for are variables that are passed by reference? 

 

Thanks!

Hi all,

 

I was trying to know where my upsert was failing and which record was making the mistake.

 

After doing some research, I found that Database.Upsert method gives me the information that I need but when I tryied to run it on my batch apex process, where my upsert is, I got this error: "  Not Serializable: LIST<Database.UpsertResult> 

 

  "

 

Does anybody know how can I fix it?

 

This is part of my code:

 

List<Database.UpsertResult> upsertResults;

Schema.SObjectField externalIdField = SalesAgreement__c.Fields.Id;

upsertResults = Database.upsert(salesAgreementDtoList,externalIdField,false)

externalIdField = SalesAgreementLineItem__c.Fields.Id;

upsertResults = Database.upsert(salesAgreementLineItemDtoList,externalIdField,false);

 

Many thanks in advance

We have a workflow which kicks-off based on a checkbox update in a custom object and sends email alert with Visualforce Email Template. Visualforce Email Template must have <apex:image>.

Then We developed an Apex scheduler which can update the checkbox so that the email alert goes every hour. While executing the Apex code it failed at the update of the checkbox with error -
'EXCEPTION_THROWN|[12]|System.DmlException: Update failed. First exception on row 0 with id a0A90000000AsaXEAS; first error: UNKNOWN_EXCEPTION, java.lang.NullPointerException: Argument Error: Parameter value is null:[]'

We can update that checkbox manually and send that email alert without any problem OR if we remove <apex:image> tag then it works fine.

 

Any idea on this issue???

  • December 23, 2010
  • Like
  • 0

Strange one comparing two multi-select using includes

 

 

	List<Account> accs = [select Id, Name, BillingCity, Country_ISO_Code__c, Type, Accreditations__c from Account where 
 	 		(Country_ISO_Code__c =: lead.Country_ISO__c) 
 	 		AND 
 	 		(Accreditations__c includes ( lead.All_Accreditation_Endorsements__c ))
 	 		Limit 1000];

 

 

Getting unexpected token, exhausted my options for now.

 

Both Accreditations fields are multi-select picklists

 

Any suggestions welcome - thanks

How do I check if a valid Contact is returned from a query like this in Apex.

 

Contact o = [SELECT c.Id, Email, LastName, FirstName, MailingCity, HomePhone, MailingState, MailingStreet, MailingPostalCode, AccountId, Source_Code__c, Drupal_User_Id__c FROM Contact c WHERE c.Email = :n.Email AND c.Id != :n.Id limit 1];

 

How do I check to see if o is a populate Contact object.