• HL-Dev
  • NEWBIE
  • 50 Points
  • Member since 2008

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 23
    Replies
I have a custom Invoice object which gets a related Case created if the invoice goes overdue.  That works fine.  Now, we want to stop the invoice from being edited by anyone except users from a particular profile, once the invoice has a related Case.  If I use the standard button override, I end up with a recursive loop because I'm trying to use the standard edit functionality (when they are allowed to edit), so it keeps calling my scontrol.  Current (bad) code is as follows:
Code:
function EditInvoice() {
  var IsCase ="{!m62_Invoice__c.Case_Number__c}";
  var TopDog = false;
  var _profile = "{!$Profile.Name}";
  if  ((_profile == "Financial Controller") || (_profile == "System Administrator")){
    TopDog = true;
  }
alert("Profile is " + _profile + " topdog is " + TopDog);
  
  var retURL= escape("/{!m62_Invoice__c.Id}");
  if ((IsCase == "") || TopDog) {  // No Case been created OR profile is that of financial controller or Sysadmin
    parent.location.href = retURL+"/e";   
  } else {
    alert ("You cannot edit the invoice once a Case has been added");
    parent.location.href = retURL;
  }
}

Using retURL + "/e" simply causes the function to be called again and again forever if the conditions are met, so it is obviously not the way to do it.

Basically I want to avoid rewriting all the edit functionality but stop certain users from editing the record under certain conditions (i.e. once a case has been created and if the user is not from a named profile).

Does anyone have any ideas to help me here?

Thanks,
Erica

  • January 23, 2008
  • Like
  • 0

I'm working on an Apex trigger and class that will geocode addresses on the contact object once a new contact record is created with an address (After Insert) and after a contact record's address has changed (After Update). I'm making and HTTP request to google to geocode the coordinates as in:

- send an address to Google

- if I get a response back from Google, check the status

- if successful, then parse through the response and extract the coordinates and write them to the contact record, so they can later be referenced by my Google Maps application.

 

Here's my problem: originally, I wrote the trigger and class so that it only sends one address per trigger execution. This code works as expected. Then I modified my code to send addresses in batches and now I'm getting the following error message:

 

System.AsyncException: Future method cannot be called from a future method: my method name goes here()

 

 

Here's what my code does:

Trigger

- when a new contact record with an address or when a existing contact record's address is updated, then add its id to an array

- call the apex class to geocode by passing this mentioned array of contact ids

 

Class

- for each contact that was passed by the trigger, query the address and pass it to Google for geocoding

- read the response back from Google and if it was successful, then parse through the response, extract the coordinates and write to the contact record (update call)

 

Why would I get the following error message? Are bulk triggers not allow when using the @future annotation or is there something wrong with my logic?

 

Thanks in advance.

 

 

  • January 23, 2009
  • Like
  • 0
Hi all,
 
I've been playing around with Flex on Sandbox and wanted to play a presentation (in .flv format) on the page. Is it possible to store a multimedia file and to reference it in Salesforce? I know how to store and reference images, but I didn't find anything regarding multimedia files.
 
Thanks in advance.
  • October 13, 2008
  • Like
  • 0
Hi,
 
I'm trying to think of an efficient way to pull the value of a custom field (Cost_Center__c) within the User table. Here's my situation: I'm given a set of Event records and using their OwnerId's, I'm trying to think what'd be an optimal way to pull the user's cost center. My requirement is that I read the currently logged in user's cost center, and given the set of event records, only pull the events with users (the user which the event is assigned to) that have a matching cost center.
 
I know I could get all the OwnerId's from the Event records and use them to query the user table to find the matching pair, but then I'd be making one API call/comparison, which isn't optimal at all. Also, I could probably add a new field on the Event record that calls an Apex Trigger (after insert) that would check the event's OwnerId, lookup the user table and write the cost center over to this new field.
 
Is there something else I could do to achieve my goal?
 
Thanks in advance.


Message Edited by HL-Dev on 09-11-2008 09:21 AM
  • September 11, 2008
  • Like
  • 0
I have a parent to child relationship query question. Here's a snippet of my code:
 
Code:
var queryString = "SELECT FirstName, LastName, " +
          "(SELECT Subject, Id FROM Events WHERE Subject = 'x') " +   
          "FROM Contact " +
          "WHERE Organization__c = '{!Contact.Organization__c}' " +
          "AND ZoneR__c = 'x' " + 
          "AND Sub_ZoneR__c = 'x' " +
          "AND Primary_Cost_Center__c = 'xxxx' " +
          "AND ((Production__c = 'A') OR (Id = '{!Contact.Id}') OR " +
          "(Production__c = 'B') OR (Production__c = 'C') OR " +
          "(Production__c = 'C')) " +
          "LIMIT 100";
var queryResult = sforce.connection.query(queryString);
results = queryResult.getArray ("records");
 
I'm trying to gather events information from a list of contacts. In my query, I'm trying to get a list of contacts that match a certain criteria and for each contact, I get the events' id and subject if they have any. Question is: how can I store the results that I get back from the parent-child relationship into a variable? In my example, if I wanted to get the contact's first name from the query result, I could assign a variable to results.FirstName. But I'm not sure how to accomplish the same for the results I get from the Parent to Child relationship (the events' info that I get back).
 
Thanks in advance.
 


Message Edited by HL-Dev on 06-13-2008 01:27 PM
I've implemented a simple Google Map application that plots the top producers of a territory. Currently, the map is associated at the contact record level and it's set up as an S-Control that's attached to a custom button on the contact detail page.
 
I've started geocoding the contacts' addresses using the Google Map GClientGeoCoder class, which makes a call to the Google servers (I send the address to it and it returns the coordinates back). This process is very inefficient and overhead heavy, especially with multiple addresses. Plus, there's really no need to geocode an address if it has been previously, unless the address on the contact record has changed.
 
For anyone that has worked on integrating SF with GoogleMaps before: what's the best way to get the coordinates from an address? I've seen a previous thread that seems to store the coordinates into custom fields, but I cannot find the source code to understand how the storage-goecoding is done.
 
Any insights will be appreciated, thanks!
  • April 30, 2008
  • Like
  • 0
Hi all,
I've searched for other threads with similar issues, but I couldn't find one with an exact answer. I wrote some Apex code that attempts to update a field within a User record. When I tested my class, just by looking at my debug statements, it seems that the field is getting updated. However, when the trigger is actually fired, I'm getting the following exception:
 
System.DmlException: Update failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, You cannot update a customizable setup entity, except when running tests

So it seems on this particular table, the field can only be updated on a test class but not on my actual trigger.
I read the Apex Doc, and there's a section that mentions that not all SObjects can be updated using Apex but it doesn't specify which SObjects can or cannot be updated.
If anyone can confirm this, I'd appreciate it.
Thanks in advance. 
 

 
 
  • February 28, 2008
  • Like
  • 0
Hi everyone,
I'm fairly new at developing on this platform and have a few pre-deployment questions. I've written a trigger that executes after a certain event happens. Also, I wrote a testMethod for the previous trigger, and the test log shows no issues so far. Now, I've done all this on sandbox.
- When I'm ready to push this into production, would I first create a new project by synching the production box's metadata? Because sandbox's metadata isn't the same as production's.
- What happens if after the trigger is deployed on production, I decide to modify/remove it? Is it possible to remove a previous trigger by using the Force.com toolkit for Eclipse? Or is it only possible via the Ant tool?
Thanks in advance.
  • January 25, 2008
  • Like
  • 0

I'm working on an Apex trigger and class that will geocode addresses on the contact object once a new contact record is created with an address (After Insert) and after a contact record's address has changed (After Update). I'm making and HTTP request to google to geocode the coordinates as in:

- send an address to Google

- if I get a response back from Google, check the status

- if successful, then parse through the response and extract the coordinates and write them to the contact record, so they can later be referenced by my Google Maps application.

 

Here's my problem: originally, I wrote the trigger and class so that it only sends one address per trigger execution. This code works as expected. Then I modified my code to send addresses in batches and now I'm getting the following error message:

 

System.AsyncException: Future method cannot be called from a future method: my method name goes here()

 

 

Here's what my code does:

Trigger

- when a new contact record with an address or when a existing contact record's address is updated, then add its id to an array

- call the apex class to geocode by passing this mentioned array of contact ids

 

Class

- for each contact that was passed by the trigger, query the address and pass it to Google for geocoding

- read the response back from Google and if it was successful, then parse through the response, extract the coordinates and write to the contact record (update call)

 

Why would I get the following error message? Are bulk triggers not allow when using the @future annotation or is there something wrong with my logic?

 

Thanks in advance.

 

 

  • January 23, 2009
  • Like
  • 0
Hi all,
 
I've been playing around with Flex on Sandbox and wanted to play a presentation (in .flv format) on the page. Is it possible to store a multimedia file and to reference it in Salesforce? I know how to store and reference images, but I didn't find anything regarding multimedia files.
 
Thanks in advance.
  • October 13, 2008
  • Like
  • 0
Trying to override the "New System" button (on a custom object called Location) I get an error: Invalid Data
with this Custom S-Control:
 
<html>
<head>
<script src="/soap/ajax/8.0/connection.js"></script>
<script>
function pInit() {
 var url = parent.location.href; //URL accessing sControl
 url += "&CF00N80000002ZueH= {!Location__c.Account__c}";
 url += "&nooverride=1"; //
 parent.location.href = url; //pass full URL to page (refresh)
}
</script>
</head>
<body onload="pInit()">
</body>
</html>
 
 
when I change:
 url += "&CF00N80000002ZueH= {!Location__c.Account__c}";
into:
 url += "&CF00N80000002ZueH= Jansen";
it works.
 
Can anyone tell me what might be wrong?
 
Peter
Hey all,
 
Here's my problem :
 
In my Custom Object Customer__c, I would like to populate my Record Name with 2 others fields. This works fine with a Trigger, but only with updates. When I try to create a new record, it tells me that the Record Name is a required fields. I guess that validation rules come before trigger actions.
 
Does anyone can explain me how to make it ?
 
Thx a lot,
 
Regards.
 
 
 
 
 
 
  • September 18, 2008
  • Like
  • 0
First time creating a Apex Class  and the Trigger and I'm getting a error message:

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

I have 100% coverage for the Apex Class but can't find any information on getting Apex Trigger Coverage.

Any help is appreciated

Class:

public class ContractUpdate {

public static void AddeCon(Contract [] UpdateContract) {
    List<Account> accountsToUpdate = new List<Account>();
    for(Contract c: UpdateContract)
   
{
    if ((c.Stage__c=='Completed') && (c.RecordTypeId == '0123000000002Hr') && (c.Status == 'Active')){
   Account acc = new Account(Id=c.AccountId,eCon_Completed__c=TRUE);
   accountsToUpdate.add(acc);
  }
 else { Account acc = new Account(Id=c.AccountId,eCon_Completed__c=FALSE);
     accountsToUpdate.add(acc);
 }
 }
 update accountsToUpdate;
}


    public static testMethod void test_AddeCon(){
   

      Account test1 = new Account(Name = 'one', eCon_Completed__c=FALSE);   
      Account test2 = new Account(Name = 'two',eCon_Completed__c=TRUE);
      Account test3 = new Account(Name = 'three',eCon_Completed__c=FALSE);
      Account test4 = new Account(Name = 'four',eCon_Completed__c=TRUE);
      Account[] accts = new Account[] { test1, test2, test3, test4 };
          
       insert accts;
     
      Contract TestCon1 = new Contract (AccountId = test1.Id, Stage__c = 'Completed',Status = 'Active',RecordTypeId = '0123000000002Hr');
      Contract TestCon2 = new Contract (AccountId = test2.Id, Stage__c = 'Install on Hold', Status = 'Active');
      Contract TestCon3 = new Contract (AccountId = test3.Id, Stage__c = 'Completed', Status = 'Cancelled', RecordTypeId = '0123000000002Hr');
      Contract TestCon4 = new Contract (AccountId = test4.Id, Stage__c = 'Completed',Status = 'Active', RecordTypeId = '0123000000002Hr');
      Contract[] con = new Contract[] {TestCon1, TestCon2, TestCon3, TestCon4};
     
      AddeCon(con);
          
      // Execute trigger with test data set
    
      // Confirm results
      Account[] acctQuery = [SELECT eCon_Completed__c FROM Account WHERE Id = :accts[0].Id OR Id = :accts[1].Id OR Id = :accts[2].Id OR Id = :accts[3].Id];
      System.assertEquals(TRUE, acctQuery[0].eCon_Completed__c);
      System.assertEquals(FALSE, acctQuery[1].eCon_Completed__c);
      System.assertEquals(FALSE, acctQuery[2].eCon_Completed__c);
      System.assertEquals(TRUE, acctQuery[3].eCon_Completed__c);
   }
  
}

Trigger:

trigger ContractUpdate on Contract (after update) {

ContractUpdate.AddeCon(Trigger.new);
 
}


Message Edited by DT Developer on 09-16-2008 02:32 PM

Message Edited by DT Developer on 09-16-2008 02:43 PM
Hi,
 
I'm trying to think of an efficient way to pull the value of a custom field (Cost_Center__c) within the User table. Here's my situation: I'm given a set of Event records and using their OwnerId's, I'm trying to think what'd be an optimal way to pull the user's cost center. My requirement is that I read the currently logged in user's cost center, and given the set of event records, only pull the events with users (the user which the event is assigned to) that have a matching cost center.
 
I know I could get all the OwnerId's from the Event records and use them to query the user table to find the matching pair, but then I'd be making one API call/comparison, which isn't optimal at all. Also, I could probably add a new field on the Event record that calls an Apex Trigger (after insert) that would check the event's OwnerId, lookup the user table and write the cost center over to this new field.
 
Is there something else I could do to achieve my goal?
 
Thanks in advance.


Message Edited by HL-Dev on 09-11-2008 09:21 AM
  • September 11, 2008
  • Like
  • 0
I have a parent to child relationship query question. Here's a snippet of my code:
 
Code:
var queryString = "SELECT FirstName, LastName, " +
          "(SELECT Subject, Id FROM Events WHERE Subject = 'x') " +   
          "FROM Contact " +
          "WHERE Organization__c = '{!Contact.Organization__c}' " +
          "AND ZoneR__c = 'x' " + 
          "AND Sub_ZoneR__c = 'x' " +
          "AND Primary_Cost_Center__c = 'xxxx' " +
          "AND ((Production__c = 'A') OR (Id = '{!Contact.Id}') OR " +
          "(Production__c = 'B') OR (Production__c = 'C') OR " +
          "(Production__c = 'C')) " +
          "LIMIT 100";
var queryResult = sforce.connection.query(queryString);
results = queryResult.getArray ("records");
 
I'm trying to gather events information from a list of contacts. In my query, I'm trying to get a list of contacts that match a certain criteria and for each contact, I get the events' id and subject if they have any. Question is: how can I store the results that I get back from the parent-child relationship into a variable? In my example, if I wanted to get the contact's first name from the query result, I could assign a variable to results.FirstName. But I'm not sure how to accomplish the same for the results I get from the Parent to Child relationship (the events' info that I get back).
 
Thanks in advance.
 


Message Edited by HL-Dev on 06-13-2008 01:27 PM
I've implemented a simple Google Map application that plots the top producers of a territory. Currently, the map is associated at the contact record level and it's set up as an S-Control that's attached to a custom button on the contact detail page.
 
I've started geocoding the contacts' addresses using the Google Map GClientGeoCoder class, which makes a call to the Google servers (I send the address to it and it returns the coordinates back). This process is very inefficient and overhead heavy, especially with multiple addresses. Plus, there's really no need to geocode an address if it has been previously, unless the address on the contact record has changed.
 
For anyone that has worked on integrating SF with GoogleMaps before: what's the best way to get the coordinates from an address? I've seen a previous thread that seems to store the coordinates into custom fields, but I cannot find the source code to understand how the storage-goecoding is done.
 
Any insights will be appreciated, thanks!
  • April 30, 2008
  • Like
  • 0
i'm trying to figure out how i force an exception to happen so I can cover my catch statements in testMethods.

can anyone tell me how to force a DML exception and a generic one?  i can't figure out how, and when i try to manually set one up, apex just tells me that the exceptions cannot be constructed.
I have read several posts and done quite a bit of searching. I'm still having trouble. I have the following trigger:

Code:
trigger opportunityContactRoleUpdate on Opportunity (after Insert, after Update)
{

    for(Opportunity o : Trigger.new)
    {
        if((o.StageName == 'Closed Won (Recurring)' || o.StageName == 'Pilot (Recurring)') && o.Recurring_Opportunity__c=='Yes' && o.Probability>=90.0 && o.Client_Id__c==4944)
        {
            Date a = System.today();
            Date b = a.toStartOfMonth();
            Date c = b.addDays(-1);
           
            List<Opportunity> oldOpps = [SELECT id FROM opportunity WHERE Client_Id__c = :o.Client_Id__c AND closedate <= :c ORDER BY closedate DESC LIMIT 1];
           

            List<OpportunityContactRole> ocrs = [SELECT id, OpportunityId FROM OpportunityContactRole WHERE OpportunityId=:oldOpps[0].id];
           
            for(integer i=0; i<ocrs.size(); i++)
            {
                ocrs[i].OpportunityId = o.id;
            }
           
            if(!ocrs.isEmpty())
            {
                update ocrs;
            }
        }
    }
}

 For which I created an Apex Test class to get coverage on:

Code:
public class opportunityContactRoleUpdateTest {

 static testMethod void myTest()
 {
  Opportunity o = new Opportunity(name='Dave 1', stagename='My Stage 1');
  
  insert o;
  
  o.Name = 'Dave 1 Updated';
  o.Stagename = 'My Stage 1 Updated';
  
  update o;
 }

}

I created this based on another post - because the insertion and create of this opportunity would cause my trigger to fire, give me enough coverage.

I'm developing in Eclipse using the Force IDE. These are some of the problems I'm having.

1. I cannot save to the server more that the class definition of my Test class. The body of my class never saves to or gets to my production environment using the 'Save to Server' or 'Synchronize with Server' options in the Force IDE - although it runs, it never saves more than the inital class definition.

2. After I do get it on the server and run the test on it, how do I 'activate' the trigger (which by the way I can save to the server just fine...) Do I have to use the ant method to activate it, or can I do it with the Force IDE...I'm not having any luck finding the method to 'activate' the trigger.

3. I can 'run tests' on my small apex class that I created and it shows me 100% coverage...however it looks to me like it's telling me 100% of the testclass run, and not 100% of my trigger was covered...I would like to 'run all tests' on my apex class from SF, but as I said, i can't get it there...

I'm pretty stuck here. Any suggestions would help me out.

---

Updated: I downloaded and installed the latest Force IDE. I create a new workspace, and a new force.com project - synchronizing with our production env. Now I'm having additional errors when trying to run my test class. I get:

INVALID_OPERATION: Cannot specify both runAllTests and specific RunTests

This happens when I right click on the test class, select 'Force' and then run tests.




Message Edited by dave_mwi on 02-29-2008 12:58 PM

Message Edited by dave_mwi on 02-29-2008 01:00 PM
Hi all,
I've searched for other threads with similar issues, but I couldn't find one with an exact answer. I wrote some Apex code that attempts to update a field within a User record. When I tested my class, just by looking at my debug statements, it seems that the field is getting updated. However, when the trigger is actually fired, I'm getting the following exception:
 
System.DmlException: Update failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, You cannot update a customizable setup entity, except when running tests

So it seems on this particular table, the field can only be updated on a test class but not on my actual trigger.
I read the Apex Doc, and there's a section that mentions that not all SObjects can be updated using Apex but it doesn't specify which SObjects can or cannot be updated.
If anyone can confirm this, I'd appreciate it.
Thanks in advance. 
 

 
 
  • February 28, 2008
  • Like
  • 0
Hi everyone,
I'm fairly new at developing on this platform and have a few pre-deployment questions. I've written a trigger that executes after a certain event happens. Also, I wrote a testMethod for the previous trigger, and the test log shows no issues so far. Now, I've done all this on sandbox.
- When I'm ready to push this into production, would I first create a new project by synching the production box's metadata? Because sandbox's metadata isn't the same as production's.
- What happens if after the trigger is deployed on production, I decide to modify/remove it? Is it possible to remove a previous trigger by using the Force.com toolkit for Eclipse? Or is it only possible via the Ant tool?
Thanks in advance.
  • January 25, 2008
  • Like
  • 0
I'm having problems with a SOQL statement in one of my ajax pages and from what I can tell in the docs, it's not possible to do a "like" search and escape special characters... True?

Basically, I have a soql statement that takes in a value entered by the user.  If the value contains a single quote, the soql breaks.  I've tried escaping with ( \ ) I've tried replacing the singel quote with two single quotes ala SQL and I've tried replacing the single quote with &#39; and none of it works.

Is there a solution to this or should I just cut off the stuff after the quote and search on that?

Thanks,
-Zach


  • May 22, 2006
  • Like
  • 0