• AlsoDoug
  • NEWBIE
  • 249 Points
  • Member since 2009

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

Hi,

 

I am currently trying to update a field on an opportunity record after the opportunity has been inserted or updated from the opportunity owners - user record.  I really don't know what I am doing but this is what I have pieced together.

 

 

This is the trigger

 

trigger InsuranceUpdate on Opportunity (after insert, after update) { for (Opportunity o : Trigger.new){ User u =[Select IS_Consultant__c from User Where Id=: o.OwnerId]; o.Iteam_Member__c = o.Owner.IS_Consultant__c; } }

 

 

This is the test class

public class testOpp{ static testMethod void InsuranceUpdate() { //find the test opp //flip it's status and update // Opportunity opp = new Opportunity(); opp.Name= 'JD Nordberg30'; opp.StageName = 'Active'; opp.CloseDate = Date.today(); insert opp; for (Opportunity o : [SELECT Id FROM Opportunity WHERE Name = 'JD Nordberg30']) { o.StageName = 'Prospect' ; update o; } } }

 

 

I am receiving the error below 

 

 

Description Resource Path Location Type System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, InsuranceUpdate: execution of AfterInsert caused by: System.Exception: Record is read-only Trigger.InsuranceUpdate: line 4, column 9: [] testOpp.cls InsuranceUpdate/src/classes line 11 Force.com run test failure

 


 

 

Also, how do I run a test of my code in eclipse?

 

Any help would be great


 

 

I am tring to write my first test class for an apex trigger and am having a tough time understanding what needs to be tested. Below is my trigger:

 

trigger setTaskDueDate on Task (before insert, before update) {

   Task[] tasks = trigger.new;

   for (integer i = 0; i < tasks.size(); i++) {
      Task ntask = tasks[i];
      ntask.Due_Date__c = nTask.ActivityDate;
   }

 

 

May I have any direction?

I have custom objects save command button on my page. Whenever I hit the enter key, the save command button is getting exectued and I want to avoid this. Instead, whenever a enter key is entered, I want the cursor to go the next corresponding field or in other words, I want to have control over enter key..how can I achieve it?
Message Edited by mallikam on 07-09-2009 09:38 AM

I cannot seem to find resources about how to set ApexPages parameters for unit tests.

 

I have a controller similar to:

 

public class MyCustomController {

public class visualForceException extends Exception {}

public MyCustomController() {
// if there is no 'id' parameter, throw error and return
if (ApexPages.currentPage().getParameters().get('id') == null) {
ApexPages.addMessages(new visualForceException('Error: No ID specified.'));

return;
}

 

// ... do other stuff here
}

}

 

Here, the constructor will check if there is an 'id' parameter in the current page.

 

My problem is... how do I set the ApexPages 'id' parameter in my TEST class?

 

Message Edited by AlexPHP on 07-08-2009 02:40 PM

I have a slight dilemma that Im hoping you call all help me with.  I have a need to call a method from another method, but am not sure how to do so. 

I need the save method to update my custom object before I can have the getupdClaseList method execute successfully.  Both are in the same class, as an extension the controller on a VisualFoce page. 

 

What I would like to happen is that the getupdCaseList method is called after the user clicks the save button (Save method).


Any ideas/tips?

 

 Save method

 

// Save method public pagereference saveChanges() { update myProject; //return null; PageReference pageRef = new PageReference('/apex/editNewProject?id='+myProject.Id); pageRef.setRedirect(true); return pageRef; }

 

 getupdCaselList Method

 

// Calc new days public List<Case> getupdCaseList(){ if(myProject.Id<>Null){ myCaseList = [select Id, Date_Du__c, Internal_Date_Due__c from Case where Project__c = :myProject.Id]; // Set date veriables OCD= myProject.Original_Completion_Date__c; TCD= myProject.Target_Completion_Date__c; // loop through and update case details system.debug(OCD); system.debug(TCD); dayOffset = OCD.daysBetween(TCD); system.debug(dayOffset); for(Case myCaseListItem:myCaseList) { Case newCase = myCaseListItem; newCase.Date_Du__c = myCaseListItem.Date_Du__c + dayOffset; newCase.Internal_Date_Due__c = myCaseListItem.Internal_Date_Due__c + dayOffset; upsert newCase; } //for loop } // myClaseList select return null; } // getmyCalseList method

 

 

 

 

 

Hello,
 
I have a method that returns a List<SelectOption> containing a list of months to be used in a menu on a VF page. I'm still new to writing Apex code and I can't figure out what the correct way to write the test method for this is. If I run tests on the following code I get this error:
 
 

System.Exception: Assertion Failed: Expected: (System.SelectOption[value="01", label="Jan", disabled="false"], System.SelectOption[value="02", label="Feb", disabled="false"], System.SelectOption[value="03", label="Mar", disabled="false"], System.SelectOption[value="04", label="Apr", disabled="false"], System.SelectOption[value="05", label="May", disabled="false"], System.SelectOption[value="06", label="Jun", disabled="false"], System.SelectOption[value="07", label="Jul", disabled="false"], System.SelectOption[value="08", label="Aug", disabled="false"], System.SelectOption[value="09", label="Sep", disabled="false"], System.SelectOption[value="10", label="Oct", disabled="false"], ...), Actual: (System.SelectOption[value="01", label="Jan", disabled="false"], System.SelectOption[value="02", label="Feb", disabled="false"], System.SelectOption[value="03", label="Mar", disabled="false"], System.SelectOption[value="04", label="Apr", disabled="false"], System.SelectOption[value="05", label="May", disabled="false"], System.SelectOption[value="06", label="Jun", disabled="false"], System.SelectOption[value="07", label="Jul", disabled="false"], System.SelectOption[value="08", label="Aug", disabled="false"], System.SelectOption[value="09", label="Sep", disabled="false"], System.SelectOption[value="10", label="Oct", disabled="false"], ...)

 

 

public class Months {

public List<SelectOption> getMonthList() {

List<SelectOption> options = new List<SelectOption>();

options.add(new SelectOption('01', 'Jan'));

options.add(new SelectOption('02', 'Feb'));

options.add(new SelectOption('03', 'Mar'));

options.add(new SelectOption('04', 'Apr'));

options.add(new SelectOption('05', 'May'));

options.add(new SelectOption('06', 'Jun'));

options.add(new SelectOption('07', 'Jul'));

options.add(new SelectOption('08', 'Aug'));

options.add(new SelectOption('09', 'Sep'));

options.add(new SelectOption('10', 'Oct'));

options.add(new SelectOption('11', 'Nov'));

options.add(new SelectOption('12', 'Dec'));

return options;

}

 

static testMethod void testMonthList() {

List<SelectOption> test_options = new List<SelectOption>();

test_options.add(new SelectOption('01', 'Jan'));

test_options.add(new SelectOption('02', 'Feb'));

test_options.add(new SelectOption('03', 'Mar'));

test_options.add(new SelectOption('04', 'Apr'));

test_options.add(new SelectOption('05', 'May'));

test_options.add(new SelectOption('06', 'Jun'));

test_options.add(new SelectOption('07', 'Jul'));

test_options.add(new SelectOption('08', 'Aug'));

test_options.add(new SelectOption('09', 'Sep'));

test_options.add(new SelectOption('10', 'Oct'));

test_options.add(new SelectOption('11', 'Nov'));

test_options.add(new SelectOption('12', 'Dec'));

 

Months my_months = new Months();

List<SelectOption> method_options = my_months.getMonthList();

 

system.assertEquals(method_options, test_options);

}

}

 

I copied/pasted the 'expected' and 'actual' responses to a text editor and they look identical to me. Is there another way I should be writing this test?
 
Thanks,
Dan 
 
 
 
 
  • June 30, 2009
  • Like
  • 0

Hello everyone

 

I've this button

 

<apex:commandButton action="{!botones}" value="go from {!Status} to the following Status" id="addButton1" />              
 

If the Status is NULL, I've a button with the value = go from  to the following Status

 

I don't want to show the button if the Status is NULL so, any idea?!?!?

 

Thank you in advance

Hi,

 

I wanted to know if it is feasible to access the org id of my salesforce org (without  querying the Organization table) in an Apex Class. Something similar to what we do in VisualForce using the {!$organization.id} global field.

 

Thanks,

Heena

  • April 07, 2009
  • Like
  • 0

I'm at a loss to figure this one out.  When trying to save various files (it applies to all of them), Eclipse isn't even attempting to Save up to the Server.  It use to try to Save and only if it encountered an error would it Save Locally and report the error. 

Now, its only saves locally with no errors and only warnings with a description of "File only saved locally, not to server".  The only way I can save a file to the server is manually right-click on the file and choose Force.com \ Save to Server.  And this works fine but its maddening to now have to do this for every file.

 

Something is not right and I'd be grateful if some knows the solution!

 

Thanks in advance

I have read the cookbook and see that I can use a trigger to block the creation of a record by throwing an error.

 

Is there a way to do it without throwing the error?

 

I need on creation of a task to check certain values and if they sync up I have to create a different object and not save (or delete after insert which doesn't seem possible) the original task.

 

Thanks

Doug

 

I have seen a couple of ideas in the idea area about adding a documentation generator which would be great but I need something now

 

Any one had any luck finding/using  any tools for this? 

 

I am looking at a couple now just figured I would check and see if anyone else has found anything as of yet.

 

thanks

Doug

 

I have gone into the setup and in the buttons and links section overridden the View/New/Edit for Event.

 

This override doesn't appear to be working everywhere.

 

On the homepage with the calendar the New Event button override is not working.

 

If I Click on the Acitivty View List icon on the Calendar and use the New Event button the Activity List the override works.

 

So something is going on here that I am not understanding.

 

Anyone got any ideas? 

 

Is the New Event button on Home Page Calendar different?

I have tried using readOnly on a selectCheckBoxes


IE

 

<apex:selectCheckboxes value="{!defaultValue}" readOnly="true"> <apex:selectOptions value="{!possiblevalues}"/> </apex:selectCheckboxes>

 

Doesn't appear to do anything.

 

Seems simple enough but no joy.

 

Work for anyone?

As always I have searched the board, documentation etc before posting.

 

I am pretty sure the answer will be no, but I present the question anyway with a vague glimmer of hope.

 

We have a custom object called Address that is a child of Account.

 

It has a field called Primary.

 

We only want to have one child address of an account to have primary=true at anyone point in time.

 

I know I can do this with a trigger.

 

The problem is that when a user attempts to change an address to primary we would like to notify (via pop up) the user that this address was not primary and changing it to such will remove the primary from some other address.

 

And this has to be done in a standard Salesforce (IE not Visual Force) page.

 

Any one have any ideas beyond it would be easier to do it as a Visual Force page?

 

Thanks

Doug

 

This there anyway to use a custom query with enhancedList component?

 

I have searched through forums etc and while it seems others have had same/similar question I haven't found a definite answer one way or the other.

 

I did find this

 

http://ideas.salesforce.com/article/show/10094251/Smarter_Lists__Enhanced_lists_by_runtime_SOQL

 

Which makes me think no.

 

Thanks

Doug

Sorry newbie with what is probably a newbie question.

 

When I am writing what I gather is defined as "dynamic" SOQL is there an equivalent to SQL 1=1.

 

I won't claim or defend that this is even best practice in SQL but it is convenient.

 

Thanks

Doug

 

 

I am having trouble creating a solution for this request.

 

I am looking to update specific account fields (text, picklist, url fields) based on the originating fields inside the contact. In this many-to-one situation, I need to pull the most recently updated field out of the contacts group and the oldest field out of the same group and bring it into the account. 

 

ex. 

Account and Contact Field: Most_recent_visit__c

Contact 1 = Most recent visit = 11/11/09 so the account would need to be updated to that. 

 

Contact 2 comes in and his most recent visit was 11/15/09, now I would need the Account field to be updated to 11/15/09.

 

All help is appreciated. 

 

This also would need to apply to fields like a text field or a picklist

  • August 30, 2009
  • Like
  • 0

Hi all,

 
I'm trying to add the following check to an on-click piece of JavaScript in a button (to restrict access to the button).  My condition in the "IF" isn't working right, anyone see why?

 

if({!User.ProfileId} <> '00e00000006ojvr'){ alert("This feature is currently only available to Administrators."); } else{ ** Do stuff** }

 


 

Hello All,

 

I have been looking for a way to resolve edit conflicts through APEX.

 

For example:

 

User A opens a contact for edit

User B opens the same contact for edit

User A updates the contacts' title and saves

User B updates the contacts' phone number and saves

 

Normally this would produce an error message to user B saying that user A has editted the contact and ask user B to redo their work.

 

I would like to find a way to merge the changes. The two users have not made any changes which would be in conflict, so I want the change from user B to succeed. Is there a way to do this?

 

Thanks for you help.

 

what is the best path to migrate an existing web app to visual force; it uses html/js/php and mysql - from the looks i have seen so far, i don't hold much hope, please help, don't want to recode this app
  • August 26, 2009
  • Like
  • 0

Hello everyone!!!

 

I have done an APEX class. If I use this query;

 

 Contact C=[select Name from Contact where Id not in ('a0U80000001p4TEEAY,a0U80000001p4T9EAI')];

 

 It works! It gives me the Contacts I want!

 

But if I do this;

 

string help='a0U80000001p4TEEAY,a0U80000001p4T9EAI';

Contact C=[select Name from Contact where Id not in (:help)];

 

It doesn't work!

 

How do I pass parameters correctly?!?!?

 

Thanks in advance!!

Hi,

 

I am currently trying to update a field on an opportunity record after the opportunity has been inserted or updated from the opportunity owners - user record.  I really don't know what I am doing but this is what I have pieced together.

 

 

This is the trigger

 

trigger InsuranceUpdate on Opportunity (after insert, after update) { for (Opportunity o : Trigger.new){ User u =[Select IS_Consultant__c from User Where Id=: o.OwnerId]; o.Iteam_Member__c = o.Owner.IS_Consultant__c; } }

 

 

This is the test class

public class testOpp{ static testMethod void InsuranceUpdate() { //find the test opp //flip it's status and update // Opportunity opp = new Opportunity(); opp.Name= 'JD Nordberg30'; opp.StageName = 'Active'; opp.CloseDate = Date.today(); insert opp; for (Opportunity o : [SELECT Id FROM Opportunity WHERE Name = 'JD Nordberg30']) { o.StageName = 'Prospect' ; update o; } } }

 

 

I am receiving the error below 

 

 

Description Resource Path Location Type System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, InsuranceUpdate: execution of AfterInsert caused by: System.Exception: Record is read-only Trigger.InsuranceUpdate: line 4, column 9: [] testOpp.cls InsuranceUpdate/src/classes line 11 Force.com run test failure

 


 

 

Also, how do I run a test of my code in eclipse?

 

Any help would be great


 

 

I am tring to write my first test class for an apex trigger and am having a tough time understanding what needs to be tested. Below is my trigger:

 

trigger setTaskDueDate on Task (before insert, before update) {

   Task[] tasks = trigger.new;

   for (integer i = 0; i < tasks.size(); i++) {
      Task ntask = tasks[i];
      ntask.Due_Date__c = nTask.ActivityDate;
   }

 

 

May I have any direction?

Hi,

 

I need to ask u one question.

I have a bundled java code or say a python code.

Can deploy it on Force.com ie using the IDE or Migration toolkit.

 

 Can I just deploy applications build on Force.com ie a Apex or some visualforce pages.

 

Please reply .. As i am in a fix..

Can you please tell me or give me some documentation as how deployment is made easy in Force.com

 

Regards,

Diti

 

  • August 25, 2009
  • Like
  • 0

I have read the cookbook and see that I can use a trigger to block the creation of a record by throwing an error.

 

Is there a way to do it without throwing the error?

 

I need on creation of a task to check certain values and if they sync up I have to create a different object and not save (or delete after insert which doesn't seem possible) the original task.

 

Thanks

Doug

 

Hello Everyone,

 

First I want to say thanks for such a great forum, I have learned so much here and really appreciate the amazing feedback I always get. It is truly awesome to see the level of expertise out there willing to help us newbies!!!

 

If I might impose one more time on the greater mind-share out there to help me with the following problem, I would be really appreciative. I am a bit stumped, and have been trying to figure this out on my own for over a week with no success.

 

I have just started learning test classes, and have figured out how to instantiate an object and test strings. My issue is that I now have to test a more complex class that is way over my head - it has changing variables, inserts, etc.) and I have no idea how to test for that stuff? The code is below along with my non-test class (it doesn't actually test anything yet as I can't figure out how to set a concrete variable for this!). Any help at all would be appreciated.

 

Thanks in advance for helping me learn.

 

 

public class addSOA { ApexPages.StandardController controller; public addSOA (ApexPages.StandardController c) { controller = c;} public PageReference emailSOA() { // Get the opportunity Id and name Opportunity opportunity = [SELECT id, name,Opportunity_No__c FROM opportunity WHERE Id = :System.currentPageReference().getParameters().get('id')]; // Create PDF // Reference the page, pass in a parameter to force PDF PageReference pdf = new PageReference('/apex/SOApdf' + '?id=' + opportunity.id); pdf.getParameters().put('p','p'); pdf.setRedirect(true); // Grab the PDF! Blob b = pdf.getContent(); // Create the attachment against the Opportunity */ Attachment a = new Attachment(parentId = opportunity.id, name=opportunity.name + '-'+ opportunity.Opportunity_No__c+'-'+'SOA.pdf', body = b); // Insert the attachment insert a; // Create an email Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage (); email.setSaveAsActivity(true); email.setToAddresses(addresses); email.setSenderDisplayName('New Order'); email.setSubject('New SO Approval Created for Opportunity # ' + opportunity.Opportunity_No__c); email.setPlainTextBody('A new SO Approval has been created for ' + opportunity.Name +' , '+ opportunity.Opportunity_No__c+'. The SO Approval is attached.'); email.setHtmlBody('A new SO Approval has been created for' + '&nbsp;'+'<b>'+ opportunity.Name +'&nbsp;'+'</b>'+ opportunity.Opportunity_No__c+'. The SO Approval is attached.'+ ' To view this Opportunity <a href=https://na1.salesforce.com/'+ opportunity.Id +'><b>click here</b></a>'); // Create an email attachment Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment(); // Set name of PDF efa.setFileName(opportunity.Opportunity_No__c+'SOA.pdf'); // Set body of PDF efa.setBody(b); // Attach the PDF to your email email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); // Send email & return to Opportunity Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); // Send the user back to the opportunity detail page */ return controller.view(); } String[] addresses = new String[]{}; public List<SelectOption> getItems() { List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('aabimanan@krausglobal.com','Amu Abimanan')); options.add(new SelectOption('bfoster@krausglobal.com','Brian Foster')); options.add(new SelectOption('cdamiani@krausglobal.com','Chris Damiani')); options.add(new SelectOption('dpatel@krausglobal.com','Dev Patel')); options.add(new SelectOption('galdea@krausglobal.com','Gabriel Aldea')); options.add(new SelectOption('jwebb@krausglobal.com','Jason Webb')); options.add(new SelectOption('jdelcampo@krausglobal.com','Julian del Campo')); options.add(new SelectOption('mmandilaras@krausglobal.com','Manny Mandilaras')); options.add(new SelectOption('nestey@krausglobal.com','Norm Estey')); options.add(new SelectOption('ptopolnitsky@krausglobal.com','Penny Topolnitsky')); options.add(new SelectOption('rreimer@krausglobal.com','Roger Reimer')); options.add(new SelectOption('rdevisser@krausglobal.com','Ross Devisser')); options.add(new SelectOption('sbailey@krausglobal.com','Scott Bailey')); options.add(new SelectOption('slangan@krausglobal.com','Shannon Langan')); return options; } public String[] getAddresses() { return addresses; } public void setAddresses(String[] addresses) { this.addresses = addresses; } //****************** //Test Method //****************** public static testMethod void TestAddSOA() { // Insert test Opportunity Opportunity testOppty = new opportunity ( Name = 'Test Opportunity', Amount = 5000, StageName = 'Closed Won', CloseDate = System.today()); insert testOppty; // Instantiate VisualForce Page PageReference pg = Page.SOApdf; Test.setCurrentPage(pg); ApexPages.currentPage().getParameters().put('id', testOppty.id); // Instantiate addSOA controller ApexPages.StandardController c = new ApexPages.standardController(testOppty); addSOA qe = new addSOA(c); } }

 

 

 

Hi,

 

I'm relatively new to Salesforce/Apex, and currently having problem getting the 75% test coverage.

 

FYI, I've customised the LMA's Licence object to include a few custom fields for our application. In doing so, I had to also create the following pages/classes - just to be consistent with the LMA's look-and-feel:

 

1) A Visualforce page - a modified version of the LMA's Modify Licence page. This is to allow me to edit my custom fields

2) A "duplicate" version of the LMA's statusPicklistExtension for my new page. I tried to use the LMA's extension but got an error saying that the class is "not marked as global and cannot be used as a controller or extension". I basically guessed what the extension does based on Status flow diagram in the LMA demo. Not sure if this is right though!

 

Now, I have also written the test methods and they do give me 100% coverage for every one of my Apex classes. But the overall coverage is still only at 64%.

 

 

Summary

 

Test ClassAcxTrackingTests
Tests Run2
Test Failures0
Code Coverage Total %64
Total Time (ms)1127.0

 

 

Code Coverage

 

 

 The Code Coverage section shows that I only get only 2% for the class TestLicenceseUpdates. But this test class belongs to the LMA. So, could this be dragging my test coverage down? And if so, how can I fix it?

 

I just remembered I have an another 'exception' class which extends Exception, and doesn't have any additional code. So I don't think it matters if I don't write any test for it.

 

Any help would be very much appreciated.

 

Thanks,

mdqh

 

 

  • August 06, 2009
  • Like
  • 0

Is there somewhere where I can check how my Eclipse editor handles Force.com syntax coloring?  None of the syntax coloring is shown, everything is black.  I've tried changing the customizable Java syntax coloring, which has no effect.

 

I'm running Eclipse 3.4.2 on XP Pro with SP 3, if any of that makes a difference.

 

Thanks