• gailh
  • NEWBIE
  • 50 Points
  • Member since 2009

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

Hi all, I'm very new to Apex and this is my first trigger. Thought it was quite simple but I'm getting the following error:

 

Validation Errors While Saving Record(s)

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Task_AfterInsert caused an unexpected exception, contact your administrator: Task_AfterInsert: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.Task_AfterInsert: line 18, column 1". 

 

The code is:

trigger Task_AfterInsert on Task (after insert) {
   
    // find new tasks
    for (Task t : trigger.new) {
        if (t.type=='Email') {
            // update record type
            RecordType rt = [select Id from RecordType where Name = 'Email' and SobjectType = 'Task' limit 1];
            t.RecordType.Id = rt.Id;
        } // end if task needs update
    } // end loop through tasks
}

 

I'm assuming that no record type is being found but checked and there is a task record type called email. I tried to only run t.RecordType.Id = rt.Id if rt.Id was not null - still the same error. 

 

Any assistance would be greatly appreciated.

  • April 13, 2012
  • Like
  • 0

I need to set up a rule where an email is triggered at 3pm PST today if a case was created before 9am today or tomorrow at 3pm tomorrow if the case was created after 9am.

 

I've been trying a few things. The latest idea is to use a workflow rule to set the "SLA Deadline" date/time field upon case creation. Here's what I tried:

 

if(VALUE(MID ( TEXT(CreatedDate), 12, 2)) < 17,
SUBSTITUTE(TEXT(CreatedDate), MID(TEXT(CreatedDate), 12, 2), '23'),
NOW())

 

(note: NOW() was just a stub I was using until I figured out the first part). The idea was to take the time portion of the field and replace it with 3 pm.

 

so, the issue I'm having is that the second line (SUBSTITUTE) isn't a Date/Time value. I've tried using "DATEVALUE" before this line but that converts it to Date, not Date/Time.

 

Any ideas how I can construct a date/time field using a formula? Or ideas on how I can do this a different way?

  • March 15, 2010
  • Like
  • 0

We would like to have a field called "Proper Account Name" and "Account Site" that then validates to become the Account Name so that we can easily select the correct account in searches and lead conversion (for instance, we might have 2 branches of 1 bank with the proper name being the bank name and the site being the branch name so Account Name would be "Bank Name - Branch Name").

 

I've set that up with a validation rule no problem but now the issue is making "Account Name" read only (or hidden). So far, the only solution I can come up with is create a VisualForce page that has account name hidden and defaulting to anything (e.g. just "x" as the name will be updated upon saving). Don't know how to do the default value but have posted in the developer community about that.

 

 My question is, is there an easier way to tackle this problem? The issue is, we will have many accounts with the same name and would like to have the proper name for mail merges and the name/site for searches with the least amount of data entry and manual rule adherance required by our users.

  • May 19, 2009
  • Like
  • 0

I'm creating a Visualforce page because we are going to be creating "Account Name" based on a custom field "Proper Account Name" and "Account Site", using workflow field update rules. If I don't create the page, then Account Name is required but then gets overridden upon saving the account. The purpose of the visualforce page is to replace the "New" account button and display all fields EXCEPT Account Name. Account Name will be hidden and default to any value. I just can't figure out for the life of me how to set the Account Name value. Any help appreciated. Rather new to this and wanted to wait a few months before starting to use this but this requirement is too important to ignore for now.... Any other suggestions on how to skin this cat are also appreciated...

 


 
<apex:page standardController="Account">
<apex:form > <apex:pageBlock title="Edit Account"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:pageBlockSection > <apex:inputHidden value="{!account.name}" /> <apex:inputField value="{!account.Site}" /> <apex:inputField value="{!account.Proper_Account_Name__c}" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
</apex:page>

 

 

  • May 19, 2009
  • Like
  • 0

Hi all, I'm very new to Apex and this is my first trigger. Thought it was quite simple but I'm getting the following error:

 

Validation Errors While Saving Record(s)

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Task_AfterInsert caused an unexpected exception, contact your administrator: Task_AfterInsert: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.Task_AfterInsert: line 18, column 1". 

 

The code is:

trigger Task_AfterInsert on Task (after insert) {
   
    // find new tasks
    for (Task t : trigger.new) {
        if (t.type=='Email') {
            // update record type
            RecordType rt = [select Id from RecordType where Name = 'Email' and SobjectType = 'Task' limit 1];
            t.RecordType.Id = rt.Id;
        } // end if task needs update
    } // end loop through tasks
}

 

I'm assuming that no record type is being found but checked and there is a task record type called email. I tried to only run t.RecordType.Id = rt.Id if rt.Id was not null - still the same error. 

 

Any assistance would be greatly appreciated.

  • April 13, 2012
  • Like
  • 0

We recently added a validation rule that requries a Rich Text Field to be filled in when the object is completed. This object is "Implementation" and the field is "Transition_Notes__c"

 

In my test classes where I have completed Implementation objects I've attempted to add Transition_Notes__c so the Validation rule doesn't impact my test class.

 

When I do this, I get "

Error: Compile Error: Invalid field Transition_Notes__c for SObject Implementation__c at line 56 column 9 

"

 

Normally I see this error when I make a typo. I've tried copy and pasting the API name. I've done this using the Apex Class GUI editor in Salesforce. I also tried the IDE in Eclipse using the auto-complete feature. And I still get this error.

 

Here's a snippet:

 

Implementation__c CompletedI1 = new Implementation__c();

        CompletedI1.Stage__c = 'Live (completed)'; 
        CompletedI1.Status__c = 'Completed';
        CompletedI1.Actual_live_Date__c = date.Today();
        CompletedI1.Completed_Date__c = date.Today();
        CompletedI1.Imp_Survey_Recipient__c = c1.id;
        CompletedI1.Transition_Notes__c = 'Filled in';
        update CompletedI1;

 I know the API name is right. I know it's attached to the right variable of the SObject. I can see the field in the Schema. What's going on?

I have a customer portal that uses a web address like for sign-in and similar salesforce.com URLs for inner pages:

https://emea.salesforce.com/secur/login_portal.jsp?orgId=00D000000Av&portalId=060200000 

 

How do I configure it so it looks like this:

customers.mydomain.com

 

I saw an Ideas entry where many people asked for this, and it was marked as Existing Feature, but I can't find any mention in the help, or the forums on how to implement this.

 

We would like to have a field called "Proper Account Name" and "Account Site" that then validates to become the Account Name so that we can easily select the correct account in searches and lead conversion (for instance, we might have 2 branches of 1 bank with the proper name being the bank name and the site being the branch name so Account Name would be "Bank Name - Branch Name").

 

I've set that up with a validation rule no problem but now the issue is making "Account Name" read only (or hidden). So far, the only solution I can come up with is create a VisualForce page that has account name hidden and defaulting to anything (e.g. just "x" as the name will be updated upon saving). Don't know how to do the default value but have posted in the developer community about that.

 

 My question is, is there an easier way to tackle this problem? The issue is, we will have many accounts with the same name and would like to have the proper name for mail merges and the name/site for searches with the least amount of data entry and manual rule adherance required by our users.

  • May 19, 2009
  • Like
  • 0

I'm creating a Visualforce page because we are going to be creating "Account Name" based on a custom field "Proper Account Name" and "Account Site", using workflow field update rules. If I don't create the page, then Account Name is required but then gets overridden upon saving the account. The purpose of the visualforce page is to replace the "New" account button and display all fields EXCEPT Account Name. Account Name will be hidden and default to any value. I just can't figure out for the life of me how to set the Account Name value. Any help appreciated. Rather new to this and wanted to wait a few months before starting to use this but this requirement is too important to ignore for now.... Any other suggestions on how to skin this cat are also appreciated...

 


 
<apex:page standardController="Account">
<apex:form > <apex:pageBlock title="Edit Account"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:pageBlockSection > <apex:inputHidden value="{!account.name}" /> <apex:inputField value="{!account.Site}" /> <apex:inputField value="{!account.Proper_Account_Name__c}" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
</apex:page>

 

 

  • May 19, 2009
  • Like
  • 0

I've searched around, but I can't find a solution to this:

In an effort to bypass the fact the Opportunity Products cannot be referenced in a formula, I'm attempting to use a Roll-Up Summary field, but its not working as I had hoped. My steps are:

1) In "Products", there is a Customer Checkbox labeled "Beta"

2) In "Opportunity Products", there is a Custom Number (0 decimal places)  Formula field named "Betalook". The formula states:

IF(PricebookEntry.Product2.Beta__c,1,0)

 So, any "Opportunity Product" entry whose Price Book item has the "Beta" box checked will show a 1 in this field, and a 0 otherwise.

 

In "Opportunities", I want to create a Custom Roll-Up Summary field ("Betacount") that will count the number of Opportunity Product entries that have a 1 in the "Betalook" field.

1) I start a new Custom Field in Opportunity, choosing "Roll-Up Summary" as the type

2) I name it "Betacount"

3) I choose "Opportunity Product" as the Summarized Object and "COUNT" as the Roll-Up Type.

4) I choose the "Only records meeting certain criteria..." radio button.

The problem is that in my choices for "Field" in the criteria, the "Betalook" field is not available. It is also not an available field in the "Field to aggregate" picklist if I choose SUM, MIN, or MAX. The Roll-Up Summary help files states: "Roll-up summary fields can calculate the values of formula fields if they do not contain functions that automatically derive values on the fly, such as NOW or TODAY." So, why can't I filter on the field? Any help would be greatly appreciated.

 

 

I would like to display a default name in the opportunity edit view. Normally I do overwrite the new button with a S-Control and set the opp3 Parameter to that name.
But what if the Opportunity has different RecordTypes? Because I need the RecordType to pass along I tried to access the url in the S-Control with window.location.href but this gives me a "/servlet/servlet.Integration..." URL instead of the "...&RecordType=....".

Any idea how to solve this problem?
  • May 07, 2008
  • Like
  • 0