• Salesforce Dev in Training
  • NEWBIE
  • 60 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 15
    Questions
  • 58
    Replies
I'm trying to map "Cases" when I convert a Lead to a Contact. I have a Lookup field on the Cases object for Leads, so I know they're able to be attached. However, I need to create some code that will keep the Case attached to the Lead when the Lead converts to a Contact. Right now, the Case isn't attaching to the newly converted Contact.

Is it possible to create a Trigger to decapitalize any letters in Account Name field after an apostrophe if the letter following is an "S"?

Example: St. Paul'S (decapitalize it) so that it would equal St. Paul's.

We had a developer write a code to capitalize all first letters and unfortunately the developer doesn't communicate with us anymore.

 

I am trying to map Cases when I convert a Lead to a Contact. Salesforce Standard Support says it requires a trigger. I created a Lookup field on "Cases" to attach the Lead, however, when the Contact is converted, it gets lost.

Any thoughts would be very helpful.

I'd like to create code that would be a before insert I believe.

I have a Custom Object titled, "Speciality Objects". This object has a record type titled "HERO Stories". There is a lookup to Contacts on this object (not a Master Detail).

The code needs to lookup to the Contact and pull the Contact's "First Name" (from Contact) + "Last Name" (from Contact) + HERO Story (plain text) into a field.

How is this possible?

Hello, I have a custom object titled "Interview Results". I have a lookup field titled "Owner". This field should default a value of whomever is logged into the org. For example, it's a lookup to "User", so the field should be the User logged in.

Is it possible to write a before insert trigger to populate this field?

I created a custom object titled "Interview Results".

By default there is a required standard field that is either a text (80) or an auto-number. I want this field to auto-fill with whatever the user chooses for a picklist. Is this possible?

The picklist is titled "Interview Type".

Essentially I want the standard field "Interview Results" to equal whatever the user picks from the custom field "Interview Type".

Hello Developer Community,

I have a question in dealing with Apex Triggers and the Task object in Salesforce. I have had help on here thus far, and I'm just about to where I need to be, but there's a snag.
Here's my code:

trigger TaskTrigger on Task (before insert) {
    for(Task ta: Trigger.new) {
        if(ta.Task_Results__c != null && ta.Subject != ta.Task_Results__c) {
            ta.Subject += ' ('+ta.Task_Results__c + ')';
        }
    }
}

This is working great.
When creating a NEW task, if the Subject is blank, then whatever is picked from the Task Results picklist autofills into the Subject -- this is great! (it does not duplicate the Task Results)
If the NEW Subject is "Call" and the Task Result is "Inbound - HWN" then the Subject becomes "Call (Inbound - HWN)" -- this is great!
However if it's an EXISTING task with the Subject of "Call", and I try to edit the Task and select the Task Results to be Inbound - HWN, it doesn't get added to the Subject at all. The Subject stays as Call. I want to Task Results to be added (only once) to the Subject if the Task is edited and it isn't there yet.

I believe I either need another trigger to combat this or potentially change up the language.

Any help is much appreciated as I'm learning Apex currently.

Quick question...

Does anyone know how to add "does not contain" to an Apex trigger (if that's a possibility - if not, I may need a second trigger)?

For example, I have the following code:
trigger TaskTrigger on Task (before insert, before update) {
    for(Task ta: Trigger.new) {
        if(ta.Task_Results__c != null && ta.Subject != ta.Task_Results__c) {
            ta.Subject += ' ('+ta.Task_Results__c + ')';
        }
    }
}

What's happening is every time a user "Edits" and "Saves" on a Task, it's duplicating the Task Result value in the Subject line. I only want this to happen once. Is there a way to add "and ta.Subject DOES NOT CONTAIN ta.Task_Results_c" or ONLY UPDATE ONCE?

In other words, I don't want the Task Results to be added to the Subject if it's already there.
Ex:
Subject - Call
Task Result - (Inbound)
Save
Final Subject = Call (Inbound)

If a user edits and saves, then what happens is this:
Subject = Call (Inbound) (Inbound)
and it keeps adding the Task Result (Inbound) to the end of the Subject.

Hey SF Dev Community,

I created a trigger that has one error in it. I need to disable it as I've already created a new change set with the fix, what's the best method to do this?

Thank you

Thanks to Mahesh D I was able to create a trigger that successfully performed the desired operation, however I have an additional question to the Community.

The code Mahesh helped me with is the following:

01//
02// Trigger on Task to populate the Subject.
03//
04trigger TaskTrigger on Task (before insert, before update) {
05    for(Task ta: Trigger.new) {
06        if(ta.Task_Results__c != null) {
07            ta.Subject += ' ('+ta.Task_Results__c + ')';
08        }
09    }
10}

What this code is doing is adding whatever a user selects in the picklist "Task Results" to the end of the Task Subject inside of parenthesis. The issue is I only want this trigger if the Subject is not equal to null. I tried adding code that said && ta.Subject != null on the "if" clause but that didn't work successfully. I have code written in my org that says if Subject = null then Subject = Task Result. What this is doing now with the code written above is duplicating the Subject if it's left blank.

Subject = Null
Task Result = Inbound Call

Hit Save, then 

Subject = Inbound Call (Inbound Call)

^ I do not want the duplicate value.

I am trying to write apex code for the Activities/Task object.

We have a custom picklist field titled "Task Results".

I want to have whatever is selected in "Task Results" to automaticcaly append/add-to whatever is typed into the Task Subject in parenthesis.

For example, if Subject is "Call" and someone selected "Inbound" from the Task Results picklist, I want the Subject to then be changed to "Call (Inbound)".

Please let me know if that makes sense. 
I accidently deleted my "OAuth Refresh Token" for my Salesforce-Volusion integration, and I cannot seem where to find it. Anyone know how to find this "OAuth Refresh Token"?

Hello SF Dev Community,

I hope everyone had a great weekend! I am trying to map a custom object from a Lead to a Contact when that Lead is converted. I see that it's an "Idea" posted and most of the comments say it's an easy fix with Apex coding, however, as a non-profit organization, it's tough sometimes to afford high-end development. I wasn't certain if this easy fix is something I could do as I've recently started to learn Apex coding. Any thoughts or instructions would greatly help.
 

Thank you,
 

AB

Hello,

I am receiving the following error:


"A workflow or approval field update caused an error when saving this record. Contact your administrator to resolve it. Next Payment Date: value not of required type: common.formula.FormulaEvaluationException: Month or Day out of range in DATE() function"

When I change (on a custom object) the Last Payment Date / Next Payment date, it's causing this error which won't allow me to save any records.

I believe somewhere in this trigger is the error:


"1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
trigger RGNextPaymentDateUpdate on Recurring_Gift__c (before insert,before update) {
    for(Recurring_Gift__c rg : Trigger.new){
        system.debug('-----Last_date__c ------'+rg.Last_date__c );
        system.debug('------Recurrence_SchedulePL__c--------'+rg.Recurrence_SchedulePL__c);
        if(Trigger.isInsert){
            if(rg.Last_date__c !=null){
                if(rg.Recurrence_SchedulePL__c=='Monthly'){
                system.debug('-----Last_date__c ------'+rg.Last_date__c );
                    rg.Next_Payment_Date__c = (rg.Last_date__c).addMonths(1);
                }
                else if(rg.Recurrence_SchedulePL__c=='Yearly'){
                    rg.Next_Payment_Date__c = (rg.Last_date__c).addYears(1);
                }
            }
        }
        else if(Trigger.isUpdate){
            Recurring_Gift__c  rgOld = Trigger.oldMap.get(rg.Id);            
            if(rg.Last_date__c !=null && rg.Last_date__c != rgOld.Last_date__c  ){
                system.debug('-----Last_date__c ------'+rg.Last_date__c );
                if(rg.Recurrence_SchedulePL__c=='Monthly'){
                    rg.Next_Payment_Date__c = (rg.Last_date__c).addMonths(1);
                    system.debug('-----Recurrence_SchedulePL__c------'+rg.Recurrence_SchedulePL__c);
                }
                else if(rg.Recurrence_SchedulePL__c=='Yearly'){
                    rg.Next_Payment_Date__c = (rg.Last_date__c).addYears(1);
                    system.debug('-----Recurrence_SchedulePL__c------'+rg.Recurrence_SchedulePL__c);
                }
            }
        }
    }
}"

Our developers are out of office, and it's somewhat urgent, however, I'm not sure where I would go to fix the error or how I need to. Any help would be appreciated.

Hello,

I am receiving the following error:

"A workflow or approval field update caused an error when saving this record. Contact your administrator to resolve it. Next Payment Date: value not of required type: common.formula.FormulaEvaluationException: Month or Day out of range in DATE() function"

When I change (on a custom object) the Last Payment Date / Next Payment date, it's causing this error which won't allow me to save any records.

I believe somewhere in this trigger is the error:

"1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
trigger RGNextPaymentDateUpdate on Recurring_Gift__c (before insert,before update) {
    for(Recurring_Gift__c rg : Trigger.new){
        system.debug('-----Last_date__c ------'+rg.Last_date__c );
        system.debug('------Recurrence_SchedulePL__c--------'+rg.Recurrence_SchedulePL__c);
        if(Trigger.isInsert){
            if(rg.Last_date__c !=null){
                if(rg.Recurrence_SchedulePL__c=='Monthly'){
                system.debug('-----Last_date__c ------'+rg.Last_date__c );
                    rg.Next_Payment_Date__c = (rg.Last_date__c).addMonths(1);
                }
                else if(rg.Recurrence_SchedulePL__c=='Yearly'){
                    rg.Next_Payment_Date__c = (rg.Last_date__c).addYears(1);
                }
            }
        }
        else if(Trigger.isUpdate){
            Recurring_Gift__c  rgOld = Trigger.oldMap.get(rg.Id);            
            if(rg.Last_date__c !=null && rg.Last_date__c != rgOld.Last_date__c  ){
                system.debug('-----Last_date__c ------'+rg.Last_date__c );
                if(rg.Recurrence_SchedulePL__c=='Monthly'){
                    rg.Next_Payment_Date__c = (rg.Last_date__c).addMonths(1);
                    system.debug('-----Recurrence_SchedulePL__c------'+rg.Recurrence_SchedulePL__c);
                }
                else if(rg.Recurrence_SchedulePL__c=='Yearly'){
                    rg.Next_Payment_Date__c = (rg.Last_date__c).addYears(1);
                    system.debug('-----Recurrence_SchedulePL__c------'+rg.Recurrence_SchedulePL__c);
                }
            }
        }
    }
}"

Our developers are out of office, and it's somewhat urgent, however, I'm not sure where I would go to fix the error or how I need to. Any help would be appreciated.

I created a custom object titled "Interview Results".

By default there is a required standard field that is either a text (80) or an auto-number. I want this field to auto-fill with whatever the user chooses for a picklist. Is this possible?

The picklist is titled "Interview Type".

Essentially I want the standard field "Interview Results" to equal whatever the user picks from the custom field "Interview Type".

I'm trying to map "Cases" when I convert a Lead to a Contact. I have a Lookup field on the Cases object for Leads, so I know they're able to be attached. However, I need to create some code that will keep the Case attached to the Lead when the Lead converts to a Contact. Right now, the Case isn't attaching to the newly converted Contact.

Is it possible to create a Trigger to decapitalize any letters in Account Name field after an apostrophe if the letter following is an "S"?

Example: St. Paul'S (decapitalize it) so that it would equal St. Paul's.

We had a developer write a code to capitalize all first letters and unfortunately the developer doesn't communicate with us anymore.

 

I am trying to map Cases when I convert a Lead to a Contact. Salesforce Standard Support says it requires a trigger. I created a Lookup field on "Cases" to attach the Lead, however, when the Contact is converted, it gets lost.

Any thoughts would be very helpful.

Hello, I have a custom object titled "Interview Results". I have a lookup field titled "Owner". This field should default a value of whomever is logged into the org. For example, it's a lookup to "User", so the field should be the User logged in.

Is it possible to write a before insert trigger to populate this field?

I created a custom object titled "Interview Results".

By default there is a required standard field that is either a text (80) or an auto-number. I want this field to auto-fill with whatever the user chooses for a picklist. Is this possible?

The picklist is titled "Interview Type".

Essentially I want the standard field "Interview Results" to equal whatever the user picks from the custom field "Interview Type".

Quick question...

Does anyone know how to add "does not contain" to an Apex trigger (if that's a possibility - if not, I may need a second trigger)?

For example, I have the following code:
trigger TaskTrigger on Task (before insert, before update) {
    for(Task ta: Trigger.new) {
        if(ta.Task_Results__c != null && ta.Subject != ta.Task_Results__c) {
            ta.Subject += ' ('+ta.Task_Results__c + ')';
        }
    }
}

What's happening is every time a user "Edits" and "Saves" on a Task, it's duplicating the Task Result value in the Subject line. I only want this to happen once. Is there a way to add "and ta.Subject DOES NOT CONTAIN ta.Task_Results_c" or ONLY UPDATE ONCE?

In other words, I don't want the Task Results to be added to the Subject if it's already there.
Ex:
Subject - Call
Task Result - (Inbound)
Save
Final Subject = Call (Inbound)

If a user edits and saves, then what happens is this:
Subject = Call (Inbound) (Inbound)
and it keeps adding the Task Result (Inbound) to the end of the Subject.

How to write test class for the below code.

 public String[] MPItemsQues5 { 
        get {
            String[] selected = new List<String>();
            List<SelectOption> sos = this.MPOptionsQues5;
            for(SelectOption s : sos) {
                if (this.oQuestion.Question5__c !=null && this.oQuestion.Question5__c.contains(s.getValue()))
                    selected.add(s.getValue());
            }
            return selected;
        }public set {
            String selectedCheckBox = '';
            for(String s : value) {
                if (selectedCheckBox == '') 
                    selectedCheckBox += s;
                else selectedCheckBox += ';' + s;
            }
            oQuestion.Question5__c = selectedCheckBox;
        }
    }