• Vinnie B
  • NEWBIE
  • 70 Points
  • Member since 2013
  • Salesforce Specialist
  • Save The Bay

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 25
    Questions
  • 60
    Replies
I have a custom object.  I want to quickly review the permissions on this object for all of the profiles in my system.  Is this possible?  I can see how to go to every profile and then to Object Settings from there.  That gives me a quick overview of all of the objects for that profile.  What about an overview of all of the profiles for a given object.

Also, seeing this I decided to be very careful when creating new objects to assign them properly then.  But it appears that you're not given the option to set permissions at the time of creation for a new object.

Is this a recent change?  I don't remember it being this tedious to assign object permissions to many profiles.
Can one just put that object into read only for a given user so that the Edit and Del links should not be there?
I know this has got to be simple but I just can't figure it out after hacking away for an hour.  I am not experienced at this.

I'm simply trying to override the New button on a custom object to a URL which pre-populates the Name field.  The URL was easy to develop (below).  It works just like the standard New button but one field is populated with some text.  (We use a workflow rule to set the Name field so there's no need for the user to enter anything.)

  https://na18.salesforce.com/a0o/e?Name=[Set%20by%20Workflow%20Rule]&retURL=%2Fa0o%2Fo

When I want to change the default button it asks me for a VF page.  I have tried creating a simple VF page that just redirects to the URL above.  I'm a pretty novice VF developer and this simple task has got me struggling.

Thanks!!
I'm running into the limit of five queued, not scheduled, jobs.  I have one job that runs an Apex batch class once a month.  However, once it runs on say 4/1, it creates a scheduled job for 5/1.  Now one of my five is taken forever.  I have two other scheduled jobs that run weekly.  Now, I'm at 3 of 5.  We have installed Rollup Helper and TaskRay and now I'm at 6!

How can I code my scheduled job so that it doesn't permanently take up a queued job?  I find it odd that a monthly process should count for one fifth of my limit in this regard.

Note that my Apex code is running fine.

Thanks!
I've been tasked with grabbing some .csv files from an external location and importing that data into an SFDC instance on a nightly basis.  There will be some required manipulation of the data involved prior to importing.

I'm thinking the best approach is to develop an Apex class that runs as a daily scheduled job.  The Apex class will do an HTTP request to get the files from the external location, process the data as needed in the Apex code, and populate the appropriate fields.

I've done a fair amount of Apex coding and think I can do this.  My question is regarding the general strategy of this.  Is there a better way to do this?  Are there any gotchas that I need to worry about in doing it this way?

Thanks!!
I'm setting up a project in Eclipse to download all of our workflow rules.  I select all for Workflow rules and I see many files in the workflows directory; Account.workflow, Opportunity.workflow, etc.  However, Contact.workflow is missing.  There's also another custom object we have that's missing.  But there are some custom objects there that don't even have any workflows.

I looked through the logs and saw some Java exceptions at the time of a metadata refresh but they didn't give me a clue as to why this would be happening.  Does anybody have any clues as to why some metadata components would be downloaded while others aren't being downloaded?

Thanks!!
Again, new to VF and seeing some simple problems.  I'm trying to mimic our main web page, with its CSS, menus, etc and putting that HTML into a VF page.  I've referenced the needed CSS and JS pages on our site.  This works for the most part but I'm seeing some issues (i.e. the issue with a simple URL HREF mentioned in another post).

One thing I've noticed is that the rendered HTML shows the "::after" code where I'm having problems.  I Googled on this but couldn't find much of an explanation, even as to how this is used in standard HTML/CSS.  Any ideas on what causes this and how to get around it would be greatly appreciated.

THANKS!!
I'm new to VF and I'm assuming (hoping!) that this is a simple question.

I'm trying to set a simple HTML link in a VF page.  I'm using code like:
 
<apex:outputLink value="http://www.cnn.com"> 
    here</apex:outputLink>
Looking at the HTML source of the rendered page I see:

&lt;apex:outputLink value="https://www.cnn.com"&gt; 
    here&lt;/apex:outputLink&gt;.
This shows the 'here' with the appropriate link, but the URL is also showing to the user after that.

First, why are the lesser and greater signs escaped?  Secondly, I'm assuming there's got to be a way to include a simple link that doesn't show the URL itself.

Again, I'm pretty good with Apex but just getting into VF.  This is likely some basic concept of VF that I'm missing.

Thanks!!


I have a program that runs every morning at 4:00 am.  Since it does some CPU intensive calculations I put some of the heavy lifting into five future functions that are called from within the main program.  Things generally are working fine.

Occassionally, I'll get a message about locked rows.  This is, of course, quite bad as some of my updates just don't happen.

I did some other coding with batch files and got around this by having Batch-1 call Batch-2 which calls Batch-3, etc.  Is there some way to make sure five different future calls won't run at the same time?

Thanks!
We were upgraded to Summer '14 over the weekend.  Now I have tests that are failing that haven't failed in months.  The issue is that I'm running several versions of a batch process to catch various parts of the code.  It's now complaining that I'm running more than 5 batch processes on our network and that's why the test is failing.

I checked and the test code on production hasn't been changed since February but just started failing this week.

Any ideas?  Thanks!!
I seem to run into this situation a lot and have been using a brute force way around it.  For example, I query a bunch of contacts for their accounts and put the results into a list.  But this list has duplicate accounts.  I want the list de-duped.  I've tried using the GROUP BY clause of the query but the query results are then aggregate result objects that I have to convert into the object in question.

I've settled on this code which is pretty concise but is a shotgun approach.  I'm thinking there has to be an easier way (using Maps?).  Any comments?

Thanks!!

for (Opportunity anOpp1 : FullListOfOpps) {
        FOUND = false;  // boolean
        for (Opportunity anOpp2 : ListOfOppsWithoutDuplicates) {
           if (anOpp2.Id == anOpp1.Id) {
             FOUND = true;
           }
        }
        if (!FOUND) {
           Opportunity newOpp = new Opportunity();      
           newOpp.id = anOpp1.id;
           ListOfOppsWithoutDuplicates.add(newOpp);
        }
      }
All of a sudden my Eclipse has been acting weird.  When I try to save it usually doesn't let me.  I get the following error messages in the .log file.  In the GUI it warns me the file was only saved locally.

I initially thought this was due to code as I could remove all of my code and get the file to save.  However, when I then started putting code back in to see what me be causing the problem, the results were not consistent.  I can understand if I made coding errors.  I do that all the time.  :)  But I wasn't getting any of the typical messages that the compiler or Salesforce gives me when I make these errors.

Has anyone seen this before?  I'm planning on trying this against a new sandbox to see if that's the issue. After that I'll assume it's the Eclipse binaries somehow being corrupted and will try the latest version.

---

!ENTRY com.salesforce.ide.core 2 0 2014-06-11 16:03:28.500
!MESSAGE  WARN [2014-06-11 16:03:28,499] (ProjectService.java:handleDeployResult:1909) - Save failed!

!ENTRY com.salesforce.ide.core 2 0 2014-06-11 16:03:28.504
!MESSAGE  WARN [2014-06-11 16:03:28,501] (ProjectService.java:handleRetrieveResult:2085) - Nothing to save to project - retrieve result is empty
I have a simple tabPanel that references a VF page in each tab.  It's pretty simple but the second tab always displays improperly with the tabs to the right in their own column.  This pushes the table (created by the other VF pages) to the right 'column' and scrunches it up.  Short of a picture, it looks like this when Tab 1 is selected:

  Tabs
  VF page with table

And this when Tab 2 is selected.

  Tabs    -  VF page with table.

Obviously, I don't want the tabs on top of my VF page, not pushing it off to the right.

The tab panel code is pretty simple:

<apex:page showHeader="true">
  <style>
    .activeTab {background-color:#236FBD; color:white; background-image:none}
    .inactiveTab {background-color:lightgrey; color:black; background-image:none}
  </style>

  <apex:tabPanel switchType="client" selectedTab="tab1" id="ODTabPanel"
      activeTabClass="activeTab" tabClass="activeTab" inactiveTabClass="inactiveTab">
   
    <apex:tab label="Program - 1" name="Program1" id="tab2">
      <apex:include pageName="OD_Display_Program2"/>
    </apex:tab>

    <apex:tab label="Program - 2" name="Program2" id="tab1">
      <apex:include pageName="OD_Display_Program1"/>
    </apex:tab>

  </apex:tabPanel>
</apex:page>

The code for the VF pages called by the tabPanel is also pretty simple:

<apex:page controller="OD_Display_Program1Controller" showHeader="TRUE" standardStylesheets="TRUE" cache="FALSE">

<apex:outputPanel >
 
    <table width="100%" border="1" cellpadding="5%" bgcolor="CCEEEE">
         ... lots of stuff in the table
    </table>

</apex:outputPanel>

</apex:page>

The other tab is basically the same.  It just grabs different data.  I did flip the two around and the problem remains with the VF page called by the second tab.

Any ideas as to why the page won't display correctly?  Thanks!!
We are current Salesforce and iContact customers.  We use iContact via the SFDC GUI right now with no problems.  What we'd like to do is have a scheduled program do the following:
  • Create an iContact campaign
  • Query for a given set of contacts
  • Add these contacts to the iContact campaign
  • Send the email using iContact
I can do the first three things pretty easily.  I'm not sure how to do the last one.  Via the GUI you are directed to a VF page (SendMessage) that has a 'Send Message to Campaign Members' button.  I'd like to fill in the values on this page and programmatically send the message.

Has anyone sent off iContact emails programmatically?  If so, any help you could provide would be greatly appreciated.

I understand that you can't insert more than 10,000 rows at once in a DML statement.  So, I wrote a little routine to do these 5,000 at a time (below).  Note that this is called in the 'finish' function of the batch process so it's gathered all of the relevant records, some 50,000 or so.

for (ID cID : contactIDs) {
      counter ++;
      STB_Constituent__c stbc = new STB_Constituent__c();
      stbc.Contact_ID__c = (String) cID;
      constituents.add(stbc);
      if (counter == 5000) {
       try {
         insert constituents;
          counter = 0;
          constituents.clear();
       } catch (System.DmlException dmlEx) {
         throw dmlEx;
       }

This code seems to be working well, but I'm still getting the error message.  Note that in my logs below it says it's only going to insert 5,000 records but then the next line says that's over 10,000.  Am I missing something as to what constitutes a "DML row".  I'll try again using a batch size of 1,000 and see how that goes.

11:27:54.704 (31704666000)|DML_BEGIN|[94]|Op:Insert|Type:STB_Constituent__c|Rows:5000
11:27:54.704 (31704687000)|EXCEPTION_THROWN|[94]|System.LimitException: Too many DML rows: 10001
11:27:54.704 (31704768000)|HEAP_ALLOCATE|[94]|Bytes:28
11:27:54.706 (31706178000)|FATAL_ERROR|System.LimitException: Too many DML rows: 10001
I have a fairly simple batch apex class that goes through contact records.  I'm trying to get a total count of the number of items that are being processed in a batch apex run.  The problem is the variable, numberOfContacts, is always reset to its default value when entering the execute loop.

I have a feeling that the issue of this being a variable in a global class is causing the problem.  Does that make sense?  If so, is there a way around this?

Thanks!!

---

global class OrgDashboardBatchable implements Database.Batchable<SObject> {
 
  global String glstrQuery;
  global List<SObject> gllstScopeRecords;

  private Integer numberOfContacts = 0;
  private ID theODB_ID;

  global OrgDashboardBatchable(ID odbID) {
    glstrQuery = 'SELECT Id FROM Contact WHERE cv__Active__c = TRUE';
    theODB_ID = odbID;
  }
 
  global Database.QueryLocator start(Database.BatchableContext bc) {
    return Database.getQueryLocator(glstrQuery);
  }
 
  global void execute(Database.BatchableContext bc, List<SObject> lstBatchRecords) {
   
    //  The first debug message is always zero.  The second does show the size of this batch.
    gllstScopeRecords = lstBatchRecords;
    System.debug('In execute: numberOfContacts1 = ' + numberOfContacts);
    numberOfContacts += gllstScopeRecords.size();
    System.debug('In execute: numberOfContacts2 = ' + numberOfContacts);
  }
 
  global void finish(Database.BatchableContext bc) {
   
    //  Code that works correctly
 
 }
  
}
I have what I think is a pretty simple issue.  I'm developing a program that will run a number of queries nightly and populate a 'snapshot' object.  This object has fields such as Date and NumberOfContacts so that we can track growth over time.  However, when I do a query that returns over 50K records (i.e. SELECT count(Name) FROM CONTACT WHERE Active__c = TRUE) I get the 50001 query row message.

I can run this query easily in the Developer Console to get my results even if well over 50K.  I looked into dividing the query up into different segments (i.e. by CreatedDate) and using a Batchable class.  Both of these seemed like a fair amount of effort to simply run a query.  I figured I'd ask here to see if there's a better way to do this.

I do plan on putting this into a scheduleable job that will run at 3:00 am or so.  Running the code manually in production is causing the problem.  I'm not sure if the scheduleable aspect alone will make a difference.

Thanks!!

 

I saw a similar post on this from 2009 but I'm assuming that's ancient history as far as SFDC is concerned.

 

I've been using the Query Editor within the Developer Console but have some issues with that:

 

  1) There is no ability to export data to a spreadsheet.

  2) It appears that when I use this in a sandbox I don't see the results of joins into parent object.  I do see these results when I'm on our Production system.

 

I also tried the Force.com Explorer tool but I have problems with this as well.

 

  1) While this works ok as a Data Dictionary, I can't see the type of a given field.  They present all sorts of information I'm not familiar with about the field (i.e. groupable, namePointing), but don't even tell me the field type!

  2) I also don't see the results of parent fields when doing simple queries.

 

I know that running raw queries isn't they way they want you to use Salesforce, but it's often necessary when debugging complex reporting tasks or testing out code development.  Any help on this would be greatly appreciated.

I can run the following simple query on the standard Account and Contacts object to include values from the parent object when querying the child object.

 

select firstName, lastName, Account.Name
  from Contact
  where firstName like 'Vinn%'

 

However, when I try to do this on a custom object I created, Custom_Account__c, I can't get it to work at all.  I set up the lookup field on Contact to have the same relationship as it does with the regular Account object (parent/child).

 

I tried the following query and many other permutations including putting the relationship name (Contacts) in place of Custom_Account__c, doing this with and without "__r" appended to it.

 

select firstName, lastName, Custom_Account__c.Number_Field__c
  from Contact
  where firstName like 'Vinn%'

 

I tried all sorts of variations but I keep getting the error:

 

"Didn't understand relationship 'Custom_Account__c' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names."

 

I don't understand why I can't simply reference the fields in a custom parent object as I do with a standard parent object.

 

Thanks!

We're trying to get rid of the Notes and Attachments section of the Contact page layout since it's not customizable.  However, we need a new "Attachments" section to replicate the attachments functionality of that related list.

 

I figured out how to create a VF page which shows the Attachments for the contact and have put that on the page layout.  I am stuck at adding an "Add Attachment" button on this page.

 

I think it's down to just writing a controller that will open the standard add attachment page and linking that attachment to the contact.  Any help here would be appreciated.

 

Note that I'm not trying to do anything with the file contents. I just want the standard Add Attachment functionality that you see in the default Notes and Attachments related list.

 

I'm fairly new to VF so this is hopefully something that's pretty simple.  :)

 

THANKS!!

I know this has got to be simple but I just can't figure it out after hacking away for an hour.  I am not experienced at this.

I'm simply trying to override the New button on a custom object to a URL which pre-populates the Name field.  The URL was easy to develop (below).  It works just like the standard New button but one field is populated with some text.  (We use a workflow rule to set the Name field so there's no need for the user to enter anything.)

  https://na18.salesforce.com/a0o/e?Name=[Set%20by%20Workflow%20Rule]&retURL=%2Fa0o%2Fo

When I want to change the default button it asks me for a VF page.  I have tried creating a simple VF page that just redirects to the URL above.  I'm a pretty novice VF developer and this simple task has got me struggling.

Thanks!!
// 
// AutoCaseCreate.cls --- can be scheduled to run at any time interval
//

global class AutoCaseCreate implements Schedulable {

    // Callable from a Unit Test
    public void execute() {
        // Find the Contacts with Related Sales Tax orgs,
        // so that we can assign a new Case to it
        list<Group> USTRID = [SELECT Email,Id,Name,Type FROM Group WHERE Type =:'queue' AND Name=:'USTR' limit 1];
        
        for(contact con : [SELECT Id, (SELECT Id, Name FROM Sales_Tax_Orgs__r ) FROM Contact
                             WHERE Id IN (SELECT Contact__c from Sales_Tax_Org__c WHERE Name != '')])
   
        {
            // Create a new Case for every contact related to sales tax orgs
            Case c = new Case(
                Priority = 'Medium',
                Status = 'New',
                Subject = 'USTR: Initial EOM Request',
                OwnerId = USTRID[0].id,
                Category__c = 'Accounting',
                Sub_Category__c = 'University Sales Tax Reporting',
                Origin = 'YSS USTR Initiated',  
                ContactId = con.id
               
            );
            // Try to insert our Case
            try {
                insert c;
            } catch (DMLException ex) {
                // Handle the error
            }
        }
    }

    global void execute(SchedulableContext sc) {
        execute();
    }
}
Here is my code for a schedule class. I'm not an expert in coding and i'have written this code with the help of some existing forums. It would be very helpful if you guys suggest me how to write the test class for this.

Thanks
 
I need help with test class for the below trigger. some one please help me. Many thanks guys.
 
trigger UpdateCR on Case  (before update) {

        Map<String, Schema.RecordTypeInfo > caseRecordTypes = Case.sObjectType.getDescribe().getRecordTypeInfosByName();

        Id recordTypeId = caseRecordTypes.get('US Cases Locked RT').getRecordTypeId();

         for ( Case c : Trigger.new) {

           if (c.CF_Tracking__c != null ){
        
              if( c.Status == 'Closed') {

                               c.RecordTypeId = recordTypeId;

        }

    }

}


}

 
I'm trying to create a class and method that will update a field on a record when a picklist value is changed.  I get the Too many SOQL queries error.

It is called by the following trigger:

trigger triggerUpdateTravelChange on Travel_Detail__c (after update, before update) {
    Travel_Detail__c[] travel_details = Trigger.new;
    If(Trigger.Isafter){
        //Updates the Change Travel Ticket Date and 
        //Increments the Change Travel Ticket Revision
        //on the Travel Ticket
        UpdateTravelChange.findTravelDetail(travel_details);
        updateTravelDetailStatus.updateTravelTicket(travel_details);

//TravelCalendarUpdate.TravelDetail(travel_details);

    }
    If(Trigger.Isbefore){
        //Updates the Change Revision and Change Date Fields
        // on the Travel Detail Record
        TravelDetailBooked.updateBooked(travel_details);
    }
}

Apex Class

trigger triggerUpdateTravelChange on Travel_Detail__c (after update, before update) {
    Travel_Detail__c[] travel_details = Trigger.new;
    If(Trigger.Isafter){
        //Updates the Change Travel Ticket Date and 
        //Increments the Change Travel Ticket Revision
        //on the Travel Ticket
        UpdateTravelChange.findTravelDetail(travel_details);
        updateTravelDetailStatus.updateTravelTicket(travel_details);

//TravelCalendarUpdate.TravelDetail(travel_details);

    }
    If(Trigger.Isbefore){
        //Updates the Change Revision and Change Date Fields
        // on the Travel Detail Record
        TravelDetailBooked.updateBooked(travel_details);
    }
}
Hello, I'm trying to deploy an apex class to production but I can't because it gives me 72% of coverage code.
This is my apex class;
Does anyone know how to test this apex class and increase the coverage code? I really will appreciate any help

public with sharing class FacturaPDFController {

    public final Factura__c fct;
    public cFactura cfct{get; set;}
    public OT__c ots{get; set;}
    public xOT otts {get; set;}
    public Integer total{get; set;}
    public List<cOT> cOTList{get;set;}
    public List<cLdd> cLddList{get;set;}

    public FacturaPDFController(ApexPages.StandardController controller) {
        this.fct =  [Select Id, Pre_Factura__r.ST_Exentas__c, Pre_Factura__r.Descuento__c, Pre_Factura__r.ST_Gravadas_IVA10__c,                         Pre_Factura__r.Total_a_Pagar__c, Pre_Factura__r.IVA_10__c From Factura__c  Where Id = :controller.getId()];
        this.cfct = new cFactura(this.fct);
        total = Integer.valueOf( this.fct.Pre_Factura__r.Total_a_Pagar__c );



        //OT personalizado
        this.ots= [Select Cant_1__c,Cant_2__c,Cant_3__c,Cant_4__c,Cant_5__c, Texto_1_fact__c,Texto_2_fact__c,Texto_3_fact__c,
        Texto_4_fact__c,Texto_5_fact__c, Precio_Unit_1__c, Precio_Unit_2__c, Precio_Unit_3__c, Precio_Unit_4__c, Precio_Unit_5__c,
        Total_Ex_1__c, Total_Ex_2__c, Total_Ex_3__c, Total_Ex_4__c, Total_Ex_5__c,
        Total_Gra_1__c, Total_Gra_2__c, Total_Gra_3__c, Total_Gra_4__c, Total_Gra_5__c        
        from OT__c  where Pre_Factura__c = :this.fct.Pre_Factura__r.id];
        this.otts=new xOT(this.ots);
        
        
        
        //OT List
        this.cOTList = new List<cOT>();
        for(OT__c o : [Select Id, Codigo_2__c, Cantidad_2__c, Descripcion_2__c, Sub_Total__c, Exentas_2__c, Gravadas_IVA_10_2__c
        from OT__c  where Pre_Factura__c = :this.fct.Pre_Factura__r.id LIMIT 10]){
            cOTList.add(new cOT(o));
        }

        //LDD List
        this.cLddList = new List<cLdd>();
        for(Linea_de_detalle__c l : [Select Q__c, P_Unit_Linea__c, Total_Exentas__c, Total_Gravadas_IVA_10__c, Producto__r.Codigo__c,                   Producto__r.Descripcion__c from Linea_de_detalle__c Where OT__r.Pre_Factura__c = :this.fct.Pre_Factura__r.id LIMIT 10]){
            cLddList.add(new cLdd(l));
        }
    }



    public String getNumberToWords(){
        return NumberToSpanishWords.toSpanishWords( total );
    }


    public class cFactura{
        public Factura__c fct{get; set;}
        public String ST_Exentas{get;set;}
        public String ST_Gravadas_IVA10{get;set;}
        public String Total_a_Pagar{get;set;}
        public String IVA_10{get;set;}
        public String Descuento{get;set;}

        public cFactura(Factura__c f){
            this.fct = f;
            this.ST_Exentas = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.ST_Exentas__c);
            this.ST_Gravadas_IVA10 = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.ST_Gravadas_IVA10__c);
            this.Total_a_Pagar = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.Total_a_Pagar__c);
            this.IVA_10 = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.IVA_10__c);
            this.Descuento = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.Descuento__c);
        }
    }
    
    
    public class xOT{ //valores que se usa para la OT personalizada
        public OT__c ots{get; set;}
        public string cantper1 {get; set;}
        public string cantper2 {get; set;}
        public string cantper3 {get; set;}
        public string cantper4 {get; set;}
        public string cantper5 {get; set;}
        public string precio1 {get; set;}
        public string precio2 {get; set;}
        public string precio3 {get; set;}
        public string precio4 {get; set;}
        public string precio5 {get; set;}
        public string totalexenta1 {get; set;}
        public string totalexenta2 {get; set;}
        public string totalexenta3 {get; set;}
        public string totalexenta4 {get; set;}
        public string totalexenta5 {get; set;}
        public string totalgravada1 {get; set;}
        public string totalgravada2 {get; set;}
        public string totalgravada3 {get; set;}
        public string totalgravada4 {get; set;}
        public string totalgravada5 {get; set;}
        
        
        public xOT(OT__c ot2) {
            this.ots=ot2;
            this.cantper1= NumberToSpanishWords.convertToEU(ot2.Cant_1__c);            
            this.cantper2= NumberToSpanishWords.convertToEU(ot2.Cant_2__c);
            this.cantper3= NumberToSpanishWords.convertToEU(ot2.Cant_3__c);
            this.cantper4= NumberToSpanishWords.convertToEU(ot2.Cant_4__c);
            this.cantper5= NumberToSpanishWords.convertToEU(ot2.Cant_5__c);
            this.precio1=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_1__c);
            this.precio2=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_2__c);
            this.precio3=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_3__c);
            this.precio4=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_4__c);
            this.precio5=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_5__c);
            this.totalexenta1=NumberToSpanishWords.convertToEU(ot2.Total_Ex_1__c);
            this.totalexenta2=NumberToSpanishWords.convertToEU(ot2.Total_Ex_2__c);
            this.totalexenta3=NumberToSpanishWords.convertToEU(ot2.Total_Ex_3__c);
            this.totalexenta4=NumberToSpanishWords.convertToEU(ot2.Total_Ex_4__c);
            this.totalexenta5=NumberToSpanishWords.convertToEU(ot2.Total_Ex_5__c);
            this.totalgravada1=NumberToSpanishWords.convertToEU(ot2.Total_Gra_1__c);
            this.totalgravada2=NumberToSpanishWords.convertToEU(ot2.Total_Gra_2__c);
            this.totalgravada3=NumberToSpanishWords.convertToEU(ot2.Total_Gra_3__c);
            this.totalgravada4=NumberToSpanishWords.convertToEU(ot2.Total_Gra_4__c);
            this.totalgravada5=NumberToSpanishWords.convertToEU(ot2.Total_Gra_5__c);
     }
     
    }       
            
    public class cOT{ //valores que se usa para cuando la Pre_Factura tiene mas de una OT
        public OT__c OT{get; set;}
        public String Sub_Total{get;set;}
        public String Exentas_2{get;set;}
        public String Gravadas_IVA_10_2{get;set;}

        public cOT(OT__c o){
            this.OT = o;
            this.Sub_Total = NumberToSpanishWords.convertToEU(o.Sub_Total__c);
            this.Exentas_2 = NumberToSpanishWords.convertToEU(o.Exentas_2__c);
            this.Gravadas_IVA_10_2 = NumberToSpanishWords.convertToEU(o.Gravadas_IVA_10_2__c);
            
        } 
    }

    public class cLdd{
        public Linea_de_detalle__c LDD{get; set;}
        public String P_Unit_Linea{get;set;}
        public String Total_Exentas{get;set;}
        public String Total_Gravadas_IVA_10{get;set;}

        public cLdd(Linea_de_detalle__c l){
            this.LDD = l;
            this.P_Unit_Linea = NumberToSpanishWords.convertToEU(l.P_Unit_Linea__c);
            this.Total_Exentas = NumberToSpanishWords.convertToEU(l.Total_Exentas__c);
            this.Total_Gravadas_IVA_10 = NumberToSpanishWords.convertToEU(l.Total_Gravadas_IVA_10__c);
        }
    }
}


this is the test that I diid but it gives me this error:
FacturaPDFControllerTest.testFacturaPDFController(), Details, System.QueryException: List has no rows for assigment to sObject Class.FacturaPDFController <ini>: line 21 column 1
Class.FacturaPDFControllerTest.testFacturaPDFController:line 22, column 1

@isTest
public class FacturaPDFControllerTest {
   public static testMethod void testFacturaPDFController() {
         Pre_Factura__c prefactura = new Pre_Factura__c ();
         insert prefactura;
       
         Factura__c fac = new Factura__c(Pre_Factura__c = prefactura.id);
          /*Write code to populate fields. See my note below*/ 
            fac.Pre_impreso__c=1234999;
            fac.Pre_impreso_001_001__c=1234999;
            fac.Pre_impreso_002_001__c=1234999;
            fac.Pre_impreso_002_002__c=1234999;
            fac.Pre_impreso_003_001__c=1234999;
            fac.Caja__c='Caja 1';
            fac.Serie__c='Serie 1';
            fac.Sucursal__c='Maker Villa Morra';
                
            insert fac;
 
   
         ApexPages.StandardController fact = new ApexPages.StandardController(fac);       
         FacturaPDFController facts = new FacturaPDFController(fact);
         facts.total=1000;
         facts.getNumberToWords();
         System.assert(facts.fct  <> NULL);

      }
  }
Hello, I'm trying to deploy an apex class to production but I can't because it gives me 72% of coverage code.
This is my apex class;
Does anyone know how to test this apex class? I really will appreciate any help

public with sharing class FacturaPDFController {

    private final Factura__c fct;
    public cFactura cfct{get; set;}
    public OT__c ots{get; set;}
    public xOT otts {get; set;}
    public Integer total{get; set;}
    public List<cOT> cOTList{get;set;}
    public List<cLdd> cLddList{get;set;}

    public FacturaPDFController(ApexPages.StandardController controller) {
        this.fct =  [Select Id, Pre_Factura__r.ST_Exentas__c, Pre_Factura__r.Descuento__c, Pre_Factura__r.ST_Gravadas_IVA10__c,                         Pre_Factura__r.Total_a_Pagar__c, Pre_Factura__r.IVA_10__c From Factura__c  Where Id = :controller.getId()];
        this.cfct = new cFactura(this.fct);
        total = Integer.valueOf( this.fct.Pre_Factura__r.Total_a_Pagar__c );



        //OT personalizado
        this.ots= [Select Cant_1__c,Cant_2__c,Cant_3__c,Cant_4__c,Cant_5__c, Texto_1_fact__c,Texto_2_fact__c,Texto_3_fact__c,
        Texto_4_fact__c,Texto_5_fact__c, Precio_Unit_1__c, Precio_Unit_2__c, Precio_Unit_3__c, Precio_Unit_4__c, Precio_Unit_5__c,
        Total_Ex_1__c, Total_Ex_2__c, Total_Ex_3__c, Total_Ex_4__c, Total_Ex_5__c,
        Total_Gra_1__c, Total_Gra_2__c, Total_Gra_3__c, Total_Gra_4__c, Total_Gra_5__c        
        from OT__c  where Pre_Factura__c = :this.fct.Pre_Factura__r.id];
        this.otts=new xOT(this.ots);
        
        
        
        //OT List
        this.cOTList = new List<cOT>();
        for(OT__c o : [Select Id, Codigo_2__c, Cantidad_2__c, Descripcion_2__c, Sub_Total__c, Exentas_2__c, Gravadas_IVA_10_2__c
        from OT__c  where Pre_Factura__c = :this.fct.Pre_Factura__r.id LIMIT 10]){
            cOTList.add(new cOT(o));
        }

        //LDD List
        this.cLddList = new List<cLdd>();
        for(Linea_de_detalle__c l : [Select Q__c, P_Unit_Linea__c, Total_Exentas__c, Total_Gravadas_IVA_10__c, Producto__r.Codigo__c,                   Producto__r.Descripcion__c from Linea_de_detalle__c Where OT__r.Pre_Factura__c = :this.fct.Pre_Factura__r.id LIMIT 10]){
            cLddList.add(new cLdd(l));
        }
    }



    public String getNumberToWords(){
        return NumberToSpanishWords.toSpanishWords( total );
    }


    public class cFactura{
        public Factura__c fct{get; set;}
        public String ST_Exentas{get;set;}
        public String ST_Gravadas_IVA10{get;set;}
        public String Total_a_Pagar{get;set;}
        public String IVA_10{get;set;}
        public String Descuento{get;set;}

        public cFactura(Factura__c f){
            this.fct = f;
            this.ST_Exentas = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.ST_Exentas__c);
            this.ST_Gravadas_IVA10 = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.ST_Gravadas_IVA10__c);
            this.Total_a_Pagar = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.Total_a_Pagar__c);
            this.IVA_10 = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.IVA_10__c);
            this.Descuento = NumberToSpanishWords.convertToEU(f.Pre_Factura__r.Descuento__c);
        }
    }
    
    
    public class xOT{ //valores que se usa para la OT personalizada
        public OT__c ots{get; set;}
        public string cantper1 {get; set;}
        public string cantper2 {get; set;}
        public string cantper3 {get; set;}
        public string cantper4 {get; set;}
        public string cantper5 {get; set;}
        public string precio1 {get; set;}
        public string precio2 {get; set;}
        public string precio3 {get; set;}
        public string precio4 {get; set;}
        public string precio5 {get; set;}
        public string totalexenta1 {get; set;}
        public string totalexenta2 {get; set;}
        public string totalexenta3 {get; set;}
        public string totalexenta4 {get; set;}
        public string totalexenta5 {get; set;}
        public string totalgravada1 {get; set;}
        public string totalgravada2 {get; set;}
        public string totalgravada3 {get; set;}
        public string totalgravada4 {get; set;}
        public string totalgravada5 {get; set;}
        
        
        public xOT(OT__c ot2) {
            this.ots=ot2;
            this.cantper1= NumberToSpanishWords.convertToEU(ot2.Cant_1__c);            
            this.cantper2= NumberToSpanishWords.convertToEU(ot2.Cant_2__c);
            this.cantper3= NumberToSpanishWords.convertToEU(ot2.Cant_3__c);
            this.cantper4= NumberToSpanishWords.convertToEU(ot2.Cant_4__c);
            this.cantper5= NumberToSpanishWords.convertToEU(ot2.Cant_5__c);
            this.precio1=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_1__c);
            this.precio2=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_2__c);
            this.precio3=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_3__c);
            this.precio4=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_4__c);
            this.precio5=NumberToSpanishWords.convertToEU(ot2.Precio_Unit_5__c);
            this.totalexenta1=NumberToSpanishWords.convertToEU(ot2.Total_Ex_1__c);
            this.totalexenta2=NumberToSpanishWords.convertToEU(ot2.Total_Ex_2__c);
            this.totalexenta3=NumberToSpanishWords.convertToEU(ot2.Total_Ex_3__c);
            this.totalexenta4=NumberToSpanishWords.convertToEU(ot2.Total_Ex_4__c);
            this.totalexenta5=NumberToSpanishWords.convertToEU(ot2.Total_Ex_5__c);
            this.totalgravada1=NumberToSpanishWords.convertToEU(ot2.Total_Gra_1__c);
            this.totalgravada2=NumberToSpanishWords.convertToEU(ot2.Total_Gra_2__c);
            this.totalgravada3=NumberToSpanishWords.convertToEU(ot2.Total_Gra_3__c);
            this.totalgravada4=NumberToSpanishWords.convertToEU(ot2.Total_Gra_4__c);
            this.totalgravada5=NumberToSpanishWords.convertToEU(ot2.Total_Gra_5__c);
     }
     
    }       
            
    public class cOT{ //valores que se usa para cuando la Pre_Factura tiene mas de una OT
        public OT__c OT{get; set;}
        public String Sub_Total{get;set;}
        public String Exentas_2{get;set;}
        public String Gravadas_IVA_10_2{get;set;}

        public cOT(OT__c o){
            this.OT = o;
            this.Sub_Total = NumberToSpanishWords.convertToEU(o.Sub_Total__c);
            this.Exentas_2 = NumberToSpanishWords.convertToEU(o.Exentas_2__c);
            this.Gravadas_IVA_10_2 = NumberToSpanishWords.convertToEU(o.Gravadas_IVA_10_2__c);
            
        } 
    }

    public class cLdd{
        public Linea_de_detalle__c LDD{get; set;}
        public String P_Unit_Linea{get;set;}
        public String Total_Exentas{get;set;}
        public String Total_Gravadas_IVA_10{get;set;}

        public cLdd(Linea_de_detalle__c l){
            this.LDD = l;
            this.P_Unit_Linea = NumberToSpanishWords.convertToEU(l.P_Unit_Linea__c);
            this.Total_Exentas = NumberToSpanishWords.convertToEU(l.Total_Exentas__c);
            this.Total_Gravadas_IVA_10 = NumberToSpanishWords.convertToEU(l.Total_Gravadas_IVA_10__c);
        }
    }
}
I have a custom object called Questions. This object has a lookup to itself because a question can have additional questions which depend on their parent question. We need to insert 200+ at a time so I wrote an apex class that simply inserts the collection given to it:

global with sharing class QuestionRestController{
   global class RequestBody {
       global List<Question__c> questions;
   }

    @HttpPost   
    global static List<Question__c> createBulk(QuestionRestController.RequestBody req) {
        insert req.questions;
        return req.questions;
    }
}

I get this error: System.DmlException: Insert failed. First exception on row 94; first error: INVALID_FIELD, Foreign key external ID: 966.0 not found for field MyExtId__c in entity Question__c no matter what I try.

I figured I could sort the questions before sending the request so that the parent questions are always inserted first but I still get the errors. I've added debug statements so I could verify the order of the questions prior to inserting and they are ordered correctly. I've also tried to insert each question by itself:

for (Question__c question: req.questions) {
    insert question;
}

But then I get a System.LimitException because I'm sending 200+ questions.

So what is the proper way to insert a list of custom objects which have a lookup to itself when the parent and child are both being inserted with the same request?

Thanks
I'm setting up a project in Eclipse to download all of our workflow rules.  I select all for Workflow rules and I see many files in the workflows directory; Account.workflow, Opportunity.workflow, etc.  However, Contact.workflow is missing.  There's also another custom object we have that's missing.  But there are some custom objects there that don't even have any workflows.

I looked through the logs and saw some Java exceptions at the time of a metadata refresh but they didn't give me a clue as to why this would be happening.  Does anybody have any clues as to why some metadata components would be downloaded while others aren't being downloaded?

Thanks!!
I have a program that runs every morning at 4:00 am.  Since it does some CPU intensive calculations I put some of the heavy lifting into five future functions that are called from within the main program.  Things generally are working fine.

Occassionally, I'll get a message about locked rows.  This is, of course, quite bad as some of my updates just don't happen.

I did some other coding with batch files and got around this by having Batch-1 call Batch-2 which calls Batch-3, etc.  Is there some way to make sure five different future calls won't run at the same time?

Thanks!
Hello 

 I have 95% covergae in production , and I moving classes/triggers that have (97%) coverage in dev. 

Whan I deploy in production , I am getting the error 

Code Coverage Failure
Your organization's code coverage is 73%. You need at least 75% coverage to complete this deployment.

what am I missing here !?

Thanks 

Hi,

Could u please help me in the following scnearios - 

1. I have a vf page which displays list of cases with a picklist in each row and a save button. I want when i press save button it will save the record and redirect me to the same page. 

Currently i am not using any custom controller  and the save button after click is re-directing to home page.
We were upgraded to Summer '14 over the weekend.  Now I have tests that are failing that haven't failed in months.  The issue is that I'm running several versions of a batch process to catch various parts of the code.  It's now complaining that I'm running more than 5 batch processes on our network and that's why the test is failing.

I checked and the test code on production hasn't been changed since February but just started failing this week.

Any ideas?  Thanks!!
Hi !

I have a simple test method which creates an Account and a Contact. A trigger on Contact which sets a field based on the Account's BillingState. Problem is when the trigger fires the Billing state evelautes to null. I cannot understand as to why. Here is test method setting these up.

test method:

static testMethod void validate() {
     
        Test.startTest();
         
        account[] accounts = new account[]{
        new account(name='highschool',BillingState='CA',BillingPostalCode='92100') };
 
        insert accounts;

        contact[] contacts = new contact[] {
        new contact(LastName='Sand10',TargetX_SRMb__Student_Type__c='New Freshman',accountId=accounts[0].id)};
 
        insert contacts;
        Test.stopTest();

        List<contact> con = [select id, LastName, FirstName,TargetX_SRMb__Student_Type__c,TargetX_SRMb__College__c,account.BillingState, account.billingPostalCode,Territory_Assignments__c from Contact];
         
        for(Contact e: con) {
    
        System.debug('Last name.......... '+e.lastname+'  State '+e.account.BillingState);   // this actually DOES return BillingState
}

In trigger logic:

...
if(String.isNotBlank(c.TargetX_SRMb__Student_Type__c) ){ 
     system.debug('lastname in trigger: '+c.lastname+' state is '+c.account.billingState);    // this shows null for BillingState
        //look at territory state
        if(String.isNotBlank(c.Account.BillingState)){
              system.debug('not blank');                                    // never get here
.....    
Thanks,
Jon