• dphill
  • NEWBIE
  • 190 Points
  • Member since 2012

  • Chatter
    Feed
  • 6
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 62
    Replies

Hi,

Please help to create a unit test for my trigger.

 

 

I having a trouble deploying my trigger in productio since sfdc is requiring a unit test. please help me. sandbox do not require a unit test. please please, im clueless onhow to start the unite tes.

 

here's the code:

=====

 

trigger UpdateQuoteManagers on Quote (before insert, before update) {
Set<ID> idOwners = new Set<ID>();


for(Quote quotes:trigger.new)
{
idOwners.add(quotes.Account_Manager__c);
}

if (idOwners.size() > 0)
{
Map<Id,User> users= new Map<Id,User>([Select Territory_Head__c, District_Head__c from User where Id in : idOwners]);

for(Quote qu:trigger.new)
{

if (users.get(qu.Account_Manager__c).Id!= null)
{
qu.District_Head2__c = users.get(qu.Account_Manager__c).District_Head__c;
qu.Territory_Head2__c = users.get(qu.Account_Manager__c).Territory_Head__c;
}
else
{
qu.District_Head2__c = null;
qu.Territory_Head2__c = null;

}
}
}
}

I'm trying to write a trigger that fills in a custom lookup field on a case by looking for a custom object with an exact match in a text field.

 

Basically, what I would like to do is when the custom object (custobj) is created or saved, and the text field (Package ID) has a value, find all cases with the same value in an equivalent custom field, and add the custom object to a lookup field on the case.

 

All attempts at writing this run into the same issue which is how to form the SOQL query to pull the related cases to update.  The following query is obviously totally wrong, but hopefully it highlights where my problem is.  What I think I need to do is pull all cases that have the Package_ID__c field which matches a Package_ID__c field on the custom object.  Can anyone help clarify how to do this?

 

List<Case> cases = new List<Case>([SELECT Id, Package_ID__c FROM Case WHERE Package_ID__c = custobj.Package_ID__c);

Thanks!!

Hi ,

I am looking at apex code to check thro triggers check if the record already exists  and display an error.

 

Suppose on Contact record  wanted to check  if Name+ email+phone exists then display an error to the user that duplicate record.

 

Is there any sample code anyone can share with me?

 

thanks

K

Hi,

I have a trigger on Opportunity which fires once opportunity stage = closed won. My Test method passes but shows error on class?

 

/*
Author: Mahfuz Choudhury
Date: 13.09.13
TestClassName:TestCloneOppLineItem on Opportunity
*/
@isTest(seeAllData=true) 
private class TestCloneOppLineItem{
    static testMethod void TestOppMethod() {
        List<Contact> contlist = new List<Contact>{};
        
        //Start of the test execution
        Test.starttest();
        //create a new account to associate with the opportunity
        Account a = new Account(Name = 'Test Account');
        insert a;
        
        //Create a contact to assign as primary contact role
        Contact con = new Contact(FirstName = 'Maf', LastName = 'Sample', AccountId = a.Id);
        Contact con1 = new Contact(FirstName = 'Lewis', LastName = 'Test', AccountId = a.Id);
        contlist.add(con);
        contlist.add(con1);
        insert contlist;
        
        //Select A Standard pricebook for the product
        Pricebook2  standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1];
        
        //Create a Test PriceBook for OpportunityLineItem
        Pricebook2 pbk = new Pricebook2 (Name='Test Pricebook Entry 1',Description='Test Pricebook Entry 1', isActive=true);
        insert pbk;
        
        //Insert a new Product for test class
        Product2 prd = new Product2 (Name='Premium Product',Description='Test Product Entry 1',productCode = 'ABC', isActive = true);
        insert prd;
        
        //Insert a new Pricebook entry
        PricebookEntry pbe = new PricebookEntry (Product2ID=prd.id,Pricebook2ID=standardPb.id,UnitPrice=50, isActive=true,UseStandardPrice=false);
        insert pbe;
        
        //create a new opportunity to test
        Opportunity opp = new Opportunity();
        opp.Name = 'Test Opportunity';
        Opp.AccountId = a.id;
        Opp.StageName = 'Closed Won';
        Opp.Type = 'Existing Business';
        Opp.CloseDate =  Date.today()+2;
        insert opp;
        
        OpportunityLineItem OLI = new OpportunityLineItem();
        OLI.Quantity = 2;
        OLI.UnitPrice = 5.00;
        OLI.OpportunityId = Opp.id;
        //OLI.ProductId = pbe.Id;
        OLI.PricebookEntryId = pbe.id;
        insert OLI;
        
        //creating opportunity contact role and make it primary
        OpportunityContactRole ocr = new OpportunityContactRole(OpportunityId = Opp.Id, ContactId = Con.Id, IsPrimary = true);
        insert ocr;
        
        System.assertEquals('Closed Won',Opp.StageName);
        System.assertEquals(Opp.IsOnlineOrder__c, false);
        
        Opp.IsOnlineOrder__c = true;
        Update Opp;
        System.assertEquals(Opp.IsOnlineOrder__c, true);
        Test.stopTest();
    }
}

 Can I get some help on this plz...

with sharing with out sharing, Which is the default in Apex class?????????

 

please help me....

I am obviously missing something obvious, but this query just doesn't work, and i can't work out why, can somebody assist?

 

SELECT Id,Name,Amount,R2_Job_Ref__c,R2_Shipping_Post_Code__c,Shipping_Postcode_2__c
FROM Opportunity
WHERE Shipping_Postcode_2__c != R2_Shipping_Post_Code__c AND R2_Shipping_Post_Code__c != null

 

Thanks!

 

Gareth

I wrote a simple class, and have a test method which in the Force.com IDE is telling me covers this class 100%.  When I right-click on the class in the Package Explorer, go to Force.com > Deploy to server... I enter my production credentials and they are validated, then I see that only my class is set to add to the production environment and I go forward with the deployment.

After several minutes, I get a FAILURE message related to one test along the lines of 'too many DML rows', looking into the logs I see there are 10283 rows which exceeds the limit of 10000.  I log in to the production environment and run the failing test, and it fails in production too WITH THE SAME ERROR.

Now I have a chicken/egg situation and I don't know how to get any code to production with this failing test, and furthermore, I don't know how anything that would have broken this test would have made it to production!  I tried locally commenting out everything in the test class and the deployment failed in the exact same way (to the character) so I know it is not anything locally that I need to change.  I did have to fix some things in the test to get it to run locally, but that is irrelevant here especially since I commented the entire body out and got the same error.

HELP!!

Class I'm trying to deploy:

public class AuthorizationToken {

public String LoginId;

public String Password;

public AuthorizationToken(String user, String pw)

{

Password = pw;

LoginId = user;

}

statictestMethodvoid testAuthTokenInstantiation()

{

String user = 'testUser';

String pw = 'testPw';

Test.startTest();

AuthorizationToken testAuthToken = new AuthorizationToken(user, pw);

Test.stopTest();

System.assertEquals(testAuthToken.LoginId, 'testUser');

}

}

FAILING TEST CLASS:

@isTest
public with sharing class generateRenewalOppty_TEST
{
    static testMethod void myTest()
    {
        Boolean success = true;
       
       
           
            Account testAccount = new Account();
            testAccount.Name = 'Test';
            testAccount.Phone = '1111111111';
            testAccount.County__c = 'Macomb';
            testAccount.Member_Payment_Form__c ='Standard - Cash';
            testAccount.Type = 'Membership - New';
        
            insert testAccount;
           
            update testAccount;
           
            Product2 testProduct2 = new Product2(Name='TestProduct', ProductCode = '123', IsActive = true);
            insert testProduct2;
           
            List<Pricebook2> testPB2List = [select Id from Pricebook2 where IsStandard = true];
           
            PricebookEntry testPBE = new PricebookEntry(Product2Id = testProduct2.Id, Pricebook2Id = testPB2List[0].Id, UnitPrice = 5.0, UseStandardPrice = false, IsActive = true);
            insert testPBE;
           
           
            Opportunity oppObj = new Opportunity(Name='Test Opp',StageName='Closed Won - In-Kind',CloseDate=System.Today(),AccountId=testAccount.Id, type='Membership - New');
            insert oppObj;
           
            OpportunityLineItem testOPL = new OpportunityLineItem(OpportunityId = oppObj.Id, Quantity = 1.0, TotalPrice = 100, PricebookEntryId = testPBE.Id);
            insert testOPL;
           
            OpportunityLineItem testOPL1 = new OpportunityLineItem(OpportunityId = oppObj.Id, Quantity = 1.0, TotalPrice = 100, PricebookEntryId = testPBE.Id);
            insert testOPL1;
           
        
            testAccount.Generate_Renewal_Oppty__c = true;
            update testAccount;
          
            Opportunity[] oppOpen =[Select Id,Amount from Opportunity Where (StageName='Open' or StageName='Membership - Renewal') and AccountId =:testAccount.Id];
            System.assertEquals(1, oppOpen.size());
          
            OpportunityLineItem[] oppLi =[Select Id,TotalPrice from OpportunityLineItem Where OpportunityId=:oppOpen[0].Id];
            System.assertEquals(2, oppLi.size());
            System.assertEquals(100, oppLi[0].TotalPrice);
            System.assertEquals(100, oppLi[1].TotalPrice);
           
            Opportunity[] oppRec = [Select Id from Opportunity];
            delete oppRec;
           
            Opportunity oppOb = new Opportunity(Name='Test Opp1',StageName='Open',CloseDate=System.Today(),AccountId=testAccount.Id);
            insert oppOb;
           
            testAccount.Generate_Renewal_Oppty__c = true;
            update testAccount;
           
            Opportunity[] oppRec1 = [Select Id from Opportunity];
THIS IS LINE 52: delete oppRec1;
           
            Opportunity oppOb1 = new Opportunity(Name='Test Opp1',StageName='Open',CloseDate=System.Today(),AccountId=testAccount.Id,Type = 'Membership - New');
            insert oppOb1;
           
            testAccount.Generate_Renewal_Oppty__c = true;
            update testAccount;
           
            //delete oppOpen;
                      
        }
 
}


TEST RESULT DETAIL:

Class: generateRenewalOppty_TEST

Method Name: myTest

Pass/Fail: Fail

Error Message: System.LimitException: Too many DML rows: 10001

Stack Trace: Class.generateRenewalOppty_TEST.myTest: line 52, column 1

 

Hi Everyone,

 

I have a text file that is uploaded by the user,

Using the Document class,

 

How can i read the content of that text file,

ex: Name, address, email, ...etc,

 

I want to save those paramters to an object i have created,

 

Is it possible to open and read an uploaded text file with VisualForce or Apex?

 

Thanks 

hi,

iam new to use field set in visualforce page

i created a one field set to retrive to vf page iam getting the error!

 

 

 

<apex:page controller="fieldset1">
    <apex:form >
        <apex:pageBlock title="Field Set List">
            <apex:pageBlockSection >
            <apex:repeat value="{!$ObjectType.cr__c.Fieldsets.Myfieldset}"/>
             <apex:inputField value="{!cr__c[f]}"/>   
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

iam did not get the field in vf page

ERROR::Invalid identifier: cr__c

 

 

 

 

Hi I'm new developing appex triggers and i can't make a trigger to work

 

I have to update a field on a custom object called pse__Timecard_Header__c The problem is that the field to update is a lookup field

 

  1. This field to be updated is: Manager__c  
  2. The manager info is located in the salesforce standard object caled "User" and the field name is called "Manager"

The Problem is that there is no direct link between the "user" object and my custom object called "timecard"

There is a looup field at the timecard to a custom "contact"  and from the contact there is a direct link to the salesforce "User"

 

 Summary: Timecard -> Contact -> Salesforce User

 

Thanks!!

 

Pablo

 

 

Hi,

I have code below, I wish to know how to get value of individual fields instead of using it like values() from map.

 

CODE:

 

for(Case c:caseemlist) {
for(EmailMessage em:c.EmailMessages) {
Emailmessage message = new Emailmessage (fromname = em.fromname,subject = em.subject,textbody = em.textbody,htmlbody = em.htmlbody,toaddress = em.toaddress,
fromaddress = em.fromaddress,ccaddress = em.ccaddress,status = em.status,messagedate = em.messagedate,ParentId=oldnewCaseIdmap.get(c.id));
//emlisttoinsert.add(message);
emailMessageMap.put(em.Id, message);
}
}

Attachment[] attList = new list <Attachment>();
Attachment[] insertAttList = new list <Attachment>();
if(emailMessageMap.values().size()>0) {
insert emailMessageMap.values();

 

Example in above, i wsh to insert individual values like fromaddress, ccaddress, how do i do it, i dont want to use values().

 

Hi,

 

I'm new in salesforce, I code something that working well but I can't make working the test method. When I call the "iWantMyJSValues" function I've got "Argument 1 cannot be null".

 

public withsharingclass CourseController {

 

privatefinalCourse__c course;   

private ApexPages.StandardController con ;   

   

public CourseController(ApexPages.StandardController controller) {

      con = controller;

      this.course = (course__c)controller.getRecord();   

   }

   

   public String valueOne { get; set; }

    integer i;

   

   

    public PageReference iWantMyJSValues() {

   

          valueOne = Apexpages.currentPage().getParameters().get('one');

           i = integer.valueof(valueOne);

   

    

if (i == 0) {    

this.course.v_end__c = this.course.v_end__c + i;

     } Else if (i == 1) {

this.course.v_start__c = this.course.v_start__c + i;

     } Else if (i == 2) {    

this.course.v_pause__c = this.course.v_pause__c + i;

     }

   

update course;

       

returnnull;

 }

   

public static testmethod void testiWantMyJSValues(){

 

    list<Course__c> courses = newlist<Course__c>{};

    Course__c testCourse = newCourse__c();

     testCourse.Language__c = 'English';

     testCourse.Training_Format__c ='On Demand';

     testCourse. Course__c = 'a0Ea000000J0G1e';

     courses.add(testCourse);

     insert courses;

 

ApexPages.StandardController to = new ApexPages.StandardController(testCourse) ;

 

CourseController controller = new CourseController(to) ;

Controller.iWantMyJSValues();

 

}

 

 

}

Hi,

 

Basically i have a task to create a batch which works if User select Startdate and enddate of data to be deleted please guide me how can i start 

Does anyone have experience with sending text messages out of salesforce by asking for the user's email address that their carrier turns into a text message and then sends (and bills for)?

 

Any one know an easier way to do that?

 

tia

Right now I'm just trying to establish a connection between my java app and Salesforce, but it isn't working out very well.  For some reason on my connection = new PartnerConnection(config); line I always error.

 

[ApiFault  exceptionCode='INVALID_LOGIN' exceptionMessage='Invalid username, password, security token; or user locked out.'

 

I have already confirmed that my username/password/security token are all correct.

 

public static void main(String[] args)  {   

ConnectorConfig config = new ConnectorConfig();   

config.setUsername("MYLOGIN");   

config.setPassword("MYPW&MYTOKEN");       

PartnerConnection connection;

try    {        

connection = Connector.newConnection(config);  

 } catch (ConnectionException e)    {     

// TODO Auto-generated catch block      e.printStackTrace();    }   }