• dnakoni
  • NEWBIE
  • 105 Points
  • Member since 2009

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 31
    Replies

my parent custom object is Presupuesto__c, my child custom object is Movimiento_Presupuestal__c,  i wanna create new field in child object with a trigger when i insert new parent field:

 

trigger calculosPresupuesto on Presupuesto__c (before insert, before update) {

 

List<Sobject> child = new List<Sobject>();
 if(Trigger.isInsert){         
  Double presAnual;  
  String presid;  
  Date fecha_hoy = Date.today(); 
  Presupuesto__c [] pre = Trigger.new;      
  
  for(Presupuesto__c p : pre){   
     if(p.Presupuesto_Anual_Aprobado__c != 0){
    Double valorMes = p.Presupuesto_Anual_Aprobado__c / 12;
    presAnual = p.Presupuesto_Anual_Aprobado__c;
    presid = p.Id;
  p.Presupuesto_de_Enero__c = valorMes;
  p.Presupuesto_de_Febrero__c = valorMes;
  p.Presupuesto_de_Marzo__c = valorMes;
  p.Presupuesto_de_Abril__c = valorMes;
  p.Presupuesto_de_Mayo__c = valorMes; 
  p.Presupuesto_de_Junio__c = valorMes;
 p.Presupuesto_de_Julio__c = valorMes;
p.Presupuesto_de_Agosto__c = valorMes;
p.Presupuesto_de_Septiembre__c = valorMes; 
p.Presupuesto_de_Octubre__c = valorMes;  
p.Presupuesto_de_Noviembre__c = valorMes;
p.Presupuesto_de_Diciembre__c = valorMes;
    
p.Balance_Enero__c = p.Presupuesto_de_Enero__c - p.Gastos_Enero__c - p.Reserva_Enero__c;
p.Balance_Febrero__c = p.Presupuesto_de_Febrero__c - p.Gastos_Febrero__c - p.Reserva_Febrero__c;
p.Balance_Marzo__c = p.Presupuesto_de_Marzo__c - p.Gastos_Marzo__c - p.Reserva_Marzo__c;
p.Balance_Abril__c = p.Presupuesto_de_Abril__c - p.Gastos_Abril__c - p.Reserva_Abril__c;
p.Balance_Mayo__c = p.Presupuesto_de_Mayo__c - p.Gastos_Mayo__c - p.Reserva_Mayo__c;
p.Balance_Junio__c = p.Presupuesto_de_Junio__c - p.Gastos_Junio__c - p.Reserva_Junio__c;
     p.Balance_Julio__c = p.Presupuesto_de_Julio__c - p.Gastos_Julio__c - p.Reserva_Julio__c;
p.Balance_Agosto__c = p.Presupuesto_de_Agosto__c - p.Gastos_Agosto__c - p.Reserva_Agosto__c;
p.Balance_Septiembre__c = p.Presupuesto_de_Septiembre__c - p.Gastos_Septiembre__c - p.Reserva_Septiembre__c;
    p.Balance_Octubre__c = p.Presupuesto_de_Octubre__c - p.Gastos_Octubre__c - p.Reserva_Octubre__c;
p.Balance_Noviembre__c = p.Presupuesto_de_Noviembre__c - p.Gastos_Noviembre__c - p.Reserva_Noviembre__c;
p.Balance_Diciembre__c = p.Presupuesto_de_Diciembre__c - p.Gastos_Diciembre__c - p.Reserva_Diciembre__c;
p.Balance_Anual__c = p.Presupuesto_Anual_Aprobado__c - p.Gasto_Anual__c - p.Reserva_Anual__c;   
 
Movimiento_Presupuestal__c mov = new Movimiento_Presupuestal__c
(Fecha_de_Movimiento__c = fecha_hoy, 
Abono__c = presAnual, 
cuenta__c = p.Id );  
child.add(mov); 
insert child;
}       

 

}

 

but the error is:

 

 

Description Resource Path Location Type

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, calculosPresupuesto: execution of BeforeInsert

 

caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, required fields missings: [Cuenta__c]: [Cuenta__c]

 

 

 

I have a successfully working controller and VF page.  Part of the reason for this controller was to bypass sharing rules.  BUT,  I need one of the methods in this controller to run with sharing.  So, I essentially created a standalone "with sharing" class with 1 method that does the querying, and returns the list of accounts back to the main controller.

 

Here's the original controller method that works:

 

    public List<aAccount> getSTAccounts(){
        if (STaccountList == null){
                STaccountList = new List<aAccount>();
                //This  query returns all site accounts in the hierarchy of the opp account where Ship To = True
                for(Account a : [Select id, Site_Number__c, Name, BillingStreet, BillingState, BillingCity From Account where 
                              parentid =:ApexPages.currentPage().getparameters().get('parentid') and Active_Ship_To__c = true Order by BillingCity, BillingStreet]){
                              STaccountList.add(new aAccount(a)); 
                              }                                                      
        }
        return STaccountList;
    }

All I really need to do is execute the above query with sharing rules in place.  So here's my standalone class:

 

public with sharing class multiShipToUtility {
/*
This little utility class is part of the whole BMI multi-bill to ship-to picker app.
For selecting the ship to sites, we need that list to be driven by sharing rules.  
In the bill to selection, we want the user to be able to see ALL bill to sites, regarless of territory
But for ship tos, we want that to be driven by territory assignment.  
To accomplish both, I had to break out the ship to selection into a separate class with sharing.
*/     
     
     public  static List<Account> getSTAccounts(string stParentId){
                string stID = stparentId;
                List<Account> STaccountList = new List<Account>();
                //This  query returns all site accounts in the hierarchy of the opp account where Ship To = True
                for(Account a : [Select id, Site_Number__c, Name, BillingStreet, BillingState, BillingCity From Account where 
                              parentid =: stParentId and Active_Ship_To__c = true Order by BillingCity, BillingStreet]){
                              STaccountList.add(a); 
                              }                                                      

        return STaccountList; 
     } 
}

 

So, back to the  main controller, I re-wrote the method like this:

 

    public List<aAccount> getSTAccounts(){

        if (STaccountList == null){
        string stParentID = ApexPages.currentPage().getparameters().get('parentid');
        List<Account> shipTos = new List<Account>();
        shipTos = multiShipToUtility.getSTAccounts(stParentID);
        for (Account a: shipTos){
        	STaccountList.add(new aAccount(a));
        }

       
        return STaccountList;    
        }

 

 

This won't compile with the message Non-void method might not return a value or might have statement after a return statement".

I researched this error a bit, and then added a basic else clause to the if-block above to return an empty list.  This compiles, but then blows up when I run the page:  "Attempt to de-reference a null object"

 

I also tried removing the static keyword from the method, but that doesn't compile eiter. 

 

So I'm totally stuck now.  Can anyone offer any suggestions? 

 

 

 

 

 

Is it possible to access fields of another object based on just an ID?  For instance, through SOQL i get a list of opportunity IDs with owner IDs.  Can I get to User fields like department, division, etc. using just the owner ID without needing another SOQL query?

Hey guys,

 

Is there a way to check (in apex) whether the current user has an Edit access to a particular Account record?

 

If there's not, I was thinking about creating a database savepoint, updating the record, catching the DML exception (if any), and then performing a rollback.

 

 

Does anyone know how I can check whether the current user has some kind of access to a particular record?

 

Let's say I have a custom VF page with an Account standard controller, and an extension. In the extension, I want to check whether the current user has UPDATE access to the current Account record on the VF page. I found the isAccessible/isUpdateable methods, but those are on a field/object level, they do not look at particular records.

 

Thanks!!

 

I'm having a weird issue with the Debug log. I set all the filters to NONE except Database, which I set to FINEST. When I look at the log, on top it says:
20.0 DB,FINEST
which means that the filters were set correctly. However, the log quickly fills up with statements like these:
CODE_UNIT_STARTED|[EXTERNAL]|BasicSearchComponentController set(searchManager,CandidateSearchController:[css=null,…….. HUGE AMOUNT OF DATA HERE
The "HUGE AMOUNT OF DATA HERE" lines have what looks to me like a serialized version of my component controller, with all its instance variables, etc. Now, I am not printing out my controller to the debug log, and even if I was, it would show up under USER_DEBUG. The problem here is that every filter is set to NONE, except Database, so I'm really stumped here.
Any help would be appreciated.

 

I am issuing a query in Apex code (in a controller) to lookup some contacts. I am doing a limit 500 on the query, but there are about 10 million contacts in the system. When doing it through SoqlXplorer it is fast. However, when issuing the query in Apex, it takes a long time, sometimes causing the code to time out. Is there a way to speed up queries? I know it has to go through a lot of records to come up with the 500 records (in my LIMIT 500 ) but this is ridiculous. 

 

Any thoughts?

 

Thanks,

Dan

  • September 07, 2010
  • Like
  • 0

Does anyone know the limits of API SOQL calls? I have an aggregate query that, when run inside a VF controller, gives out a Too many query rows (16,125) error. However, the same query ran from SOQLXplorer returns no error and shows me the data.

Did anyone received this error before? I tried to run batch apex throughout the day to test it and it was running ok and completing in around 20 mins. Now I tried scheduling it and just as it started running it failed with the following error:

 

"First error: Unable to access query cursor data; too many cursors are in use."

 

Any ideas?

 

 

I have the following problem:

 

LastName is a required field on a Lead. Is there a way to change that? I have a requirement stating that Last Name should be optional, but no way to change it. Any ideas?

 

Thank you.

Hi, 

 

I am trying to control what to display on a NotesAndAttachments related list on my Visualforce page. I am using the 'header' facet to remove access to New Note and Attach File buttons. However, what options are there for the 'body' facet? What I want to do is remove the 'Del' and 'Edit' links, and only leave the 'View' link. Is there any way to do that?

 

Thanks.

How do I access the cid that comes with an email attachment? For example, I have two <img> tags in my email, with their src of cid:something here.

 

And then in the last part of the email:

 

Content-Type: image/png
Content-Transfer-Encoding: base64
Content-ID: <chart_01Z30000000VWm7_1266606255000_6.png>
X-Attachment-Id: 0.7

 

BASE64 DATA HERE

 

 

 

My question is, how do I access the Content-ID in Apex EmailAttachments (or any other class) so that I can save that content ID on a particular custom object's field I created?

 

The cid is in the body in the HTML (in the IMG tag), that's why it knows which image to display where, but I want to access the attachment's content-id so that I can match the IMG tag to its content-id manually.

 

Thanks.

I know there's the Bulk API for mass uploading/updating records in salesforce. Is there a way to mass download records also? I am using the normal API in my Flex app to get records from salesforce and do some processing on them. Right now, you can only get back 500 (or something) records at a time, so I have to do QueryMore and that slows down my program.

 

So to recap, is there a way to mass download records from salesforce? 

I created a custom object AccountContactAssociation that servers as a many-to-many join. It has two custom Master-Detail fields. 

 

One is named Account and is a Master-Detail(Account).

One is named Contact and is a Master-Detail(Contact).

 

I'm trying to create a trigger as follows:

 

 

trigger AccountContactAssociationTrigger on AccountContactAssociation__c (after insert) {

AccountContactAssociation__c ac = Trigger.new[0];

 

  

  ac.Contact.FirstName = ac.Account.Name;

 

 

 

 

What I am basically trying to do is to access a field in the Account that is referenced by the junction object (in this case string Name) and assign it to a FirstName field in the referenced Contact object.

 

 

The above code does not compile, and I have a hard time figuring how to access the abovementioned fields.

 

 

I would greatly appreciate any suggestions.

 

Thanks! 

I'm attempting to use the Blob.toPdf function sending in an HTML string. The resulting PDF is not very well formatted. 

In the code below, I'm attempting to create a couple of tables and line up columns. The html works when I perform the "RenderAs=PDF" in a visual force page. I'm trying to replicate that using the Blob.toPDF() function.

 

 

Here is the test program I'm trying to run. If you paste this into an apex class, you can cut an paste the code inside the "testBlobPDF" and in an anonymus window and execute.

 

/**
 * Testing the ability to convert a string to a PDF file.
 */
@isTest
public class testBlobToPDF 
{

    public static testMethod void testBlobPDF() 
    {
        string PDFBody = testBlobToPDF.Body();
        Blob pdfBlob = Blob.toPDF(PDFBody);
        testBlobToPDF.SaveBlobToDoc(pdfBlob);
    }
    
    public static void SaveBlobToDoc (Blob blobPDF)
    {
    	string FileName = 'TestPDF';
    	Document doc;
    	list<Document> docs = [Select ID, Name, Body, FolderID, DeveloperName, Type, ContentType From Document Where Name = :FileName];
    	if (docs.size() > 0)
    		doc = docs[0];
    	else
    	{
    		doc = new Document();
    		doc.Name = FileName;
    		doc.DeveloperName = FileName;
    		doc.Type = 'pdf';
    		doc.ContentType = 'application/pdf';
    		doc.FolderId = UserInfo.getUserId();  //PLaces this into the persons Personal Folder
    	}
    	
    	doc.Body = blobPDF;
    	upsert doc;
    }
    
    public static string Body()
    {
    	string bodyStr = 
'    <div style="position: absolute; width: 8.0459in; height: 10.1124in; font-family: Verdana; font-size: 11.0pt">' + 
'      <table width="100%" border="0" cellspacing="0" cellpadding="2" style="font-weight: bold">	' +
'        <tr>	' +
'            <td width="35%" style="vertical-align: top" align="left">	' +
'                Appointment For: 4/5/2012  1:00 PM	' +
'            </td>	' +
'            <td width="35%" style="vertical-align: top" align="left">	' +
'                improveit! 360, Dev0	' +
'            </td>	' +
'            </tr>' +
'       </table>' +
'    <table width="100%" cellspacing="0" cellpadding="2">	' +		
'        <tr>			' +
'            <td width="45%" style="vertical-align: top">		' +	
'                <table width="100%" border="0" cellspacing="0" cellpadding="2">		' +	
'                    <tr>			' +
'                        <td style="vertical-align: top" width="25%" >			' +
'                            Name(s):			' +
'                        </td>			' +
'                        <td  width="75%" >			' +
'                            Christopher Miller	' +	
'                        </td>			' +
'                    </tr>			' +
'                    <tr>			' +
'                        <td style="vertical-align: top" width="25%" >			' +
'                            Address:			' +
'                        </td>			' +
'                        <td  width="75%" >			' +
'                            420 Pine Blvd.<br />			' +
'                            Stockton-515887724, VA 43201<br />			' +
'                        </td>			' +
'                    </tr>			' +
'                    <tr>			' +
'                        <td style="vertical-align: top" width="25%" >			' +
'                            Phone(s):			' +
'                        </td>' +			
'                        <td  width="75%" >' +			
'                            (234) 373-8468 Home<br />' +			
'                            (233) 246-8194 Home<br />' +			
'                             			' +
'                        </td>			' +
'                    </tr>' +			
'                </table>' +			
'            </td>' +			
'            <td width="45%" style="vertical-align: top">' +			
'                <table width="100%" cellspacing="0" cellpadding="2" style="border: 1px solid black;">' +			
'                    <tr>' +			
'                        <td style="vertical-align: top" width="25%" >' +			
'                            Status:' +			
'                        </td>' +			
'                        <td  width="75%" >' +			
'                            Assigned' +			
'                        </td>' +			
'                    </tr>' +			
'                    <tr>' +			
'                        <td style="vertical-align: top" width="25%" >' +			
'                            Type:' +			
'                        </td>' +			
'                        <td  width="75%" >' +			
'                            New			' +
'                        </td>' +			
'                    </tr>' +			
'                    <tr>' +			
'                        <td style="vertical-align: top" width="25%" >' +			
'                            Date / Time:' +			
'                        </td>' +			
'                        <td  width="75%" >' +			
'                            4/5/2012  1:00 PM' +			
'                        </td>' +			
'                    </tr>' +			
'                    <tr>' +			
'                        <td style="vertical-align: top" width="25%" >' +			
'                            Duration:' +			
'                        </td>' +			
'                        <td  width="75%" >' +			
'2' +			
'                        </td>' +			
'                    </tr>' +			
'                    <tr>' +			
'                        <td style="vertical-align: top" width="25%" >' +			
'                            Rep 1:' +			
'                        </td>' +			
'                        <td  width="75%" >' +			
'                            Jeff Clark' +			
'                        </td>' +			
'                    </tr>' +			
'                    <tr>' +			
'                        <td style="vertical-align: top" width="25%" >' +			
'                            Rep 2:' +			
'                        </td>' +			
'                        <td  width="75%" >' +			
'                        </td>' +			
'                    </tr>' +
'                </table>' +			
'            </td>' +			
'        </tr>' +			
'        </table>' +			
'     </div>';
		return bodystr;
		
    	
    }
}

 

 

Thanks in advance,

 

Jeff Clark

Does anyone know how I can check whether the current user has some kind of access to a particular record?

 

Let's say I have a custom VF page with an Account standard controller, and an extension. In the extension, I want to check whether the current user has UPDATE access to the current Account record on the VF page. I found the isAccessible/isUpdateable methods, but those are on a field/object level, they do not look at particular records.

 

Thanks!!

Hi All, I have met a problem and have no idea how to handle it. Here is the situation: I need to write a SOQL sentence like "SELECT field1 FROM object1" but in my case I don't know the value of fields1 in the first place. There is a string to hold the value. How can write the SOQL sentence to use this string value. Thanks

Hi, Can't seem to figure out as to why this piece of code always returns a Null value and always executes the if statement even when there is an entry in the table. Thanks


                   if (currentBuyerId.get(a.UserOrGroupId) == NULL){
                    //If UserOrGroupId does not exist
                    //Add records being shared with buyers into the array for later insert
                    relationShare.add(buyerShare);      
                }

 

**********************

 

trigger Buyer_Supplier_Share on mcbangalore__Relation__c (after insert,after update) {

AccountShare buyerShare = new AccountShare();
List<AccountShare> relationshare = new List<AccountShare>();
id badId = '00550000001DzCR';

//
if ( trigger.isInsert||trigger.isUpdate) {

    for(Relation__c relation:trigger.new) {
        
        //Retrieve every supplier sharing record and insert it into the Buyer Sharing table
        
         List<AccountShare> supplierShare= [Select AccountId, UserOrGroupId from AccountShare
                        where AccountId =:relation.Supplier__c];

        //Map the Ids and UserOrGroup Ids of the Buyer Record to prevent duplicate entries
    
        Map<Id, AccountShare> currentBuyerId = new Map<Id,AccountShare> ([Select UserOrGroupId,AccountId from AccountShare
                        where AccountId = :relation.Buyer__c]);
        
        for (AccountShare a :supplierShare) {   
        
            //Share the Buyer Account with the Sellers;
            buyerShare.AccountId = relation.Buyer__c;
            //Share the Seller Account with all the Buyer Contacts
            buyerShare.UserOrGroupId = a.UserorGroupId;
            
            //Set the access level
            buyerShare.AccountAccessLevel = 'edit';
            //Set the Sharing Reason
            //buyerShare.RowCause = schema.Relation__Share.Rowcause.Grant_Relationship__c;
        
            //Check if the UserOrGroupId already exists for this Id
                
                   if (currentBuyerId.get(a.UserOrGroupId) == NULL){
                    //If UserOrGroupId does not exist
                    //Add records being shared with buyers into the array for later insert
                    relationShare.add(buyerShare);      
                }

    
            } //For AccountShare a
        } //for trigger.new
    } //If (trigger.IsInsert)


//Insert Array into the database
Database.SaveResult[] buyerresult = Database.insert(relationShare,false);

//Process Errors

Hi everyone.

 

I have been trying to find this in the System Log but have found nothing. Can anyone tell me if they know of a way for me to read/capture the outgoing SOAP message generated by an Apex Class?

 

Regards,

Ivar

  • March 04, 2011
  • Like
  • 0

Anyone know how to test Catch blocks. I've looked around for creating Catch test conditions but have been unsuccessful so far.

 

Code Snippet:

            insert skEnroll;
        } 
        catch (DMLException e) {            
            ApexPages.addMessages(e);            
            return null;
        }
        return page.aeskenrollconfirm; 
    }        
}

 

my parent custom object is Presupuesto__c, my child custom object is Movimiento_Presupuestal__c,  i wanna create new field in child object with a trigger when i insert new parent field:

 

trigger calculosPresupuesto on Presupuesto__c (before insert, before update) {

 

List<Sobject> child = new List<Sobject>();
 if(Trigger.isInsert){         
  Double presAnual;  
  String presid;  
  Date fecha_hoy = Date.today(); 
  Presupuesto__c [] pre = Trigger.new;      
  
  for(Presupuesto__c p : pre){   
     if(p.Presupuesto_Anual_Aprobado__c != 0){
    Double valorMes = p.Presupuesto_Anual_Aprobado__c / 12;
    presAnual = p.Presupuesto_Anual_Aprobado__c;
    presid = p.Id;
  p.Presupuesto_de_Enero__c = valorMes;
  p.Presupuesto_de_Febrero__c = valorMes;
  p.Presupuesto_de_Marzo__c = valorMes;
  p.Presupuesto_de_Abril__c = valorMes;
  p.Presupuesto_de_Mayo__c = valorMes; 
  p.Presupuesto_de_Junio__c = valorMes;
 p.Presupuesto_de_Julio__c = valorMes;
p.Presupuesto_de_Agosto__c = valorMes;
p.Presupuesto_de_Septiembre__c = valorMes; 
p.Presupuesto_de_Octubre__c = valorMes;  
p.Presupuesto_de_Noviembre__c = valorMes;
p.Presupuesto_de_Diciembre__c = valorMes;
    
p.Balance_Enero__c = p.Presupuesto_de_Enero__c - p.Gastos_Enero__c - p.Reserva_Enero__c;
p.Balance_Febrero__c = p.Presupuesto_de_Febrero__c - p.Gastos_Febrero__c - p.Reserva_Febrero__c;
p.Balance_Marzo__c = p.Presupuesto_de_Marzo__c - p.Gastos_Marzo__c - p.Reserva_Marzo__c;
p.Balance_Abril__c = p.Presupuesto_de_Abril__c - p.Gastos_Abril__c - p.Reserva_Abril__c;
p.Balance_Mayo__c = p.Presupuesto_de_Mayo__c - p.Gastos_Mayo__c - p.Reserva_Mayo__c;
p.Balance_Junio__c = p.Presupuesto_de_Junio__c - p.Gastos_Junio__c - p.Reserva_Junio__c;
     p.Balance_Julio__c = p.Presupuesto_de_Julio__c - p.Gastos_Julio__c - p.Reserva_Julio__c;
p.Balance_Agosto__c = p.Presupuesto_de_Agosto__c - p.Gastos_Agosto__c - p.Reserva_Agosto__c;
p.Balance_Septiembre__c = p.Presupuesto_de_Septiembre__c - p.Gastos_Septiembre__c - p.Reserva_Septiembre__c;
    p.Balance_Octubre__c = p.Presupuesto_de_Octubre__c - p.Gastos_Octubre__c - p.Reserva_Octubre__c;
p.Balance_Noviembre__c = p.Presupuesto_de_Noviembre__c - p.Gastos_Noviembre__c - p.Reserva_Noviembre__c;
p.Balance_Diciembre__c = p.Presupuesto_de_Diciembre__c - p.Gastos_Diciembre__c - p.Reserva_Diciembre__c;
p.Balance_Anual__c = p.Presupuesto_Anual_Aprobado__c - p.Gasto_Anual__c - p.Reserva_Anual__c;   
 
Movimiento_Presupuestal__c mov = new Movimiento_Presupuestal__c
(Fecha_de_Movimiento__c = fecha_hoy, 
Abono__c = presAnual, 
cuenta__c = p.Id );  
child.add(mov); 
insert child;
}       

 

}

 

but the error is:

 

 

Description Resource Path Location Type

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, calculosPresupuesto: execution of BeforeInsert

 

caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, required fields missings: [Cuenta__c]: [Cuenta__c]

 

 

 

Hi

i just meet one question, when i convert the string to integer type. i used the integer.valueof() method . but if string like 'ABCDEF' that can't  do integer conversion but throw System.TypeException.

could i do judgement first first? like if the string parameter s='123'  can do integer conversion, and then i call the integer.valueof(s)

is there any method ??

 

 

 

I have a successfully working controller and VF page.  Part of the reason for this controller was to bypass sharing rules.  BUT,  I need one of the methods in this controller to run with sharing.  So, I essentially created a standalone "with sharing" class with 1 method that does the querying, and returns the list of accounts back to the main controller.

 

Here's the original controller method that works:

 

    public List<aAccount> getSTAccounts(){
        if (STaccountList == null){
                STaccountList = new List<aAccount>();
                //This  query returns all site accounts in the hierarchy of the opp account where Ship To = True
                for(Account a : [Select id, Site_Number__c, Name, BillingStreet, BillingState, BillingCity From Account where 
                              parentid =:ApexPages.currentPage().getparameters().get('parentid') and Active_Ship_To__c = true Order by BillingCity, BillingStreet]){
                              STaccountList.add(new aAccount(a)); 
                              }                                                      
        }
        return STaccountList;
    }

All I really need to do is execute the above query with sharing rules in place.  So here's my standalone class:

 

public with sharing class multiShipToUtility {
/*
This little utility class is part of the whole BMI multi-bill to ship-to picker app.
For selecting the ship to sites, we need that list to be driven by sharing rules.  
In the bill to selection, we want the user to be able to see ALL bill to sites, regarless of territory
But for ship tos, we want that to be driven by territory assignment.  
To accomplish both, I had to break out the ship to selection into a separate class with sharing.
*/     
     
     public  static List<Account> getSTAccounts(string stParentId){
                string stID = stparentId;
                List<Account> STaccountList = new List<Account>();
                //This  query returns all site accounts in the hierarchy of the opp account where Ship To = True
                for(Account a : [Select id, Site_Number__c, Name, BillingStreet, BillingState, BillingCity From Account where 
                              parentid =: stParentId and Active_Ship_To__c = true Order by BillingCity, BillingStreet]){
                              STaccountList.add(a); 
                              }                                                      

        return STaccountList; 
     } 
}

 

So, back to the  main controller, I re-wrote the method like this:

 

    public List<aAccount> getSTAccounts(){

        if (STaccountList == null){
        string stParentID = ApexPages.currentPage().getparameters().get('parentid');
        List<Account> shipTos = new List<Account>();
        shipTos = multiShipToUtility.getSTAccounts(stParentID);
        for (Account a: shipTos){
        	STaccountList.add(new aAccount(a));
        }

       
        return STaccountList;    
        }

 

 

This won't compile with the message Non-void method might not return a value or might have statement after a return statement".

I researched this error a bit, and then added a basic else clause to the if-block above to return an empty list.  This compiles, but then blows up when I run the page:  "Attempt to de-reference a null object"

 

I also tried removing the static keyword from the method, but that doesn't compile eiter. 

 

So I'm totally stuck now.  Can anyone offer any suggestions? 

 

 

 

 

 

I am issuing a query in Apex code (in a controller) to lookup some contacts. I am doing a limit 500 on the query, but there are about 10 million contacts in the system. When doing it through SoqlXplorer it is fast. However, when issuing the query in Apex, it takes a long time, sometimes causing the code to time out. Is there a way to speed up queries? I know it has to go through a lot of records to come up with the 500 records (in my LIMIT 500 ) but this is ridiculous. 

 

Any thoughts?

 

Thanks,

Dan

  • September 07, 2010
  • Like
  • 0

Does anyone know the limits of API SOQL calls? I have an aggregate query that, when run inside a VF controller, gives out a Too many query rows (16,125) error. However, the same query ran from SOQLXplorer returns no error and shows me the data.

Hi,

 

I have an object with a lookup to both contact and account.

 

Is it possible to have the account lookup populated automatically when you add a contact by using the account they are assigned to?

 

If so can this be done my a trigger or another method.

 

Thanks


Ross

Hi Guys,

 

I think I am pretty close here.

 

The GET HTTP should send out a custom built URL from two fields on a custom object (not all together different from a Case style page). The return information is XML and I am trying to pull down a specific field and insert that back onto into the custom record.

 

Any ideas where I am going wrong. I am certainly struggling with the update part of the APEX code. 

 

Any thoughts would be helpful;

 

 

trigger LatLong on Incident__c (before insert, before update) {
    
    public void parseResponseDom(String url){
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        // url that returns the XML in the response body  
    
        req.setEndpoint('http://www.uk-postcodes.com/latlng/{!latitude__c},{!longitude__c}.xml');
        req.setMethod('GET');
        HttpResponse res = h.send(req);
        Dom.Document doc = res.getBodyDocument();
        
        //Retrieve the root element for this document.  
    
        Dom.XMLNode result = doc.getRootElement();
        
        String postcode = result.getChildElement('postcode', null).getText();
        // print out specific elements  
        
        System.debug('postcode: ' + postcode);
        for(Dom.XMLNode child : result.getChildElements()) {
        System.debug(child.getText());
        }
        
        Incident__c I = [select Council_Name_Text__c from Incident__c 
             where Council_Name_Text__c = null limit 1];
             
        I.Council_Name_Text__c = postcode;
       
        update I;
        
  
        }
    }

Hi there,

 

I'm experiencing a strange problem. In a Visualforce Page there is a large number of custom buttons. They were implemented as <apex:commandLink> and work well in Firefox, Safari, Opera, Internet Explorer 7.

But the same button doesn't work in IE 8! I tried the Developertools from the extras menu in IE 8 and opened the page in IE 7 mode, everything works as expected.

I also tried to change the <apex:commandLink> in a <apex:commandButton>, but there is no reaction.

The action invoked is just similar to any other working Button (a simple pageReference which sets a field value).


Is there any known problem or a workaround to fix this problem?

 

Any suggestions welcome ;-)

 

Best regards,

Tobias Forstmeier