• AlecS
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 16
    Replies

I have written trigegrs in my sandbox environment.

 

I did not realize that I have to write test cases for these triggers until I started looking to move them to production.

 

What's the quickest way to learn how to write test cases for moving code to production.

 

Thank you.

 

 

  • March 06, 2013
  • Like
  • 0

I just finished writing and testing few triggers in sandbox. How do I move them to production system?

 

I get an error message:

Entity_Is_Locked

 
  • February 23, 2013
  • Like
  • 0

I just finished writing and testing few triggers in sandbox. How do I move them to production system?

 

I get an error message:

Entity_Is_Locked

 
  • February 23, 2013
  • Like
  • 0

I have a trigger that does some work when the opportunity is closed with stage=close won. But my code also checks to make sure that if I am editing an opportunity that is saved with stage=close won (that is trigger.old has stage = close won) then it should not carry out the task.

 

Trigger createRenewalOpp on opportunity(after update){

    List<Opportunity> oppList = new List<Opportunity>();
    
    //making sure that the opportunity is not already closewon
    for(Opportunity p : trigger.old) {
          if(p.stageName !='Closed Won' ){

//execute code
}
}
}

 

The problem with above code is that if I create a new opportunity and close it starught away with stage = close won (meaning trigger.old has no value) then the code following the "if" statement does not execute.

 

How can I check to create an exception for such a scenario?

 

Thank you!

 

  • February 15, 2013
  • Like
  • 0

I have an Apex page that defines the format of  a date field.

 

<apex:page standardController="Invoice__c" extensions="ApexButtonPageController" action="{!doMyApexLogic}">

<apex:outputText value=" {0,date,MM.dd.yyy}">
<apex:param value="{!Invoice__c.Invoice_Due_Date__c}" /> 

</apex:outputText>
</apex:page>

 However, the output of the date field, Invoice__c.Invoice_Due_Date__c is 

 

2013-03-11 00:00:00

 

How can I fix this?

 

Thank you.

  • February 12, 2013
  • Like
  • 0

I have an Opportunity trigger. The trigger checks for the old value of the opportunity, specially the StageName=ClosedWon.

 

However, if I click on "New" opportunity and ClosedWon the opportunity the first time itself, the checking fails, because there's no old value at all for such opportunity.

 

How do I catch and fix this?

 

Thanks!

  • February 11, 2013
  • Like
  • 0

I have a custom object called Invoice.

 

I want to create a new Task under this object.

 

I have this code:

Note inv_note = new Note();
	     inv_note.ID = theInvoice.id;
            inv_note.Title = theInvoice.Invoice_Name__c+' invoice emailed';
            inv_note.body = 'Invoice emailed';
        insert inv_note;
        

 This is the error message that I get:


Invalid id value for this SObject type: a07W0000000kJQMIA2

Error is in expression '{!doMyApexLogic}' in component <apex:page> in page apexbuttonpage
 
Thanks for your help!
  • February 11, 2013
  • Like
  • 0

I have a custom object Invoice. I want that when a certain action is performed, it must keep track of that task under that object.

 

I have this code in one of my class to create the task.

 

Task inv_task = new Task();
	    inv_task.WhatId = theInvoice.id;
            inv_task.WhoId = theInvoice.Contract__r.Name;
            inv_task.Subject = 'Invoice Emailed';
            inv_task.status = 'Completed';
            inv_task.description = 'Invoice emailed';
 insert inv_task;
        

 But I get this error message:

 

Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Contact/Lead ID: id value of incorrect type: 00530000000cIRWAA2: [WhoId]

Error is in expression '{!doMyApexLogic}' in component <apex:page> in page apexbuttonpage
 
How can I create a task. Please help!
 
Thanks!
  • February 10, 2013
  • Like
  • 0

I have an Apex class that is trying to get information from my custom object Invoice and send an email.

 

However, I get this error message:

SObject row was retrieved via SOQL without querying the requested field: Invoice__c.Invoice_Due_Date__c
Error is in expression '{!doMyApexLogic}' in component <apex:page> in page apexbuttonpage

 My code is here:

 

public class ApexButtonPageController {
    Invoice__c theInvoice;
    

    public ApexButtonPageController(ApexPages.StandardController stdController) {
        // get the current Invoice
        theInvoice = (Invoice__c)stdController.getRecord();
    }

    public PageReference doMyApexLogic() {
        //logic to send email out
        
        
        
        // First, reserve email capacity for the current Apex transaction to ensure
                        
// that we won't exceed our daily email limits when sending email after
                        
// the current transaction is committed.
Messaging.reserveSingleEmailCapacity(2);

// Processes and actions involved in the Apex transaction occur next,
// which conclude with sending a single email.

// Now create a new single email message object
// that will send out a single email to the addresses in the To, CC & BCC list.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

// Strings to hold the email addresses to which you are sending the email.
String[] toAddresses = new String[] {'name@domain.com'}; 
  

// Assign the addresses for the To and CC lists to the mail object.
mail.setToAddresses(toAddresses);

// Specify the address used when the recipients reply to the email. 
mail.setReplyTo('test@test.com');

// Specify the name used as the display name.
mail.setSenderDisplayName('Billing');

// Specify the subject line for your email address.
mail.setSubject('Invoice');

// Set BCC as false
mail.setBccSender(false);

// Optionally append the salesforce.com email signature to the email.
// The email address of the user executing the Apex Code will be used.
mail.setUseSignature(false);


mail.setHtmlBody('Dear theInvoice.Email_Invoice_To__c <p>'+
     'Please find attached the invoice on your account that will be due on'+ theInvoice.Invoice_Due_Date__c+'.<p>'+
                'The invoice summary is as follows:<p>'+
'Account Name'+                      theInvoice.Account_Name__c+'<p>'+
'Contract Number'+                   theInvoice.Contract__c+'<p>'+

'Invoice Date'+                      theInvoice.Targeted_Date__c+'<p>'+
//'Invoice Due Date                  {!Invoice__c.Targeted_Date__c}<p>'+
//Invoice Number                    {!Invoice__c.Invoice__c}
//Invoice Amount                    USD {!Invoice__c.Amount_Invoiced__c}

'');

// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });      
        
        
        update theInvoice;
        //</demo logic>
        return new PageReference('/' + theInvoice.id);
    }
}

 

  • February 08, 2013
  • Like
  • 0

Whenever, I activate a Contract, a trigger is executed and creates a custom object called Invoice__c. I am able to copy all the values from Contract to Invoice__c EXCEPT for the RecordType. 

 

RecordType is a standard field present in ALL objects. How can I copy the RecordType of Contract to the RecordType of Invoice__c? I just need this code.

 

Thanks.

  • January 17, 2013
  • Like
  • 0

I have written a trigger on Opportunity that creates another copy of the Opportunity at close time for renewal business.

 

However, this renewal opportunity should be owned by another user, let's say, Alec Sewart.

 

I have tried all these codes, but they don't work. How can I assign all renewal opportunity to Alec Stewart through trigger.

 

//option 1:
opp.OwnerId = [SELECT Id, name FROM User WHERE Name = 'Alec Stewart'].id;

//option 2:
opp.Owner.Name =  'Alec Stewart';

//option 3:
opp.Owner.FirstName = [select FirstName from User where name = 'Alec Stewart'].FirstName;
opp.Owner.LastName = [select LastName from User where name = 'Alec Stewart'].LastName;

 

 

Thanks.

  • January 15, 2013
  • Like
  • 0

I am trying to assign the Record Type of Opportunity to the Record Type of Contract being created.

 

Within the Opportunity object, there's a standard field called RecordType. However, when I assign this value

 

con.RecordType = opp.RecordType;

 

I get this error message:

 

Error: Compile Error: No such column 'RecordType' on entity 'Opportunity'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 4 column 22

 

How can I resolve this?

 

Thank you!

  • January 14, 2013
  • Like
  • 0

Within this code, I want to check what's the OLD value of the field Status. This code gives me this error message:


Error: Compile Error: Method does not exist or incorrect signature: [LIST<Contract>].get(String) at line 4 column 70

 

I know that this is not a complete code - I just need someone to look at this part of the code and tell me how can I quickly check what is the old value of con.Status.

 

How can I fix this?

 

for(Contract con : trigger.new){
        if(con.Contract_Years__c != null && trigger.old.get(con.Status) != 'Active')

 

Thank you.

  • January 10, 2013
  • Like
  • 0

Here's my scenario.

 

I have a custome object called Invoice__c.

 

When my Contract is activated, I want to create as many Invoice__c objects as there are years in the contract. That is, if I have a 3 year contract, then I should create 3 Invoice__c objects after Contract is activated.

 

How can I do that? 

 

I am able to create one intance of the Invoice__c object. I am having issues creating multiple objects. 

 

Thanks a lot!

  • January 10, 2013
  • Like
  • 0

I have an Opportunity trigger. I want to assign the opportunity ownership to another person 

 

I have tried:

 

 opp.Owner.Name = 'Jack Smith';

and

opp.OwnerId = '00550000001ZszE'

 

None of these work.

 

How can I assign opportunity to another user?

 

Thanks!

  • January 09, 2013
  • Like
  • 0

I have an Opportunity trigger. I want to assign the opportunity ownership to another person 

 

I have tried:

 

 opp.Owner.Name = 'Jack Smith';

and

opp.OwnerId = '00550000001ZszE'

 

None of these work.

 

How can I assign opportunity to another user?

 

Thanks!

  • January 09, 2013
  • Like
  • 0

Hello,

 

I want to assign values to variables on the fly. For example, I have a variable called, YearXDate. X is a number from 1 to n. I want to assign values to YearXDate while in a loop where loop variable is from 1 to n. How do I do that?

 

Thanks!

  • January 04, 2013
  • Like
  • 0

Using trigger, I am trying to create a renewal opportunity the moment a new opportunity is closed won. However, each Opportunity name is unique. The way I make them unique is by giving the name as follows:

Opportunity Name = [Account Name - <contract start year> to <contract end year>]

Example: Abc Corp - 2012 - 2013

 

I am having a tough time copying the Account Name to a string value. If I try to read the string value of the Account name, I get the 15 digit ID.

 

How can I get the Account name, like "Abc Corp".

 

Thanks!

  • December 26, 2012
  • Like
  • 0

I have an Apex page that defines the format of  a date field.

 

<apex:page standardController="Invoice__c" extensions="ApexButtonPageController" action="{!doMyApexLogic}">

<apex:outputText value=" {0,date,MM.dd.yyy}">
<apex:param value="{!Invoice__c.Invoice_Due_Date__c}" /> 

</apex:outputText>
</apex:page>

 However, the output of the date field, Invoice__c.Invoice_Due_Date__c is 

 

2013-03-11 00:00:00

 

How can I fix this?

 

Thank you.

  • February 12, 2013
  • Like
  • 0

I have a custom object called Invoice.

 

I want to create a new Task under this object.

 

I have this code:

Note inv_note = new Note();
	     inv_note.ID = theInvoice.id;
            inv_note.Title = theInvoice.Invoice_Name__c+' invoice emailed';
            inv_note.body = 'Invoice emailed';
        insert inv_note;
        

 This is the error message that I get:


Invalid id value for this SObject type: a07W0000000kJQMIA2

Error is in expression '{!doMyApexLogic}' in component <apex:page> in page apexbuttonpage
 
Thanks for your help!
  • February 11, 2013
  • Like
  • 0

I have a custom object Invoice. I want that when a certain action is performed, it must keep track of that task under that object.

 

I have this code in one of my class to create the task.

 

Task inv_task = new Task();
	    inv_task.WhatId = theInvoice.id;
            inv_task.WhoId = theInvoice.Contract__r.Name;
            inv_task.Subject = 'Invoice Emailed';
            inv_task.status = 'Completed';
            inv_task.description = 'Invoice emailed';
 insert inv_task;
        

 But I get this error message:

 

Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Contact/Lead ID: id value of incorrect type: 00530000000cIRWAA2: [WhoId]

Error is in expression '{!doMyApexLogic}' in component <apex:page> in page apexbuttonpage
 
How can I create a task. Please help!
 
Thanks!
  • February 10, 2013
  • Like
  • 0

I have an Apex class that is trying to get information from my custom object Invoice and send an email.

 

However, I get this error message:

SObject row was retrieved via SOQL without querying the requested field: Invoice__c.Invoice_Due_Date__c
Error is in expression '{!doMyApexLogic}' in component <apex:page> in page apexbuttonpage

 My code is here:

 

public class ApexButtonPageController {
    Invoice__c theInvoice;
    

    public ApexButtonPageController(ApexPages.StandardController stdController) {
        // get the current Invoice
        theInvoice = (Invoice__c)stdController.getRecord();
    }

    public PageReference doMyApexLogic() {
        //logic to send email out
        
        
        
        // First, reserve email capacity for the current Apex transaction to ensure
                        
// that we won't exceed our daily email limits when sending email after
                        
// the current transaction is committed.
Messaging.reserveSingleEmailCapacity(2);

// Processes and actions involved in the Apex transaction occur next,
// which conclude with sending a single email.

// Now create a new single email message object
// that will send out a single email to the addresses in the To, CC & BCC list.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

// Strings to hold the email addresses to which you are sending the email.
String[] toAddresses = new String[] {'name@domain.com'}; 
  

// Assign the addresses for the To and CC lists to the mail object.
mail.setToAddresses(toAddresses);

// Specify the address used when the recipients reply to the email. 
mail.setReplyTo('test@test.com');

// Specify the name used as the display name.
mail.setSenderDisplayName('Billing');

// Specify the subject line for your email address.
mail.setSubject('Invoice');

// Set BCC as false
mail.setBccSender(false);

// Optionally append the salesforce.com email signature to the email.
// The email address of the user executing the Apex Code will be used.
mail.setUseSignature(false);


mail.setHtmlBody('Dear theInvoice.Email_Invoice_To__c <p>'+
     'Please find attached the invoice on your account that will be due on'+ theInvoice.Invoice_Due_Date__c+'.<p>'+
                'The invoice summary is as follows:<p>'+
'Account Name'+                      theInvoice.Account_Name__c+'<p>'+
'Contract Number'+                   theInvoice.Contract__c+'<p>'+

'Invoice Date'+                      theInvoice.Targeted_Date__c+'<p>'+
//'Invoice Due Date                  {!Invoice__c.Targeted_Date__c}<p>'+
//Invoice Number                    {!Invoice__c.Invoice__c}
//Invoice Amount                    USD {!Invoice__c.Amount_Invoiced__c}

'');

// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });      
        
        
        update theInvoice;
        //</demo logic>
        return new PageReference('/' + theInvoice.id);
    }
}

 

  • February 08, 2013
  • Like
  • 0

I have written a trigger on Opportunity that creates another copy of the Opportunity at close time for renewal business.

 

However, this renewal opportunity should be owned by another user, let's say, Alec Sewart.

 

I have tried all these codes, but they don't work. How can I assign all renewal opportunity to Alec Stewart through trigger.

 

//option 1:
opp.OwnerId = [SELECT Id, name FROM User WHERE Name = 'Alec Stewart'].id;

//option 2:
opp.Owner.Name =  'Alec Stewart';

//option 3:
opp.Owner.FirstName = [select FirstName from User where name = 'Alec Stewart'].FirstName;
opp.Owner.LastName = [select LastName from User where name = 'Alec Stewart'].LastName;

 

 

Thanks.

  • January 15, 2013
  • Like
  • 0

I am trying to assign the Record Type of Opportunity to the Record Type of Contract being created.

 

Within the Opportunity object, there's a standard field called RecordType. However, when I assign this value

 

con.RecordType = opp.RecordType;

 

I get this error message:

 

Error: Compile Error: No such column 'RecordType' on entity 'Opportunity'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 4 column 22

 

How can I resolve this?

 

Thank you!

  • January 14, 2013
  • Like
  • 0

Within this code, I want to check what's the OLD value of the field Status. This code gives me this error message:


Error: Compile Error: Method does not exist or incorrect signature: [LIST<Contract>].get(String) at line 4 column 70

 

I know that this is not a complete code - I just need someone to look at this part of the code and tell me how can I quickly check what is the old value of con.Status.

 

How can I fix this?

 

for(Contract con : trigger.new){
        if(con.Contract_Years__c != null && trigger.old.get(con.Status) != 'Active')

 

Thank you.

  • January 10, 2013
  • Like
  • 0

Here's my scenario.

 

I have a custome object called Invoice__c.

 

When my Contract is activated, I want to create as many Invoice__c objects as there are years in the contract. That is, if I have a 3 year contract, then I should create 3 Invoice__c objects after Contract is activated.

 

How can I do that? 

 

I am able to create one intance of the Invoice__c object. I am having issues creating multiple objects. 

 

Thanks a lot!

  • January 10, 2013
  • Like
  • 0

Using trigger, I am trying to create a renewal opportunity the moment a new opportunity is closed won. However, each Opportunity name is unique. The way I make them unique is by giving the name as follows:

Opportunity Name = [Account Name - <contract start year> to <contract end year>]

Example: Abc Corp - 2012 - 2013

 

I am having a tough time copying the Account Name to a string value. If I try to read the string value of the Account name, I get the 15 digit ID.

 

How can I get the Account name, like "Abc Corp".

 

Thanks!

  • December 26, 2012
  • Like
  • 0