• MikeGoelzer
  • NEWBIE
  • 0 Points
  • Member since 2006

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 28
    Replies
How can I get a trigger that fires in response to a self-service portal user's actions to insert a new record?  I keep getting an exception like this for SSP users when doing an insert:

EXCEPTION:..Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Owner ID: id value of incorrect type: 03530000000v8GcAAI: [OwnerId]

No other user type has this problem, and all the profiles have create permission for the object I'm trying to insert.


Message Edited by MikeGoelzer on 11-10-2008 08:00 AM

Message Edited by MikeGoelzer on 11-10-2008 08:14 AM
I have a VF page that we embed in the Account detail page.  When the user clicks one of our <apex:commandlink>'s, it redirects to him or her to the new Case page.  The source we're using is below.

The problem is that this doesn't work inside the Console view.  Clicking the link redirects the whole browser (if I include a target="_top" attribute) or else does nothing at all.  Can anyone suggest an approach that would work on detail pages both in Console and when viewed normally?

Code:
                                            <apex:commandLink value="{!ent.ButtonCaption}" 
                                                action="{!CreateNewCase}" rendered="{!ent.rendered}" 
                                                styleClass="btn" onclick="navigateToUrl('/500/e—retURL=%2F0013000000MAsrv%3Fisdtp%3Dmn&amp;def_account_id=0013000000MAsrv&amp;isdtp=mn');"
                                                >
                                                    <apex:param name="prmFunc" value="{!ent.NewCaseFuncName}"/>
                                                    <apex:param name="prmEntId" value="{!ent.entitlement.Id}"/>
                                                    <apex:param name="prmSPId" value="{!ent.SPId}"/>
                                                    <apex:param name="prmEntName" value="{!ent.entitlement.Name}"/>
                                            </apex:commandLink>  

navigateToUrl is SF's Javascript but it doesn't work if I try to call it; I think that's because that function is defined outside of the IFRAME in which the VF page runs.



Message Edited by MikeGoelzer on 11-02-2008 11:33 AM
Hi, I have been having a very unusual problem with Eclipse and Ant when downloading metadata for a specific package in a specific salesforce org.  Seems like a problem with that org / package, but my support case isn't really going anywhere, so I am hoping someone else has seen this issue.

Here's the skinny:

1.  Ant with the usual downloadCode task on this package does this:




2.  Eclipse does this for the same package:




3.  If you dig into the Eclipse log, the exception always mentions "ManageableState.java" during its stack unwind.  So I assume the two pics have the same cause.

4.  No other package does anything like this for me.  Other orgs and even other packages within that particular org download fine.

5.  Eclipse on my Mac does the same thing for this package.  Ditto for a second PC.

Ideas on what might be happening? 


We have a managed package containing a custom object with three record types.  Pre-Winter '09 it worked fine; now it won't install in other orgs, and I'm hoping someone can help me understand what has changed.

Symptoms:

1.  In the dev org, doing a "Run all Tests" reports 0 failures.

2.  If I take the managed package install link to another org and install, I get a bunch of unit test failures like this:

ut_calculations_modelvalidator.SimplestTestCase()Apex Classes(01p800000008jBO)
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, record type missing for: Support Program
(ENT_2)
;


Here's the source code for this test:

Code:
    static testMethod void SimplestTestCase() 
    {
        ENT_2__Support_Program__c sp = new ENT_2__Support_Program__c( 
             Name='TestSP',
             P1__c = 'xyz'
             );
        insert sp;
    }


3.  I thought maybe Winter '09 wanted me to specify a RecordTypeId explicitly, so I tried several variations on this:

Code:
    static testMethod void SimplestTestCase() 
    {
        ENT_2__Support_Program__c sp = new ENT_2__Support_Program__c( 
             Name='TestSP',
             P1__c = 'xyz'
             );
        sp.RecordTypeId = '012300000009x0G';
        insert sp;
    }

 
Again, the dev org's "Run all Tests" has no problem with this.  (That id is a valid record type for the dev org's ENT_2__Support_Program__c object.)  But rebuilding the package and attempting an install in any other org gives this error message:

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: id value not valid for the users profile: 012300000009x0GAAQ: [RecordTypeId]
(ENT_2)

Any idea what I am doing wrong?
Why/how did Winter '09 break VF pages that are inlined into standard object detail pages?  All of a sudden, these inlined VF pages are displaying as shown below:



Clicking the "here" does in fact redirect the iframe to the correct URL, but what do we do to save the user from this extra click?

Our application uses an 'after insert' task trigger to trap the "Log a Call" and "Send an Email" actions.  We use this to log the first response on a Case.  This much works like a charm.

However, when Email To Case processes an inbound email, it creates a task.  We obviously don't want to count these as "responses" for that Case.  Luckily, E2C also inserts an EmailMessage object, and every EmailMessage object has a flag called "Incoming" plus a lookup field called ActivityId which together could be used to filter out the incoming emails.

Not so luckily, the EmailMessage objects don't get inserted until after the 'after insert' Task trigger has run.  So, the result is that our trigger has to make its decision about whether a "response" has occurred before the data it needs is actually available.  Specifically, the code below never prints anything in after insert:

Code:
for(Task t : trigger.new) {
EmailMessage[] emArr = [select Id,Incoming from EmailMessage Where ActivityId=:t.Id];
for(EmailMessasge email : emArr){
system.debug( 'email was:' + (email.Incoming ? 'incoming' : 'outgoing') );
}
}

b/c the inner loop never runs.  Does anyonre have a good suggestion (other than button overrides) to distinguish between outbound emails and inbound ones at the point where we are executing?

UPDATE 9/3/08:  Clarified wording + fixed the ternary operator in the code snippet.


Message Edited by MikeGoelzer on 09-03-2008 09:55 PM
I am trying to create a dependent package for the first time.  Per the docs, I started by installing the base (managed) package in a new DE org.  Then, I namespaced the new org and started copying over components.  However, I then noticed something odd.

In the new org, when I create a new Apex class in the web UI, it automatically gets assigned the namespace I defined for the new org.  But when I create a new class in Eclipse, it gets assigned the base package's namespace.

Which way is right?  Do dependent packages require their own namespace?
Is there any way in Apex to do an update on Case without re-running the assignment rules?  The SOAP API has a header for exactly this purpose, but is there any equivalent in Apex?

Is there a recommended way of pre-populating fields on the 'New' form?  For instance, let's say we want to show the user a New Case page where one custom field we've added is default set to a particular string.

I know about a non-recommended, undocumented way of doing it, and I can see that many AppExchange packages also know about this.  (ie, adding CF00012000000abcde=text to the URL)  But we've had some problems with it and would like to find an alternative.

Considered:  'fake' Visual Force New form that emulates the real one, but with the pre-population.  Problem is that, for Case at least, multiple page layouts will exist and this info is not fully exposed by the new Apex metadata classes.

Also considered:  generate a new object programmatically, setting the field in a trigger, and then show the user an edit page for the new record.  Problem is that this means all the assignment rules, triggers, workflow, etc., will run before correct info is available.

Any other ideas?  This is such a common request; there must be a better solution.
Once we create and upload a "Managed - Release" package, it seems to become impossible to delete or modify the package.  This is true even though there are no subscriber orgs, i.e., we uninstalled it fully from the one EE account where it had been installed as a test.

Is this a feature or bug?  (Managed Beta does not work this way; it offers a Delete button.)

EDIT:  subject line


Message Edited by MikeGoelzer on 07-07-2008 09:40 AM
How can I get a trigger that fires in response to a self-service portal user's actions to insert a new record?  I keep getting an exception like this for SSP users when doing an insert:

EXCEPTION:..Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Owner ID: id value of incorrect type: 03530000000v8GcAAI: [OwnerId]

No other user type has this problem, and all the profiles have create permission for the object I'm trying to insert.


Message Edited by MikeGoelzer on 11-10-2008 08:00 AM

Message Edited by MikeGoelzer on 11-10-2008 08:14 AM
We have a managed package containing a custom object with three record types.  Pre-Winter '09 it worked fine; now it won't install in other orgs, and I'm hoping someone can help me understand what has changed.

Symptoms:

1.  In the dev org, doing a "Run all Tests" reports 0 failures.

2.  If I take the managed package install link to another org and install, I get a bunch of unit test failures like this:

ut_calculations_modelvalidator.SimplestTestCase()Apex Classes(01p800000008jBO)
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, record type missing for: Support Program
(ENT_2)
;


Here's the source code for this test:

Code:
    static testMethod void SimplestTestCase() 
    {
        ENT_2__Support_Program__c sp = new ENT_2__Support_Program__c( 
             Name='TestSP',
             P1__c = 'xyz'
             );
        insert sp;
    }


3.  I thought maybe Winter '09 wanted me to specify a RecordTypeId explicitly, so I tried several variations on this:

Code:
    static testMethod void SimplestTestCase() 
    {
        ENT_2__Support_Program__c sp = new ENT_2__Support_Program__c( 
             Name='TestSP',
             P1__c = 'xyz'
             );
        sp.RecordTypeId = '012300000009x0G';
        insert sp;
    }

 
Again, the dev org's "Run all Tests" has no problem with this.  (That id is a valid record type for the dev org's ENT_2__Support_Program__c object.)  But rebuilding the package and attempting an install in any other org gives this error message:

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: id value not valid for the users profile: 012300000009x0GAAQ: [RecordTypeId]
(ENT_2)

Any idea what I am doing wrong?
We want to build reports using email addresses of contracted opportunities.  We can do this through the "Contact Roles" in Opportunities.  However, it is not required so very few of our users follow my instructions to fill it out.
 
1) Is it possible to design a workflow rule where if an opportunity is created and saved, the user must fill in something in the Contact Roles section?
 
2) If not - We have a lookup field in opportunities called Primary Contact (looks in Contacts tab for appropriate person).  Below that, I created a field called "Primary Contact Email".  Is it possible to design a trigger where if a name is inserted into the Primary Contact field via the lookup, the email address of that contact will automatically be pulled into the field "Primary Contact Email"
 
Thank you for any help you can provide!
 
 
Hi All,
I am using HttpRequest and HttpResponse method to make an external call in Apex. But in HttpResponse I am not getting the proper result. I am getting the "Status=Object Moved" and "StatusCode=302". I understand this is because of "response.redirect" on the requested page. For this, I again get theURL for the redirected page and made a new request by setting the new EndPoint. But this time I am getting the "Session time out error".
This is because  both request has different session. Any idea how we can made multiple request with same session?


Thanks,
NG
  • October 09, 2008
  • Like
  • 0

Yesterday's Winter09 Developer Highlights webinar mentioned some interesting new developer account features.  We were advised that we need to sign up for a fresh DE account to receive the new features, because existing DE accounts will not get the new features.  However, if I'm understanding correctly, developers that have already published managed-released packages from existing DE accounts will have a package prefix that is tied to their existing DE org.  That prefix is also intrinsic to the single managed package that is also tied to that org.  As far as I understand it, the tying of the prefix and the managed package to the DE account are key to making the package upgrades work.

So I think this means that existing managed apps cannot be moved to new DE orgs as far as I am aware.  Is there a way for these DE accounts to be upgraded to receive the new DE features?  Otherwise developers of existing managed packages won't have access to the new DE features.  Or maybe there's something I'm missing here?

  • October 09, 2008
  • Like
  • 0
I'm hoping that some one can spend a few minutes and verify the results that I am seeing here and hopefully, before I pull out what little hair I have left, tell me where I am going wrong.

I am attempting to swap a user's profile using Apex Code but I am receiving this error message:
Code:
System.DmlException: Update failed. First exception on row 0 with id 005500000011fHiAAI; first error: FIELD_INTEGRITY_EXCEPTION, 
This profile is used by a user who is a delegated admin and must have the view setup permission: Profile ID: [ProfileId]
 
I do not have any delegated admins defined AND the two profiles in question are unused (except by the user in this test case). 

Here is the Apex Class.  The test method runs w/o issue.
Code:
global class ProfileSwap {
    
    public static String origProfile = 'Sales-Test-A';
    public static String altProfile = 'Sales-Test-B';
    public static String targetUserEmail = 'someone@somewhere.com';
    
    public ProfileSwap(){}
    
    /* swaps current profile for a pre-determined alternate */
    public void swap(ID userID){
        
        //-- load current user profile
        User u = [select id, profileId from User where id =: userId];
        if( u == null ) throw new ValidationException('Unable to load user with id '+userId);
        System.debug('>>>>>> Loaded user '+u);
        
        Map<ID,ID> profileMap = getProfileMap();
        if( !profileMap.containsKey(u.profileId) ) throw new ValidationException('Unknow profile, cannot swap');
         
        //-- update w/ new profile
        u = new User(id=u.id, profileId = profileMap.get(u.profileId));
        System.debug('>>>>>> Updating user: '+u);
        update u;
    }
    
    /* returns mapping between current and target profiles */
    public static Map<ID, ID> getProfileMap(){
        //-- load target profiles
        ID origProfileId = [select Id from Profile where name =: origProfile].id;
        ID altProfileId = [select Id from Profile where name =: altProfile].id;
        
        Map<ID,ID> profileMap = new Map<ID,ID>();
        profileMap.put(origProfileId, altProfileId);
        profileMap.put(altProfileId, origProfileId);
        
        return profileMap;
    }

    public static testMethod void test(){
        
        User u = [select id, profileId, profile.name from User where email =: targetUserEmail];
        
        //-- mapping of profile to swap from -> to
        Map<ID,ID> profileMap = getProfileMap();
        
        //-- expected resulting id
        ID targetId = profileMap.get(u.profileId);
        String startProfile = u.profile.name;
        
        //-- swap profiles
        new ProfileSwap().swap(u.id);
        
        //-- verify
        u = [select id, profileId, profile.name from User where email =: targetUserEmail];
        System.debug('Orig Profile: '+startProfile+'; Swapped Profile: '+u.profile.name);
        System.assert(targetId == u.profileId, 'Expected target profile "'+targetId+'", got "'+u.profileId+'"');
    }
    
    webservice static void doIt(String userId){
        new ProfileSwap().swap(userId);
    }
}
 

The 'doIt' method is invoked by an OnClick javascript link on the user's home page.  Adding 'without sharing' to the ProfileSwap class does not affect anything.
Code:
{!requireScript("/soap/ajax/14.0/connection.js")}
{!requireScript("/soap/ajax/14.0/apex.js")}
  try{
        var userId = "{!$User.Id}";
 sforce.apex.execute("ProfileSwap", "doIt", {userId:userId});

  } catch(e){ alert(e); }

Thanks for your time.

--Chris
  • October 09, 2008
  • Like
  • 0
I would like to create a S-Control on the Contact object to NOT allow the contact to be deleted if this contact id exists in another custom object called 'ShipTo'. This custom object 'ShipTo' contains contact id's and contract ids that this contact is associated with. So, in other words, if the contact to be deleted is also referenced in this custom object, 'ShipTo', then issue a message to the user that this contact can not be deleted because it is associated as a ShipTo contact in this custom object. Is this possible via a S-Control and maybe some tips in acomplishing this.

Thanks.
Why/how did Winter '09 break VF pages that are inlined into standard object detail pages?  All of a sudden, these inlined VF pages are displaying as shown below:



Clicking the "here" does in fact redirect the iframe to the correct URL, but what do we do to save the user from this extra click?

Hi,

I'm trying to make my apex code navigate automatically to a given account page (after some processing, the method comes up with the account id). My apex code is invoked by an update trigger. Is this possible?

Thanks
  • October 02, 2008
  • Like
  • 0
It would seem that the answer is no - though that doesn't make sense.

Basically, I am trying to write a before insert trigger to populate the Name (official) field of a custom object.  I have read a number of messages that are very close to this one - but not quite. Some folks recommend creating a VisualForce page, but I am trying to do it on a standard Salesforce form.

When I enter a new record, I get a message back saying "Invalid Data", "You Must Enter a Value". Now, this trigger works fine if I have it autopopulate a different, non-required field, it's fine. However, if I try to use it with the object's Name field or even another field that I have set to required, it fails. Does this sort of process not work , or am I mssing something?

Code:
trigger updateEnrollmentRecordName on Enrollment__c (before insert, after update) {
    List<Enrollment__c> updatedEnrollment = new List<Enrollment__c>();
    for (Enrollment__c e : trigger.new){
        e.Name = e.Enrollee_Name_Text__c + ' - ' + e.Program_Name__c + ' ' + e.Cycle__c + ' ' + e.Cycle_Year__c;
        updatedEnrollment.add(e);
  }     
 }

Many thanks.



Message Edited by ksnyder on 10-02-2008 03:07 PM
Dear all,
 
I have very critical issue with production trigger, as it not allowing me to inactivate it.
I've changed the corresponding meta xml under each trigger and tried to Deploy to Server thru eclipse, but it doesn't update in production!!! :-( This is very very critical,as i need to disable the trigger very soon now. Please help me what could be the solution to edit/inactivate the trigger?

<?xml version="1.0" encoding="UTF-8"?>

<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">

<active>false</active>

<apiVersion>10.0</apiVersion>

</ApexTrigger>

 

Thanks in advance

 

  • October 01, 2008
  • Like
  • 0
Hi,

I have a trigger in Opportunity object (UpdateOpportunityAmount) that updates the Amount field based on stage. This trigger calls the Opportunity Line Item object to update the unit price accordingly.

In Opportunity Line Item we have a trigger (UpdateOpportunityProduct) that sets certain fields in opportunity object, based on selected Product. The error I am getting is.
Code:
UpdateOpportunityAmount: execution of BeforeUpdate

caused by: System.DmlException: Update failed. First exception on row 0 with id 00k60000005cTOLAA2; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateOpportunityProduct: execution of BeforeUpdate

caused by: System.DmlException: Update failed. First exception on row 0 with id 0066000000APwGhAAL; first error: UNKNOWN_EXCEPTION, Object (id = 0066000000APwGh) is currently being updated in trigger UpdateOpportunityAmount: [Id]

Trigger.UpdateOpportunityProduct: line 45, column 17

Trigger.UpdateOpportunityAmount: line 27, column 17

I know the reason, I just cant think of a solution or a workaround. because of the before update/ after update issue with triggers, i cant perform the Opportunity Line Item operation within the Opportunity Trigger.Any help would be highly appreciated.

Thanks,

 

  • September 15, 2008
  • Like
  • 0
If I have an "after insert" trigger, I can use something like the following to determine whether a particular field has changed:

if (Trigger.old[0].myfield__c != Trigger.new[0].myfield__c) {
    // field changed
}
else {
    // field didn't change
}
 
Right?

If Trigger.old and Trigger.new have more than one record (because the trigger fired due to several records being changed at once), can I be certain that the records in Trigger.old and Trigger.new are always in the same order? In other words, can I assume that Trigger.old[x] and Trigger.new[x] refer to the same record?

Thanks,

Jeri
Can anyone help troubleshoot why my test coverage code is not testing a bulk update?
 
Here is my test coverage code:
 
Code:
static testMethod void testOpportunityOwnerRoleClass() 
 {
  // Create a new opportunity to test
  Opportunity o = new Opportunity(Ownerid='00540000000o1y6AAA',Name='Test Opportunity Owner Role Trigger',CloseDate=Date.newInstance(2008,12,31),StageName='Prospecting');
  insert o;
  // Check if owner role field has been set to updated with owner role
  System.assert(true, [Select Owner_Role__c from Opportunity WHERE ownerid = '00540000000o1y6AAA']);
  //System.assert(true, [Select Owner_Role__c from Opportunity WHERE ownerid = '00570000000sTcH']);
 }
 
 static Opportunity createNOpportunities(Integer n) {
 
 
  Opportunity opp = new Opportunity(
   ownerid = '00540000000o1y6AAA',
   Name = 'Bulk Opportunity Test',      
   StageName = 'Prospecting',     
   CloseDate = System.Today());
  
  insert opp;
  
  return opp;
 }
 
 
 public static testMethod void testBulkOpportunities() {
  
  Opportunity o = createNOpportunities(numOpportunities);
  o.StageName = 'Qualification';
  update o;
  
  Integer i = 0;
  for (Opportunity op : [Select Owner_Role__c from Opportunity WHERE ownerid = : o.ownerid])
  {
   System.assertEquals('SVP, Sales & Marketing',op.owner_role__c);
   i++;
  }
 }

 
I'm trying to loop thru multiple opportunities where a field has been updated and assert that each opportunity with a specific ownerid is set correctly?
 
I'm having problems looping thru all opportunities created in the bulk test?
 
Currently, my test coverage code is 67%.  I need another 8% to deploy.
 
Please help.
Thankk you.


Message Edited by Dman100 on 09-02-2008 11:18 PM

Message Edited by Dman100 on 09-03-2008 09:58 AM
  • September 03, 2008
  • Like
  • 0
Hi all,

sorry if this has already been posted.

I am working on the Customer Service part of Salesforce.
When logging Cases, the system should calculate a due date based on the SLA and on the Customer Service Center Calendar (meaning, without holidays, bank holidays, week-ends, etc.).
Since there are no standard feature to enable this feature, I have been told this is feasible through Apex.

I'm pretty new in the Apex world: I've done some developments, but nothing too fancy, so if you could help me out on this one, I would really appreciate.
Not mentioning I'm sure it's the kind of issue Customers face all the time...

Thanks in advance,
Free
 
  • August 29, 2008
  • Like
  • 0
I would like to be able to update the CASE subject field with the contents of 2 other custom fields everytime the record is updated/added.
Do i just use the workflow with field update?
Can it be done with s-control snippet? if so, how?

Thanks in advance for any help or direction