• Gigi.Ochoa
  • NEWBIE
  • 385 Points
  • Member since 2010
  • Manager
  • Strategic Growth Inc


  • Chatter
    Feed
  • 12
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 56
    Replies
Hi folks,

I am getting problem with test coverage.
I am getting test coverage of 0%
Actually i don't know how to link the test class with the Apex class.

Here is my APEX Code

global class RenewalOpportunity implements Schedulable {
       global void execute(SchedulableContext SC) {
           
                RenewalOpp R= new RenewalOpp();
           
           
       }
    
    public class RenewalOpp{

RenewalOpp(){
Date d = Date.Today();


for(Account a:[select id,Name,Service_End_Date__c,Customer_Success_Manager__c,ARR__c
    from Account acc
    where
     (Id NOT IN (select AccountID from opportunity
    where AutoCreatedFlag__c = true ))])
{
    if(a.Service_End_Date__c!=NULL){
        
    // Difference between Service End date and Current date    
    Integer numberDaysDue= d.daysBetween(a.Service_End_Date__c);
    
    if(numberDaysDue<=60)  {  
        
    // Creating a new opportunity  
    Opportunity O= new Opportunity();
    o.Name=a.Name;
    o.StageName='Legal';
    o.Amount=a.ARR__c;
    o.AccountId=a.ID;
    o.CloseDate=Date.today();
    o.Customer_Success_Manager__c=a.Customer_Success_Manager__c;
    o.NextStep='Won';
    o.OwnerID='005d0000001Kt9D';
    o.AutoCreatedFlag__c = true;
        insert o;
        
       // Create a Pricebook Entry for Product
        
        List<OpportunityLineItem> oliList = new List <OpportunityLineItem>();
        Pricebook2 stdpb = [SELECT Id FROM Pricebook2 WHERE IsStandard = true]; // Select Price Book
        List<PriceBookEntry> entryList = new List<PriceBookEntry>();
        PriceBookEntry pe= new PriceBookEntry();
        pe.Pricebook2Id=stdpb.Id;
        pe.Product2Id='01tJ0000003qkr0';
        pe.UnitPrice=10;  // Standard Price
        pe.IsActive=true;
        Integer counter = [select count()  FROM PriceBookEntry where Product2.Id='01tJ0000003qkr0' And
        PriceBook2.isStandard=true AND UnitPrice=10];
        
        entryList.add(pe);
        if(counter==0){
        insert entryList;
        }
        
        List<PriceBookEntry> priceBookList = [select Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry where Product2.Id='01tJ0000003qkr0' And
        PriceBook2.isStandard=true LIMIT 1 ]; // Get the Price Book entry ID that we entered in the previous step
        OpportunityLineItem oli = new OpportunityLineItem(); // Create new Opportunity Product
        oli.OpportunityId = o.Id;                           
        oli.PricebookEntryId=priceBookList[0].Id;       // PricebookentryID of the existing pricebook entry for the specific product
        oli.UnitPrice =a.ARR__c;                       // Sales Price (or List Price)
        oli.Quantity=1;
        insert oli;
                          
              }
    }
}
 }
 
 }
    
    
    
    }



My Test Code

@isTest (seeAllData=true)  

public class RenewalTest{
    
    static testmethod void RenewalTest() {
    
    Date d = Date.Today();
    Date dueDate = date.newInstance(2015, 3, 20);
   // CSM__c csm= new CSM__c(Name='Chidanand',Customer_Success_Manager__c='Chidanand',Email='Chidanand@knstek.com');  
   // insert csm;
    Campaign c = new Campaign(Name='Chidanand');
    insert c;
    
    Product2 prod = new Product2(Name = 'Laptop X200',
            Family = 'Hardware');
        insert prod;
        
        
    
    
    Account a = new Account(Name='KNS',Service_End_Date__c=dueDate,Customer_Success_Manager__c='Jeff Tucker',ARR__c=500);
    insert a;
    Opportunity o = new Opportunity(Name='abc',AccountId=a.Id,CampaignId=c.Id,
                    StageName='Legal',Amount=5000,CloseDate=d,NextStep='Open',AutoCreatedFlag__c=false);
                    
    for(Account acc:[select id,Name,Service_End_Date__c,Customer_Success_Manager__c,ARR__c
    from Account acc
    where
     (Id NOT IN (select AccountID from opportunity
    where AutoCreatedFlag__c = true ))]){
    
    if(a.Service_End_Date__c!=NULL){
    
        Integer numberDaysDue= d.daysBetween(a.Service_End_Date__c);
        
        if(numberDaysDue<=60)  {
        
            Opportunity Op= new Opportunity();
            op.Name=a.Name;
            op.StageName='Legal';
            op.Amount=a.ARR__c;
            op.AccountId=a.ID;
            op.CloseDate=Date.today();
            op.Customer_Success_Manager__c=a.Customer_Success_Manager__c;
            op.NextStep='Won';
            op.OwnerID='005d0000001Kt9D';
            op.AutoCreatedFlag__c = true;
            insert op;
            
           // Id pricebookId = Test.getStandardPricebookId();
           List<PriceBookEntry> entryList = new List<PriceBookEntry>();
           Pricebook2 stdpb = [SELECT Id FROM Pricebook2 WHERE IsStandard = true]; // Select Price Book
           PricebookEntry standardPrice = new PricebookEntry(
           Pricebook2Id = stdpb .Id, Product2Id = prod.Id,
           UnitPrice = 10, IsActive = true);
          // entryList.add(standardPrice );
           
           
           Integer counter = [select count()  FROM PriceBookEntry where Product2.Id=:prod.Id And
        PriceBook2.isStandard=true AND UnitPrice=10];
        
        entryList.add(standardPrice );
        if(counter==0){
        insert entryList;
        }
           
           
           
          // insert entryList;
           
           String z=prod.Id;
           
           
           List<PriceBookEntry> priceBookList = [select Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry
           where (Product2.Id=:z) And (PriceBook2.isStandard=true) LIMIT 1 ]; // Get the Price Book entry ID that we entered in the previous step
        OpportunityLineItem oli = new OpportunityLineItem(); // Create new Opportunity Product
        oli.OpportunityId = op.Id;                           
        oli.PricebookEntryId=priceBookList[0].Id;       // PricebookentryID of the existing pricebook entry for the specific product
        oli.UnitPrice =10;                       // Sales Price (or List Price)
        oli.Quantity=1;
        insert oli;
           
           
        
        }
    
    }
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    }
    
    }



 
Hey guys,
I've run into a requirement for my org based on the Idea sObject. I've created a cObject called "Review" also. I need to accomplish the following flow:

User creates "Idea" entry-> Trigger copies it to "Review" and deletes it from "Idea"

Any ideas? Could I accomplish this in one trigger or do I need two?

Thanks for any and all help!

The below code works fine.  However you will notice that I do have a SOQL inside of a loop.
In an attempt to avoid issues down the line, I need to move this outisde the loop.  Any ideas on how to do this an still reference  the current b.Candidate__c(which is the contactID attached to the current Book_of_Business__c record.     Thanks in Advance

trigger BOBChange on Book_of_Business__c (before insert, before update) {
 
List<Quintile__c> Quintiles = new List<Quintile__c> ();
List<Book_of_Business__c> bob=[SELECT Id,Name,Candidate__c  from Book_of_Business__c ];
List<Contact> Contacts = new List<Contact> ();

Quintiles = [Select Quintile__c, T12_Min__c,T12_Max__c, LOS_Min__c, LOS_Max__c
             FROM      
                Quintile__c
             WHERE
                start_date__c <= today AND
                End_date__c > today];
               
              
    If (bob.size() > 0){
        for (Book_of_Business__c b : Trigger.new) {
            system.debug('BOB ------------- > ' + b.Id);
            system.debug('CandidateID ------------- > ' + b.Candidate__c);
            Contacts = [Select ID, Quintile_LOS__c, Total_years_as_a_rep__c, Producer_LOS__c,FirstName, LastName from Contact where ID =: b.Candidate__c];                 
            for (Contact c : Contacts){
             system.debug('C  ID ------------- > ' + c.Id);
                for (Quintile__c q : Quintiles) {
                 if(b.Candidate__c == c.ID &&
                  q.T12_Min__c <= b.Post_Haircut_T_12__c &&
                        q.T12_Max__c > b.Post_Haircut_T_12__c &&
                        q.LOS_Min__c <= c.Quintile_LOS__c &&
                        q.LOS_Max__c > c.Quintile_LOS__c) {
                             b.Quintile__c = q.Quintile__c;   // update BOB Quintile Field
                       System.debug(' Q.Quintile__c --------- >' + Q.Quintile__c);
                             }
                }

            }
        }
    }
}
Hi,

I have a custom object called Style__c which has a Lookup field to Product2 table called.

When I run a SOQL command inside the controller of my Visualforce template, ReturnFormStyleInfo, the name value doesn't report.

When I choose the template which refers to the controller, the data populates the email template but you can see it is missing the Product Name:

template output, doesn't include product2 lookup Style name field

Running a SOQL query directly, you can see that the name should be available for output via the component.

direct query on Style__c records aligned to case, showing that the name field is being pulled

Here is the getStyleInfo method from the class ReturnFormStyleInfo
public string getStyleInfo()
{
        string ret = '\nStyle\t\tPrice\tQty\n';
        for(Style__c s : [SELECT Style__r.Name, Price__c,Quantity__c FROM Style__c WHERE Case__r.CaseNumber=:thecase])
        {
            ret += s.Style__r.Name + '\t$' + s.Price__c + '\t' + s.Quantity__c + '\n';
        }
        return ret;
}

Which is referenced in this component.
<apex:component access="global" controller="ReturnFormStyleInfo">
<apex:attribute name="casenum" description="This is the CaseNumber of the case." type="string" assignTo="{!thecase}" />
{!StyleInfo}
</apex:component>
Hi All,

This trigger has been running just fine with no no errors, then yesterday starting throwing back "UpdateLeadOwner: System.LimitException: Too many SOQL queries: 101"

Here's the code:

trigger UpdateLeadOwner on Lead (before insert,before update) {
    for (Lead leadInLoop : Trigger.new) {
   
if (leadInLoop.LeadSource != 'Contact Us' && leadInLoop.LeadSource != 'Reprint') {
    // Retrieve owner from Account record based on email domain name
    list <Account> acct = [Select OwnerId from Account WHERE Domain__c = :leadInLoop.Domain__c AND Owner.UserRoleId != '00E50000000t0Bf' Limit 2];
        if (acct.size() == 1) {

    System.debug('account owner id is: ' + acct[0].OwnerId);
    leadInLoop.OwnerId=acct[0].OwnerId;
        }
    }
}

Any idea how to track down what changed so I can fix?  Thanks!
Hello

I have written a trigger but I am now trying to unit test it.  However I am getting the following error message with my apex class.  Can anyone see what I have done wrong?

User-added image

Thanks

Sonya
I have a page that on load pulls from an outside webservice.  This webservice may have issue and therefore won't display data.  I display an error to the user but I want to create a case that is assigned to a group of people in the compnay so it can be worked on.  I am unable to create a case when the page is being loaded due to DML restrictions. 

My Idea: create a checkbox and have it check so that when the error is caught it is cheked and initiates the action method.  This doesn't seem to work as I had planned.

Is anyone doing this and how?
Hi All, 

I wrote a custom controller and now trying to increase the code coverage. It is stuck at 39%. I'm not sure what am I missing? 

public String SelectPrimaryAccount { get; set; }
    public boolean SameAsCaller { get; set; }

 
    public List<SelectOption> getPrimaryAccount() {
        List<SelectOption> primaryAccount = new List<SelectOption>();
        primaryAccount.add(new SelectOption('','-None-'));
        primaryAccount.add(new SelectOption('Caller Account','Caller Account'));
        primaryAccount.add(new SelectOption('Project Site Contact', 'Project Site Contact'));
        primaryAccount.add(new SelectOption('Insurance', 'Insurance'));
 
        return primaryAccount;
    }

    public PageReference Save() {
    
        //Job Account and contact   
            Id acctid = Job.Account__c;
            id conid;
            
            job_Contact__c c1; job_Account__c a1;
            for(Contact con : [select id, accountid from Contact where id =:Job.Account__c]){
                c1 = new job_Contact__c(contact__c = con.id);
                a1 = new Job_Account__c(account__c = con.accountid);
                conid = con.id;
                Job.Account__c = con.accountid;
                
                if(SelectPrimaryAccount == 'Caller Account'){
                            job.account__c = con.accountid;
                }
            }
            
            job_Contact__c c2; job_Account__c a2; Contact con2;
            if(SameAsCaller != true && job.Project_Site_Contact_Name__c != null){
            
                con2 = [select id, accountid from Contact where id =:job.Project_Site_Contact_Name__c limit 1];
                job.Project_Site_Contact_Account__c = con2.accountid;
                
                c2 = new job_Contact__c(contact__c = con2.id);
                a2 = new Job_Account__c(account__c = con2.accountid);
                
                if(SelectPrimaryAccount == 'Project Site Contact'){
                        job.contact__c = job.Project_Site_Contact_Name__c;
                        job.account__c = con2.accountid;
                }
            }
            else {
                job.Project_Site_Contact_Name__c = conid;
                job.Project_Site_Contact_Account__c = job.account__c;
                //job.account__c = conid.accountid;
            }
            
            job_Contact__c c3; job_Account__c a3; Contact con3;
            if(job.Insurance_Adjuster_Broker__c != null){
                con3 = [select id, accountid from Contact where id =:job.Insurance_Adjuster_Broker__c limit 1];
                c3 = new job_Contact__c(contact__c = con3.id);
                a3 = new Job_Account__c(account__c = con3.accountid);
                   
                if(SelectPrimaryAccount == 'Insurance'){
                        job.contact__c = job.Insurance_Adjuster_Broker__c;
                        job.account__c = con3.accountid;
                }
            }
            
            if(acctid != null){
                a3 = new Job_Account__c(account__c = acctid);
                if(SelectPrimaryAccount == 'Insurance'){
                    job.account__c = job.account__c;
                    job.contact__c = null;}
            
            }
            
        
        insert job; 
        
           if(c1!=null){
            c1.job__c = job.id;
            a1.job__c = job.id;
            jcon.add(c1);jacct.add(a1);}
            
            if(c2!=null){
                c2.job__c = job.id;
                a2.job__c = job.id;
                jcon.add(c2); jacct.add(a2);
            }
        
            if(acctid!=null){
                a3.job__c = job.id;
                jacct.add(a3);
                if(c3!=null){
                    c3.job__c = job.id;
                    jcon.add(c3);
                }
            }
          
            insert jCon;
            insert jAcct;

It's getting coverage on the queries and the confitional statements. But that's about it. 

Here's my test class:

@isTest (seealldata = true)
                    
public class CreateNewJobInquiry_Test {

    public static testMethod void TestCreateNewJobInquiry () {
        //PageReference pageRef = page.NewRecord;
        //Test.setCurrentPage(pageRef);
      
        Contact contact = new Contact();
        Account account = new account(billingStreet = contact.mailingstreet, billingcity = contact.mailingCity, billingstate = contact.mailingcity, billingpostalcode = contact.mailingpostalcode, phone = contact.phone);
        account.name = 'CIG';
        insert account;
        
        Contact.contact_type__c = 'Adjustor';
        contact.firstname = 'semira';
        contact.Lastname = 'roy';
        contact.accountid = account.id;
        insert contact;
    
        Contact contact2 = new Contact();
        Contact2.contact_type__c = 'Adjustor';
        contact2.Lastname = 'noname';
        contact2.firstname = 'noname';
        contact2.accountid = account.id;
        insert contact2;
        
        
    Job__c job = new Job__c(account__c = account.id, Job_Name__c = 'test', Project_Site_Address__c = contact.mailingstreet, Project_Site_City__c = 'Los Angeles', Project_Site_state__c = 'CA', Project_Site_zipcode__c ='90027', County__c = 'LA', City_of_LA__c = 'Yes');
    job.contact__c = contact.id;
    job.Project_Site_Contact_Name__c = contact2.id;
    job.Insurance_Adjuster_Broker__c = contact.id;
    
    
    ApexPages.currentPage().getParameters().put('qp', job.id);
    CreateNewJobInquiry testObj2 = new CreateNewJobInquiry();
    testObj2.Sameascaller = false;
    testObj2.SelectPrimaryAccount = 'caller account';
    
        testObj2.save();
    }
}


I have a custom object Pint, I want it create new pint again automatically once a pint's status is Closed.  I got an error message while creating a trigger, please help.

Error Error: Compile Error: Duplicate variable: p (attempt to re-create the variable with type: Pint__c) at line 4 column 32

trigger CreatePin on Pint__c (after update) {
       for (Pint__c p : Trigger.new) {
               if (p.Status == 'Closed') {
                       Pint__c p = new Pint__c();
                       p.Account__c = c.AccountId;                  
               insert p;
        }
        }
        }
Hello-

Yesterday, I installed an apex trigger titled 'Change Lead Status' with the intent that anytime a Lead has a completed activity logged, it changes the Lead Status to 'Working - Contact Made'. While that functionality works just fine, my users have noticed an error message whenever they try and log an activity (manually) on an Account without a Contact included on the Name field in the Task page layout. The error will not let them log the Task without a Contact associated with it. I don't understand what is happening, and I'm confused as to why a Lead based apex trigger is affecting Accounts/Contacts.

I have two questions A) is there any way to modify this code so that this data is not required to log a Task manually? The apex trigger works fine other than this error. B) If not, how would I go about removing this apex trigger? I looked at some documentation around this, and they direct me to the sandbox to remove the trigger, but the trigger does not appear in my sandbox. 

Here is the code: 

trigger changeLeadStatus on Task (before insert, before update) {
    String desiredNewLeadStatus = 'Working - Contacted';

    List<Id> leadIds=new List<Id>();
    for(Task t:trigger.new){
        if(t.Status=='Completed'){
            if(String.valueOf(t.whoId).startsWith('00Q')==TRUE){//check if the task is associated with a lead
                leadIds.add(t.whoId);
            }//if 2
        }//if 1
    }//for
    List<Lead> leadsToUpdate=[SELECT Id, Status FROM Lead WHERE Id IN :leadIds AND IsConverted=FALSE];
    For (Lead l:leadsToUpdate){
        l.Status=desiredNewLeadStatus;
    }//for
   
    try{
        update leadsToUpdate;
    }catch(DMLException e){
        system.debug('Leads were not all properly updated.  Error: '+e);
    }
}//trigger

Any help would be greatly appreciated, I have received several complaints over the past day. 

Thank you,

Ryan

The code is as follows: 
Hi

I am trying to write a trigger that will update the lookup field called Most_recent_nomination_tenancy__c field on a custom object called Referral__c when a new Nomination/Tenancy is created.  However at present rather than updating the field with the name of the new Nomination/Tenancy it is turning the field blank.   Does anyone know why this trigger is turning the field blank and not updating it?

trigger UpdateReferralWithNewNomTen on Nomination_Tenancy__c (before insert, before update) {

  for(Nomination_Tenancy__c newRecord : Trigger.new)  {        
      Referral__c Referral = [Select Id, Most_recent_nomination_tenancy__c from Referral__c WHERE Id = :newRecord.Referral__c ];
        Referral.Most_recent_nomination_tenancy__c = newRecord.Name;
        update Referral;               
    }

}

Many Thanks,

Mike
Hi, 

I have a problem that I'm finding hard to figure out. Any help on the issue would be most welcome. 

I have a custom object called Bonus, this has a lookup relationship with another custom object called Payments. 

Using a VF page and standard controller with extension, I have a button on the Bonus page layout that will create 4 payment records for a single Bonus record when pressed. 

This all works fine, however if I refresh the page immidiately after creating the Payment records, I get 4 more. If I close the page, open it again and then refresh I do not get any duplicates. 

Has anyone ever experienced this before? ...or have any suggestions for how I can troubleshoot?

Many thanks!
This is my third time trying to post this question... Third time's the charm?

Hello all,

I'm having an issue trying to display an image in a PDF rendered Visualforce Page. The image's URL is stored in a field on the object controlling the page.

I've tried using <apex:image...> and <img src...>. Using the actual URL works just fine and displays the image. Removing the renderAs="pdf" displays all images correctly.

Any help would be much appreciated.

Thank you!

Code snippet:

<apex:page standardController="Order__c" showheader="false" standardStylesheets="true" renderAs="PDF">

<apex:pageBlock >
<apex:image value="ImageStoredAsDocument" width="98%"/> <!-- this displays fine -->

        <img src="{!Order__c.CustomField_URL__c}" /> <!-- this does not display when rendered as PDF -->
        <img src="ActualURL" /> <!-- this displays fine -->
</apex:pageBlock>


I want to add a second "Log a Call "button to the Account/Contact/Oppty pages that will have a different default subject than the out of the box "Call".
I want the button to read "Log a Demo" and the default subject value to be "Demo".
Can this be done?

Thanks, kb

Hi Force devs

Can we lock the record order from the apex code. not from approval process.

Rgrds
SR