• mengel
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 6
    Replies
Hi,
We have a custom button that does a call to an external application utilizing OnClick JavaScript.
I want to be certain the user logged in has access to edit the opportunity when this option is launched similar to the edit button.
What do I need to do to invoke that test of the sharing settings?
Thanks
Any advice is appreciated. 
Jackie

 

We really need a solution for this - will adding a public class with Sharing invoke the sharing rules?

I have a custom object called Branch.
My Account and Opportunity both have a lookup field to this object.
 
I need to ensure that the Opportunity Branch always contains the same value in the Account Branch if the opportunity is edited - I know this is very simple but i'm hitting a mental roadblock.  
 
My trigger below does not appear to be firing when I do an edit and save on the Opportunity record.
 
Also any help with setting up the test case for this would also be helpful.
 
I am new to this and did figure out how to retreive the code using Ant and Eclipse from the sandbox - but I know it will fail on deploy when I try to put it to production without a test case.   I am not particullary savy when it comes to java script.
 
Any input would be appreciated.
trigger OppBranchEqualAccBranch_Update on Opportunity (before update) {
  if (System.Trigger.isUpdate) {
         for(Opportunity oppnew :[select Id, Branch__c, Account.ID, Account.Branch__c from Opportunity where Id in:Trigger.new])
       {
             if(oppnew.Account.Branch__c == null) 
              oppnew.Branch__c = null;
             else                 
              oppnew.Branch__c = oppnew.Account.Branch__c;
              // Update oppnew;
        }       
    }
}
  • November 13, 2008
  • Like
  • 0
Still cutting my teeth on a test method of a reasonably simple trigger I've brought up in the past.

The trigger works fine in sandbox, but doesn't seem to work during the test method, I'm at the end of my wits with it so was hoping somebody with more insight might be willing to check it out:

Code:
public class TestTriggers {
  static testMethod void myTest() {
   Date futureDate = date.newInstance(2050, 6, 6);
    Account account = new Account(name='testAccount', OfficeOwningAccount__c='VIC', Industry='Defence');
    insert account;
    account = [select name from Account where name=:account.name];
    Opportunity opp = new Opportunity(name='testOpp', accountID=account.ID, StageName='1.0 - Territory', CloseDate = futureDate);
    insert opp;
    opp = [select ID, name, StageName, Primary_Contact__c, PricingMethod__c from Opportunity where ID=:opp.ID];
    Contact contact = new Contact(lastname='testContact', accountID=account.ID);
    insert contact;
    contact = [select name from Contact where LastName=:contact.lastname];
    OpportunityContactRole oppContact = new OpportunityContactRole(IsPrimary = true, ContactID=contact.ID, OpportunityID=opp.ID);
    insert oppContact;
    oppContact = [select Id, isPrimary from OpportunityContactRole where OpportunityID=:oppContact.OpportunityID and ContactID=:oppContact.ContactID];
    Practice_Service_Offering__c practiceService = new Practice_Service_Offering__c(Opportunity__c = opp.ID, of_Sale__c = 100);
    insert practiceService;
    practiceService = [select Id from Practice_Service_Offering__c where Opportunity__c = :opp.ID];
    update opp;
    opp.name = 'testOppUpdate';
    opp.StageName = '7.0 - Win';
    opp.ENGAGEMENTSTARTDATE__C = futureDate;
    opp.ENGAGEMENTCLOSEDATE__C = futureDate;
    opp.HOURS_PER_DAY__C = 8;
    opp.PRICINGMETHOD__C = 'Fixed-Price';
    opp.PROPOSED_CONSULTANTS_AGREED_BILLING_RA__C = 'testBillRate';
    opp.AMOUNT = 20000;
//This info is all required fields for something at Stage 7
//When something goes to stage 7, IsClosed switches to true
    update opp;
    opp = [select ID, name, IsClosed, StageName, Primary_Contact__c, PricingMethod__c from Opportunity where ID=:opp.ID];
//Assertions go here:
    System.assert(account != null);
    System.assert(contact != null);
    System.assert(oppContact != null);
    System.assert(practiceService != null);
    System.assert(opp.PricingMethod__c == 'Fixed-Price');
    System.assert(opp.name == 'testOppUpdate');
    System.assert(opp.IsClosed);
    System.assert(opp.Primary_Contact__c != null);
     try {
       delete opp;
       delete account;
       delete oppContact;
       delete contact;
       delete practiceService;
       }
     catch (DmlException e) {
       e.getDmlMessage(0);
       System.assert(false);
     }
 System.assert(opp==null);
    }
}

 
The trigger in question is here
Code:
trigger SetPrimaryContact on Opportunity (before update) {

    for (Opportunity o : Trigger.new) {
     //innitialise variables
     OpportunityContactRole contactRole;
     //Check that the opportunity is being closed out
      if (o.IsClosed && !Trigger.oldMap.get(o.id).IsClosed) {
     contactRole = [select ContactID from OpportunityContactRole where IsPrimary = true and OpportunityId = :o.id];
      }
      //if something is returned from the list:
      //get the primary contact associated with opp and assign the id to primary contact field
    if(contactRole != null){
    o.Primary_Contact__c = contactRole.ContactID;
    }
    //Profit
   }
}

Idea is simple, if an opportunity is closed out, then it pulls the information from related list into the opportunity field. This is a work around due to us having mail merges going out which should contain info from the related list section.

There are 3 failed assertions in the above:
System.assert(false); //from catch statement
System.assert(opp==null); //from just after catch statement (obviously it seems to be having some problems deleting opp)
//The big one
System.assert(opp.Primary_Contact__c != null);

I lightly considered commenting out the assertions and hoping for the best, but something tells me, our Best Practice Rep. would try and choke me out for that.
:smileytongue:

may I also use this opportunity (no pun intended) to point out that
:manvery-happy: and :womanmad: are phenominally creepy.

 

  • November 19, 2008
  • Like
  • 0
I have a custom object called Branch.
My Account and Opportunity both have a lookup field to this object.
 
I need to ensure that the Opportunity Branch always contains the same value in the Account Branch if the opportunity is edited - I know this is very simple but i'm hitting a mental roadblock.  
 
My trigger below does not appear to be firing when I do an edit and save on the Opportunity record.
 
Also any help with setting up the test case for this would also be helpful.
 
I am new to this and did figure out how to retreive the code using Ant and Eclipse from the sandbox - but I know it will fail on deploy when I try to put it to production without a test case.   I am not particullary savy when it comes to java script.
 
Any input would be appreciated.
trigger OppBranchEqualAccBranch_Update on Opportunity (before update) {
  if (System.Trigger.isUpdate) {
         for(Opportunity oppnew :[select Id, Branch__c, Account.ID, Account.Branch__c from Opportunity where Id in:Trigger.new])
       {
             if(oppnew.Account.Branch__c == null) 
              oppnew.Branch__c = null;
             else                 
              oppnew.Branch__c = oppnew.Account.Branch__c;
              // Update oppnew;
        }       
    }
}
  • November 13, 2008
  • Like
  • 0