• Benjamin_Mitchell
  • NEWBIE
  • 25 Points
  • Member since 2018

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies
Hello,

I am trying to create a test class for this trigger:
 
trigger leadDuplicatePreventer on opportunity(before insert) {
   set<string> settgs = new set<string>();
   list<opportunity> opps = [select id,Trigger_Help__c  from opportunity WHERE CreatedDate = LAST_N_DAYS:90];
   Profile p=[SELECT ID, Name FROM Profile WHERE Id=:userinfo.getProfileId() Limit 1];
   for(opportunity opp : opps){
     if(opp.Trigger_Help__c != null && p.Name <> 'System Administrator'){
	 settgs.add(opp.Trigger_Help__c);
	 }
   }
   
   for(opportunity op : trigger.new){
      if(settgs.contains(op.Trigger_Help__c)){
	     op.adderror('An Opportunity of this type already exists on this Account.  Please contact a system administrator with questions.');
	  }
   
   }


   
}

I think my problem is with assigning the second opp to be put on the Test Account.  How should I do this so that it does so correctly?

My current test class:
@isTest
private class TestleadDuplicatePreventer {
    @isTest static void TestleadDuplicatePreventerwithOneOpp() {
        Account acct = new Account(Name='Test Account');
        insert acct;
        Opportunity opp = new Opportunity(Name=acct.Name + ' Opportunity',
                                         StageName='Open Opportunity',
                                         CloseDate=System.today().addMonths(1),
                                         Facility__c='Tacoma WA',
                                         Oppty_Type__c='UCO Service',
                                         AccountID=acct.Id);
        insert opp;
        Test.startTest();
        opp= new Opportunity(Name='Opportunity Test',
                            StageName='Open Opportunity',
                            CloseDate=System.today().addMonths(2),
                            Facility__c='Tacoma WA',
                            Oppty_Type__c='UCO Service',
                            Account=[SELECT ID from Account WHERE Account.Name='Test Account']);
        try
        {
            insert opp;
        }
        catch(Exception duplicate)
        {       
        }
        Test.stopTest();
    }

}

The Trigger_Help__c is a formula created by adding the Oppty Type and the Id associated with the account.  So is there a different way I should be tackling this test class?
Hello,

I am trying to create a test class for this trigger:
 
trigger leadDuplicatePreventer on opportunity(before insert) {
   set<string> settgs = new set<string>();
   list<opportunity> opps = [select id,Trigger_Help__c  from opportunity WHERE CreatedDate = LAST_N_DAYS:90];
   Profile p=[SELECT ID, Name FROM Profile WHERE Id=:userinfo.getProfileId() Limit 1];
   for(opportunity opp : opps){
     if(opp.Trigger_Help__c != null && p.Name <> 'System Administrator'){
	 settgs.add(opp.Trigger_Help__c);
	 }
   }
   
   for(opportunity op : trigger.new){
      if(settgs.contains(op.Trigger_Help__c)){
	     op.adderror('An Opportunity of this type already exists on this Account.  Please contact a system administrator with questions.');
	  }
   
   }


   
}

I think my problem is with assigning the second opp to be put on the Test Account.  How should I do this so that it does so correctly?

My current test class:
@isTest
private class TestleadDuplicatePreventer {
    @isTest static void TestleadDuplicatePreventerwithOneOpp() {
        Account acct = new Account(Name='Test Account');
        insert acct;
        Opportunity opp = new Opportunity(Name=acct.Name + ' Opportunity',
                                         StageName='Open Opportunity',
                                         CloseDate=System.today().addMonths(1),
                                         Facility__c='Tacoma WA',
                                         Oppty_Type__c='UCO Service',
                                         AccountID=acct.Id);
        insert opp;
        Test.startTest();
        opp= new Opportunity(Name='Opportunity Test',
                            StageName='Open Opportunity',
                            CloseDate=System.today().addMonths(2),
                            Facility__c='Tacoma WA',
                            Oppty_Type__c='UCO Service',
                            Account=[SELECT ID from Account WHERE Account.Name='Test Account']);
        try
        {
            insert opp;
        }
        catch(Exception duplicate)
        {       
        }
        Test.stopTest();
    }

}

The Trigger_Help__c is a formula created by adding the Oppty Type and the Id associated with the account.  So is there a different way I should be tackling this test class?

Hey guys,

is there a workaround for getting lightning:outputField "value"?

Look at this code!

UI.cmp

<lightning:outputField fieldName="ExternalCode__c" aura:id="adrExternalCode" />
I've tried to do something like this in the UIController.js
component.find('adrExternalCode').get('v.value');

but it does not work, and i even got an error because component.find('adrExternalCode') is undefined.
 

Wait: i can display the value (through fieldName="ExternalCode__c"), but i can't take it and do anything with it?

Hello, I know this question has been asked on here before and I've looked through people's answers but none of them have been able to help me so far.

I would like to display a graph from a report on a Visuaforce page.

 

Here is my code:
<apex:page >
<analytics:reportChart reportId="00O2D000000FJMu"/>
</apex:page>

This shows up when I'm looking at it in the Preview from the developer console. But as soon as I use the link for this VF page it just shows a blank page.

Thanks in advance for the help.

Tony

Hey guys, 

I need to refresh an iFrame on when a user clicks a button. What's the best way to do that? I tried the solution shown here, which is neat, but for my purpose that appended "time" breaks my page. The page is a part of a managed package so I can't change it. Let me know if there is another way to do this.

Here is my code currently 

Cmp
<aura:component access="global" implements="lightning:availableForFlowScreens">
    <aura:attribute name="UploadFiles" type="Boolean" default="true"/>
    <aura:attribute name="Encoded_ID" type="String" />
    <aura:attribute name="UploadWarning" type="String" />
    <aura:attribute name="time" type="String" />
    
    	<aura:if isTrue="{! v.UploadFiles }" >
                <ui:outputText class="warning" value="{!v.UploadWarning}" />
                <div class="slds-p-top_small"></div>
            	<iframe src="{!'/TVA_CFB__RequestFile?'+v.Encoded_ID + 't=' + v.time}" height="350px" 
                width="350px" frameborder="0" class="slds-p-bottom_small"/>
            <ui:button press="{!c.myAction}">Upload another file</ui:button><br/><!--Ifraim should be reloaded on the press of this button-->
            </aura:if>
</aura:component>

Controller
({
    myAction : function(component, event, helper) {

                 var d = new Date();
                 var n = d.getTime();   
				component.set("v.time", n );   
           
    }
})