• J&A-Dev
  • NEWBIE
  • 125 Points
  • Member since 2008

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 35
    Replies

 

How do I create a string and run this simple soql query that populates it. 

 

 

Example 

String uRoleName = [Select u.Name From UserRole u Where u.id = : UserInfo.getUserRoleId() Limit 1]; 

 

Above doesnt work because it wants an SObject but UserRole is not an accessible sObject and I dont want an instance of it anyways I just want the one field returned into a string. 

Hi friends -

 

Newbie question.. help please? any of you have the following situation?

 

When user clicks on the custom link on the home page, depending on the count value the user should be redirected to either page ABC1 or ABC2.

 

I mean if the count value=0 redirect the page to ABC1 other wise redirect to ABC2

 

I am trying to achieve this using custom comtroller.

 

public class MyController

{

List<CustomObject__c > co;

public List<CustomObject__c > getPageName()

{

 co=[Select values from CustomObject__c];

Integer count=co.size();

 

//Please help how to proceed with this part..

if(count ==0)

{

redirect to page ABC1;

}

else

{

redirect to page ABC2;

}

}

}

Hi all,

 

I'm reading page 206 on the Apex reference doc and it states that one Apex transaction can make 10 callouts to an HTTP request. If I need to make more than 10 callouts, what are all my options other than using the @future notation? I'm calling a geocoding webservice, and the app will be making closer to 200 callouts/day.

 

Any suggestions will be appreciated.

 

Thanks in advance.

Hi,

 

I wrote a batch Apex job that updates contact records (200 records/batch) by doing a lookup to another table. For the most part, all looks good until a DML Exception occurs. When this happens, none of the records on that batch get updated as expected. My question is: what's the best way to handle this? Can I have a try and catch statement and when the DML Exception is caught, reprocesses all the records within that batch minus the record/records that caused the DML Exception?

 

Any pointers will be appreciated.

 

Thanks in advance.

Hi,

 

I'm aware of we can set the "contentType" attribute on the apex:page tag to export the current contents of the page to excel. But what if I have a button on the page that will change the content of the page? Is there a way to build an export from a button click?

 

Thanks in advance.

Hi,

 

I have 2 Batch Apex classes that update contact records. Now, I'm trying to write the test method for both, and it seems that when I attempt to simulate the batch job for either job, the other batch job runs as well and I get a runtime error. If I comment out one of the jobs, then other job runs fine and I get 100% coverage (on that particular batch apex job).

 

Is there anything in particular that I need to do to be able to test multiple Apex jobs?

 

Thanks in advance.

Hi,

 

I'm working on a project that would require updates to contact records from emails. Let me describe our scenario: our eCommerce group would send out a number of emails to each contact about all our products and each contact would have the ability to "opt out" from getting emails from any particular product. Each product will be mapped to a field within the contact record, so I'm exploring all my options. The one feature that I noticed might work is Apex Email (have each contact reply to an Apex Email inbox and process each request), but I'd like to know if there are other options.

 

Any help/advice on this would be appreciated.

 

Thanks.

I'm aware of the governor's limitation that states that we can only process 100 records per element in the trigger. So if the trigger has , let's say, 4 records, then the max number of DML rows that can be processed is 400. In my case, I'm trying to update child records (contacts) when there is a change on a single parent record (account). The challenge is that we have a good number of accounts that have way over 100 contacts. So how should I approach this?

 

I've seen a few posts suggesting the usage of @future, but I'm not quite sure how to put it together. I wrote an s-control that will do this, but I'd like to start moving it so that it runs server side. Any ideas or suggestions will be greatly appreciated.

Message Edited by J&A-Dev on 09-10-2009 01:50 PM
  • September 10, 2009
  • Like
  • 0

Hi all,

 

I wrote an s-control that makes a GET call to an external server, gets the response back, parses it and it stores parts of the response into the DB. Once I parse the response from the server, I populate a custom field with the parsed response. Currently, I do this by passing the field value via query string but the field must be present on the layout for this to work. Is there a way to hide the field from the layout and still be able to pass the field value via query string client-side?

 

Thanks in advance.

  • September 08, 2009
  • Like
  • 0

Hi all,

 

I'm looking to see what is the best way to structure my data for later manipulation using triggers and classes. The trigger will fire after inserts and update updates. Here's what I'm trying to achieve:

- store a list of contact records with their new values (by calling Trigger.newMap)

- store a list of contact records with their old values (by calling Trigger.oldMap)

- compare the old and new values of certain fields and apply whatever logic I need to.

 

What's the best way to store these values in a trigger and pass them to a class? A constructor class, maps? What I'm looking to do is to be able to provide both the new and old values of a particular record by providing an Id.

 

Thanks in advance.

 

 

Hi all,

 

I'm working with the remoteFunction() to make a GET call to an external webservice. The service returns an XML back and I was wondering if the Ajax toolkit contains any functions to parse the XML response. This is how I'm making the GET call:

 

 

sforce.connection.remoteFunction({
url : "my_http_request_link_w_querystring",
requestHeaders: {
"Content-Type": "text/xml",
"SOAPAction":},
mimeType: "text/xml",
method: "GET",
onSuccess : function(response) {
alert(response);
},
onFailure : function(response) {
alert("Problem with REST call w/ response = " +
response);
}

);

 

 Thanks in advance.

 

 

Message Edited by J&A-Dev on 07-29-2009 07:30 AM

Hi all,

 

I have to implement a batch process and I was thinking about building the application on the Force.com platform. I'd like to hear what your suggestions are, as I'm not sure if this is something I can do using Apex classes and triggers.

 

The goal is to provide sales summary data at the Account (object) level. The sales data is stored under contact records. Here's an example to help illustrate what I'm trying to achieve:

- Account "A" has 4 contacts with sales figures. The aggregated sales data (from all contacts belonging to Account A) will be written at the Account level.

-Ideally, this sales data present at the Account object should update when: a) the sales figure on any of its contact records change, or b) A new contat record is associated with Account A and has a sales figure > 0.

 

I wanted to build a trigger on the Contact object that will fire after inserts and after updates when the criteria is met. This should work for most users when creating/updating single records, but we also have a nightly job that updates the sales figures on a large number of contact records. This number varies from 500 to over 30K contact records. What would you suggest that I do? I know that Apex allows to retrieve up to 10K records from a single SOQL query.

 

Thanks in advance.

Hi,

I'm using the describeSObject call to retrieve the field names of an object (contact in this case). Once I get the field names, is there a way to dynamically retrieve their values from merge fields? I'm trying to avoid hardcoding the merge fields essentially. Here's what I do:

- Make describeSObject call to retrieve all field values that I'm looking for and store them in a data structure. Let's say I store the field names in an array called fieldNames.

- Merge fields are retrieved by using this syntax: "{!Contact.Phone}". Instead of hardcoding the field name, is there a way to retrieve the value by passing the field name stored in fieldNames?

 

Or if there is another way to achieve what I'm after, I'd like to hear suggestions.

 

Thanks in advance. 

Hello,

 

I'm in the process of building an application that will make an HTTP request to an external server. Once the response is received by my application, it'll parse it and according to the results, it should open up a new contact record page with some info pre-populated (this info will come within the response of the HTTP request). What would be the best way to design this app? If I where to use Apex to make the external call, am I limited to 10 callouts?

 

Thanks in advance. 

Hi all,

 

Is it possible to add an outputLink as a column within a table? If so, how can this be achieved?

Thanks in advance.

I created a custom component with the following 2 attributes:

 

<apex:component > <apex:attribute name="zoneSales" description="Zone Sales." type="String" required="true"/> <apex:attribute name="zoneLabel" description="Zone Label." type="String" required="true"/> <apex:pageBlockSection id="PB_JNLD_Zone1P" title="{!zoneLabel}" collapsible="false"> <apex:pageBlockTable value="{!zoneSales}" var="zcm"> <apex:column value="{!zoneSales}" headerValue="Total-JNLD"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:component>

 

In my controller, I created an inner class that will contain the 2 attributes:

 

String[] myZoneNumber = new String[]{'Zone 1', 'Zone 2', 'Zone 3', 'Zone 4', 'Zone 5', 'Zone 6', 'Zone 7', 'Zone 8'}; String[] myZoneTotal = new String[]{'$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8'}; public MyZoneObject getInitMyZoneObject() { MyZoneObject mzo = new MyZoneObject(myZoneNumber, myZoneTotal); return mzo; } public class MyZoneObject { public String[] myZoneNumber {get;set;} public String[] myZoneTotal {get;set;} public MyZoneObject(String[] zoneNumber, String[] zoneTotal) { this.myZoneNumber = zoneNumber; this.myZoneTotal = zoneTotal; } }

 

 And finally, here's how I call my component from the VF page:

 

<apex:repeat value="{!InitMyZoneObject}" var="myZoneObj"> <c:ZoneComponent zoneLabel="{!myZoneObj.myZoneNumber}" zoneSales="{!myZoneObj.myZoneTotal}"/> </apex:repeat>

 

What I expecting to happen is for the pageBlockSection to repeat 8 times, which is array size for either attribute. Instead, I'm getting a single pageBlockSection displaying the entire array for both attributes. What I'm not entirely sure is the way I created the inner class "MyZoneObject".

 

Thanks in advance.


 

 

 

 

Hi,

 

I need to be able to query around 50,000 records and I'd like to know if this is possible using pure Apex/VisualForce. I'm reading the Visualforce documentation and it looks like there is a 10,000 rows limitation on VisualForce if used within a For loop. What would you recommend I do?

 

This is what I'm trying to do:

- query all rows within custom object (around 50k).

- return the sum of a sales field from the above rows.

 

I've tried writing separate functions that will each return a sub-set of the 50k rows, but as soon as the total number of rows from all queries goes over 10k, I'm hitting the governor's limit. If what I'm trying to achieve is possible using only Apex and VisualForce, I'd love to hear suggestions.

 

Thanks in advance.

I have an inputText that is used to get a 4 digit string from the user. This string is then passed to a SOQL query as a filter. For some reason, when the 4 digit string is found in our database, the page is refreshed properly and the necessary values are displayed on the page. The problem is when the string is not found in the database and it's throwing this error:

 

System.NullPointerException: Attempt to de-reference a null object

 Here's the relevant section of my code:

 

<apex:page controller="ZipCMQuery" id="currPageId">
<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="IXI_DT" id="IXITabPanel"
tabClass="activeTab" inactiveTabClass="inactiveTab">
<apex:tab label="Data Table" name="IXI_DT" id="IXI_DT">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Select territory" collapsible="false">
<apex:facet name="header">Cost Center:</apex:facet>
<apex:inputText id="costCenter" title="Cost Center" value="{!myCostCenter}" maxLength="4" required="true" size="4"/><br/>
<apex:commandButton value="Search" action="{!test}" rerender="PB_JNLD_Zone" status="status7"/>
</apex:pageBlockSection>
<apex:outputPanel id="out7">
<apex:actionstatus id="status7" startText="searching..."/>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>

<apex:pageBlock id="PB_JNLD_Zone" title="">
<apex:pageBlockSection id="PB_JNLD_Zone" title="JNLD Sales (Zone)">
<apex:outputText value="{!TotalSalesJNLDStr}"/><br/>
<apex:outputText value="{!SalesJNLDCurrCCStr}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:tab>
</apex:tabPanel>
</apex:page>

 

public class ZipCMQuery { private Decimal totalSalesJNLD = 0.00; private Decimal totalSalesIXI = 0.00; private Decimal salesJNLDCurrCC = 0.00; private Decimal salesIXICurrCC = 0.00; private Decimal salesJNLDCurrZS = 0.00; private Decimal salesIXICurrZS = 0.00; String myCostCenter; public String getMyCostCenter() { return myCostCenter; } public void setMyCostCenter(String s) { myCostCenter = s; } public PageReference test() { salesJNLDCurrCC = 0.00; salesIXICurrCC = 0.00; salesJNLDCurrZS = 0.00; salesIXICurrZS = 0.00; totalSalesJNLD = 0.00; totalSalesIXI = 0.00; String thisCC = getMyCostCenter(); System.debug('Value of cost center = ' + thisCC); for (Zip_Code_Metrics__c myZCM : [SELECT Cost_Center_R__c, Zip_Code__c, Primary_Mailing_City_Name__c, JNLD_R_Zone__c, JNLD_R_Sub_Zone__c, State__c, JNLD_R_Sales__c, IXI_Sales_for_JNLD_R__c From Zip_Code_Metrics__c WHERE JNLD_R_Zone__c = '1']) { if (thisCC.equals(myZCM.Cost_Center_R__c)) { salesJNLDCurrCC = salesJNLDCurrCC + myZCM.JNLD_R_Sales__c; System.debug('Value of salesJNLDCurrCC = ' + salesJNLDCurrCC); salesIXICurrCC = salesIXICurrCC + myZCM.IXI_Sales_for_JNLD_R__c; System.debug('Value of salesIXICurrCC = ' + salesIXICurrCC); } if ((myZCM.JNLD_R_Sales__c != null) && (myZCM.JNLD_R_Sales__c > 0.00) && (myZCM.JNLD_R_Sub_Zone__c.equals('B'))) { salesJNLDCurrZS = salesJNLDCurrZS + myZCM.JNLD_R_Sales__c; System.debug('Value of salesJNLDCurrZS = ' + salesJNLDCurrZS); } if ((myZCM.IXI_Sales_for_JNLD_R__c != null) && (myZCM.IXI_Sales_for_JNLD_R__c > 0.00) && (myZCM.JNLD_R_Sub_Zone__c.equals('B'))) { salesIXICurrZS = salesIXICurrZS + myZCM.IXI_Sales_for_JNLD_R__c; System.debug('Value of salesIXICurrZS = ' + salesIXICurrZS); } if ((myZCM.JNLD_R_Sales__c != null) && (myZCM.JNLD_R_Sales__c > 0.00)) totalSalesJNLD = totalSalesJNLD + myZCM.JNLD_R_Sales__c; System.debug('Value of totalSalesJNLD = ' + totalSalesJNLD); if ((myZCM.IXI_Sales_for_JNLD_R__c != null) && (myZCM.IXI_Sales_for_JNLD_R__c > 0.00)) totalSalesIXI = totalSalesIXI + myZCM.IXI_Sales_for_JNLD_R__c; System.debug('Value of salesJNLDCurrZS = ' + totalSalesIXI); } return null; } public Decimal getTotalSalesJNLDStr() { return totalSalesJNLD.setScale(2); } public Decimal getSalesJNLDCurrCCStr() { return salesJNLDCurrCC.setScale(2); } }

 

 

 When I add a debug statement, it seems that the PageReference function is not returned when the user input isn't found in our instance.

 

Thanks in advance.

 

 

 

Hi,

 

Is it possible to pass the user selected picklist value from an inputField to a controller? If so, can someone either post a snippet or pseudo code of how this would be achieved?

 

Thanks in advance.

Hi all,
I was testing the InboundEmail functionality using Apex code and came across an issue. I'm using the sample code that came with the Spring '08 release as the squeleton to auto-generate a task when an email is received. This is how I've structured my code:
- The email.fromAddress will be used to query the Contact table and set the WhoId field of the task.
- Instead of assigning the task to whoever sent the email, I want to be able to control this by allowing the person that's sending the email to assigned a user to the task. So, what I do is within the body of the email, have a special character '#' right before the person's email address (which will become the Task's OwnerId). Then I split the email.plainTextBody when an '#' is found. For some reason, when I send an email, the task isn't created. If I hardcode the email address within the SOQL query, then the code works fine. Here's my code:
 
Code:
global class TaskFromEmail implements Messaging.InboundEmailHandler
{
 global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,
                 Messaging.InboundEnvelope env) 
 {
  Messaging.InboundEmailResult emailResult = new Messaging.InboundEmailResult();
  String myPlainText = '';
  myPlainText = email.plainTextBody;
  Task[] newTask = new Task[0];
  String[] userEmailAddress = new String[2];
  User myUser = null;
  
  if (myPlainText.contains('#')) 
  {
   userEmailAddress = myPlainText.split('#', 2);
   System.debug('##### ' + userEmailAddress[1] + ' #####');
  } 
  
  
  try
  {
   Contact myContact = [SELECT Id, Name, Email
      FROM Contact
      WHERE Email = :email.fromAddress
      LIMIT 1];      
   myUser = [SELECT Id, Email
       FROM User
       WHERE Email = :userEmailAddress[1]
       //WHERE Email = :email.subject
       LIMIT 1];        
              
   newTask.add(new Task(Description = userEmailAddress[0],
              Priority = 'Normal',
        Status = 'Inbound Email',
        Subject = email.subject,
        OwnerId = myUser.Id,
        ActivityDate = System.today()+1,
        WhoId = myContact.Id));
   insert newTask;
   System.debug('New Task Object: ' + newTask);
  }
  catch (QueryException e)
  {
   System.debug('Contact Query issue: ' + e);
  }        
  emailResult.success = true;
  return emailResult;
 }
 

 static testMethod void testTasks()
 {
     Messaging.InboundEmail email = new Messaging.InboundEmail();
     Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

  // Create the plainTextBody and fromAddres for the test
  email.plainTextBody = 'Here is my plainText body of the email #myEmailAddress@someDomain.com';
  email.fromAddress ='myEmailAddress@someDomain.com';

  TaskFromEmail taskObj = new TaskFromEmail();
  taskObj.handleInboundEmail(email, env);
 } 
                
}

 
Does anyone have an idea? From what I've seen, is the issue that I'm passing a variable (userEmailAddress[1]) into an SOQL query string?

Hi all,

 

I'm reading page 206 on the Apex reference doc and it states that one Apex transaction can make 10 callouts to an HTTP request. If I need to make more than 10 callouts, what are all my options other than using the @future notation? I'm calling a geocoding webservice, and the app will be making closer to 200 callouts/day.

 

Any suggestions will be appreciated.

 

Thanks in advance.

Hi,

 

I wrote a batch Apex job that updates contact records (200 records/batch) by doing a lookup to another table. For the most part, all looks good until a DML Exception occurs. When this happens, none of the records on that batch get updated as expected. My question is: what's the best way to handle this? Can I have a try and catch statement and when the DML Exception is caught, reprocesses all the records within that batch minus the record/records that caused the DML Exception?

 

Any pointers will be appreciated.

 

Thanks in advance.

Hi,

 

I have 2 Batch Apex classes that update contact records. Now, I'm trying to write the test method for both, and it seems that when I attempt to simulate the batch job for either job, the other batch job runs as well and I get a runtime error. If I comment out one of the jobs, then other job runs fine and I get 100% coverage (on that particular batch apex job).

 

Is there anything in particular that I need to do to be able to test multiple Apex jobs?

 

Thanks in advance.

Hi,

 

I have one SOQL which will retrieve nearly 50k records. Can anyone please tell me how to handle this scenario.

As SOQL is able to retrieve at most 10,000 records, somehow I need to pass the start index to SOQL to retrieve set of next 10,000 recs..etc.

 

Is it possible at all? How will Batch apex help in this?

 

Thanks ain advance,

Suvra

  • December 08, 2009
  • Like
  • 0

Hey

Periodically when running my batch process from a VisualForce page I get a "Read Timed Out" error.

 

I am not calling out to any external systems in my batch.

 

I have gotten this message from code that worked both before and after the problem batch, with no changes to the code in between.

 

Any explanation for this would be highly appreciated!

 

Thanks

Dave

  • November 10, 2009
  • Like
  • 0

Hi all,

 

I wrote an s-control that makes a GET call to an external server, gets the response back, parses it and it stores parts of the response into the DB. Once I parse the response from the server, I populate a custom field with the parsed response. Currently, I do this by passing the field value via query string but the field must be present on the layout for this to work. Is there a way to hide the field from the layout and still be able to pass the field value via query string client-side?

 

Thanks in advance.

  • September 08, 2009
  • Like
  • 0

 

How do I create a string and run this simple soql query that populates it. 

 

 

Example 

String uRoleName = [Select u.Name From UserRole u Where u.id = : UserInfo.getUserRoleId() Limit 1]; 

 

Above doesnt work because it wants an SObject but UserRole is not an accessible sObject and I dont want an instance of it anyways I just want the one field returned into a string. 

Hi all,

 

I'm working with the remoteFunction() to make a GET call to an external webservice. The service returns an XML back and I was wondering if the Ajax toolkit contains any functions to parse the XML response. This is how I'm making the GET call:

 

 

sforce.connection.remoteFunction({
url : "my_http_request_link_w_querystring",
requestHeaders: {
"Content-Type": "text/xml",
"SOAPAction":},
mimeType: "text/xml",
method: "GET",
onSuccess : function(response) {
alert(response);
},
onFailure : function(response) {
alert("Problem with REST call w/ response = " +
response);
}

);

 

 Thanks in advance.

 

 

Message Edited by J&A-Dev on 07-29-2009 07:30 AM
Hi,

Using SOQL query in Trigger i am able to query 1000 records at a time. Since list is having the capacity of 100 records updation at a time, we are updating 1000 records using 10 different list (Dividing 100 records per list). At the time of updating it is accumulating the each list updates and giving error like 'Too Many DML Rows : 200 '. Why it is accumulating the all updates even after dividing into 10 different lists.
How to rectify this is error. Please do the needful ASAP.

Hi all,

 

I have to implement a batch process and I was thinking about building the application on the Force.com platform. I'd like to hear what your suggestions are, as I'm not sure if this is something I can do using Apex classes and triggers.

 

The goal is to provide sales summary data at the Account (object) level. The sales data is stored under contact records. Here's an example to help illustrate what I'm trying to achieve:

- Account "A" has 4 contacts with sales figures. The aggregated sales data (from all contacts belonging to Account A) will be written at the Account level.

-Ideally, this sales data present at the Account object should update when: a) the sales figure on any of its contact records change, or b) A new contat record is associated with Account A and has a sales figure > 0.

 

I wanted to build a trigger on the Contact object that will fire after inserts and after updates when the criteria is met. This should work for most users when creating/updating single records, but we also have a nightly job that updates the sales figures on a large number of contact records. This number varies from 500 to over 30K contact records. What would you suggest that I do? I know that Apex allows to retrieve up to 10K records from a single SOQL query.

 

Thanks in advance.

Hi,

I'm using the describeSObject call to retrieve the field names of an object (contact in this case). Once I get the field names, is there a way to dynamically retrieve their values from merge fields? I'm trying to avoid hardcoding the merge fields essentially. Here's what I do:

- Make describeSObject call to retrieve all field values that I'm looking for and store them in a data structure. Let's say I store the field names in an array called fieldNames.

- Merge fields are retrieved by using this syntax: "{!Contact.Phone}". Instead of hardcoding the field name, is there a way to retrieve the value by passing the field name stored in fieldNames?

 

Or if there is another way to achieve what I'm after, I'd like to hear suggestions.

 

Thanks in advance. 

Hi,

 

I am trying to set the RecordType in a before insert trigger for web to case input. The trigger code is:      

trigger CaseSetupTrigger on Case (before insert){
for (Case c: Trigger.new) {
c.RecordType = [select Id from RecordType where Name = 'Canada' and SobjectType = 'Case'];
}
}

I know the code above works as I can see the correct RecordTypeID in the debug log for some workflow rules that use the RecordType. The problem is that when the case is finally saved the RecordType has been overwritten with the default RecordType for unassigned cases. There are no workflow rules that set the RecordType. The workflow rules also use $RecordType.Name which is the name of the default recordType and not Canada as would be expected.

 

I have tried changing the case setting for "Choose the desired behavior to use when applying assignment rules to manually created records:" to "Keep existing Record Type" but this has no effect. 

 

I'm guessing that this has something to do with the order that triggers web to case and workflow rules fire but I can't seem to pin it down.

 

Any suggestions on how to get the record type set in a before insert trigger to actually stick for a web to case and not get changed?

 

Thanks

 

Hi all,

 

Is it possible to add an outputLink as a column within a table? If so, how can this be achieved?

Thanks in advance.