• grigri9
  • NEWBIE
  • 260 Points
  • Member since 2009

  • Chatter
    Feed
  • 10
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 31
    Questions
  • 84
    Replies

 

trigger CEWSowner on PSC_CEWS__c (before insert) {
    PSC_CEWS__c  [] CEWSList = trigger.new;
    List <PSC_CEWS__c> updatedListToInsert= new List <PSC_CEWS__c>();
       
    for(PSC_CEWS__c CEWS : CEWSList){
         List<User> lookupCEWSUser = [select ID from User where CAI__c =: CEWS.CAI__c Limit 1];
         if(lookupCEWSUser.size() > 0){
         CEWS.Ownerid = lookupCEWSuser[0].Id;
         updatedListToInsert.add(CEWS);
         }
     }
    if(updatedListToInsert.size() > 0) {
    insert updatedListToInsert;
    }
}

 So I have a custom object 'PSC_CEWS__c' that is upserted/inserted with a unique identifier for each user 'CAI__c.'     Before insert, i want to match the CAI__c to the correct User in Salesforce, and make that person the record owner.   So far, this actually does nothing.  I have something typed wrong, but have looked at it long enough and am thinking I'm missing something real basic here.

 

Any thoughts?

  • November 12, 2011
  • Like
  • 0

Hi

 

I am moving my new objects,code,pages from test environment to production. I have around 8 objects and each object have number of new fields. If i add the profiles along with the new objects from force.com IDE to production does the field level security  also moves to production? 

 

Appreciate if you can anyone answer for this as i have a deployment scheduled tomorrow.

Hello,

 

I have created a trigger that runs a class to update the account on an asset when an inactive tick box is ticked.

 

Here is my class:

 

public with sharing class Inactive_asset_class {

   public static void Inactive_asset(Asset[] cont){

      ASSET a = [select asset.AccountId FROM ASSET where Inactive__c=true ];
      a.Accountid = '0012000000oX453';
      update a.account;
   }
}

 

Here is my trigger:

 

trigger inactive_asset on Asset (after update){
    Inactive_asset_class.Inactive_asset(Trigger.new);

}

 

Here is my test:

@isTest
private class InactiveTriggerTest {

    static testMethod void myUnitTest() {
       
       //create a test asset
       
       Asset test_asset = new Asset(id='02i2000000KU6mR',accountid='0012000000foauZ',name='0012000000foauZ',Asset_Tag__c = '18668',Inactive__c=false);
       
       test_asset.Inactive__c=true;
       UPDATE (test_asset);
       

  
      }
}

 

 

Unfortunately the trigger is failing to deploy with this failure, any ideas?  I just can't suss this out!

 

Run Failures:
  InactiveTriggerTest.myUnitTest System.DmlException: Update failed. First exception on row 0 with id 02i2000000KU6mRAAT; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, inactive_asset: execution of AfterUpdate

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

Class.Inactive_asset_class.Inactive_asset: line 7, column 14
Trigger.inactive_asset: line 2, column 5: []

 

  • November 11, 2011
  • Like
  • 0

Hi,

I am trying to automatically assign a new user to a Chatter Group called 'Everyone'.  The code below works as long as I do not select a role; however, when I select a role I get the following error.  Does anyone have a clue what this error means or if there is a code that can do what I am trying to do?

 

22:29:46.425
(425800000)|EXCEPTION_THROWN|[24]|System.DmlException: Insert failed.
First exception on row 0; first error: MIXED_DML_OPERATION, DML
operation on setup object is not permitted after you have updated a
non-setup object (or vice versa): CollaborationGroupMember, original
object: User: []
22:29:46.426
(426685000)|FATAL_ERROR|System.DmlException: Insert failed. First
exception on row 0; first error: MIXED_DML_OPERATION, DML operation on
setup object is not permitted after you have updated a non-setup object
(or vice versa): CollaborationGroupMember, original object: User: []

 

 

 

trigger User_trigger on User (after insert, before insert, after update, before update) {
    if ( Trigger.isInsert ) {    
        if ( Trigger.isAfter ) {
            List<CollaborationGroupMember> cgm = new List<CollaborationGroupMember>();              
            Id cgID = [ Select Id 
                      FROM CollaborationGroup 
                      WHERE Name = 'Everyone' LIMIT 1 ].ID;
System.debug('zzz: ' + cgID);    
            for ( user u: Trigger.new ) {
                cgm.add(new CollaborationGroupMember (CollaborationGroupId = cgID, MemberId = u.id));    
            }    
            insert cgm;          
        }
    }
}

 



This seems like a layup but cant figure out the syntax.

Since I cant use a formula field to reference cross-objects on standard objects (we like the case to be related to the opportunity) I need to populate two fields that I will use in a simple mail template.

How do i reference the value that is in case field Order_Number__c?

trigger addOppFields on Case (before insert) {
Case mycase=trigger.new[0];
Opportunity opp=[select ID,Webpartner__c from Opportunity where name = :mycase.Order_Number__c];
mycase.XMWebPartner__c=opp.Webpartner__c;
mycase.Merge_OpportunityID__c=opp.ID;

 

I am getting a DML not allowed on generic list error when running some apex code that inserts a list of custom objects into the database.  The code snippet below creates two custom objects and stores them as concrete types in a generic list (List<sObject>).  However, when i try to insert the custom objects into the database using a single insert statement on the list, i get the DML not allowed on generic list error, even though when i inspect the output in the debug window I can clearly see that the list contains two concrete custom objects… Any idea why I am getting this error?  This seems like an inconsistency...

 

code:
List<sObject> itemsToInsert = new List<sObject>();


sObject outputCategoryTypeSO = new AgreementLineItemCategoryType__c(AgreementLineItemCategory__c = outputCategorySO.Id);itemsToInsert.add(outputCategoryTypeSO);


outputCategoryTypeSO = new AgreementLineItemCategoryType__c(AgreementLineItemCategory__c = outputCategorySO.Id);itemsToInsert.add(outputCategoryTypeSO);


system.debug(LoggingLevel.INFO, 'itemsToInsert = '+itemsToInsert);
if (!itemsToInsert.isEmpty()) {

    Database.insert(itemsToInsert);

}

debug log:
11:11:58:442 USER_DEBUG [210]|INFO|itemsToInsert = (AgreementLineItemCategoryType__c:{AdjustmentType__c=% Discount, AgreementLineItemCategory__c=a5GS00000004CxzMAE, PriceMethod__c=Per Unit, Product_Type__c=Maintenance, ItemSequence__c=1, PriceType__c=One Time, ConfigurationId__c=a3LS00000008btoMAA, IsOptionRollupLine__c=false, Quantity__c=1.00000, BasePriceMethod__c=Per Unit, Term__c=1, PriceUom__c=Each, SellingFrequency__c=One Time, LineNumber__c=1, ChargeType__c=Standard Price, Description__c=Acrobat Desk-09946063, AdjustmentAmount__c=2.00000, Frequency__c=One Time, LineType__c=Product/Service, SummaryGroupId__c=a3YS0000000CchoMAC, Uom__c=Each}, AgreementLineItemCategoryType__c:{AdjustmentType__c=% Discount, AgreementLineItemCategory__c=a5GS00000004CxzMAE, PriceMethod__c=Per Unit, Product_Type__c=Maintenance, ItemSequence__c=1, PriceType__c=One Time, ConfigurationId__c=a3LS00000008btoMAA, IsOptionRollupLine__c=false, Quantity__c=1.00000, BasePriceMethod__c=Per Unit, Term__c=1, PriceUom__c=Each, SellingFrequency__c=One Time, LineNumber__c=2, ChargeType__c=Standard Price, Description__c=Acrobat Desk-09946064, AdjustmentAmount__c=3.00000, Frequency__c=One Time, LineType__c=Product/Service, SummaryGroupId__c=a3YS0000000CchoMAC, Uom__c=Each})
11:11:58:442 DML_BEGIN [215]|Op:Insert|Type:SObject|Rows:2
11:11:58:443 EXCEPTION_THROWN [215]|System.TypeException: DML not allowed on generic List<SObject>

 

What is really interesting is that if i make a simply change to the code to insert the items one at a time it works:

 

if (!itemsToInsert.isEmpty()) {

    for (sObject insert_item:itemsToInsert)  {

        system.debug(LoggingLevel.INFO, 'insert_item = '+insert_item);

        Database.insert(insert_item);

    }

}


Thanks


  • November 09, 2011
  • Like
  • 0

Hi,

 

Would it be possible to retrieve the criteria that triggers a workflow rule from within an Apex Class?  I'm wanting to display a string similar to what you see on the WF pages on a VF page:

 

(Plan Process: Plan Stage Name equals Implementation) and (Plan Process: 1st Payroll Upload Date not equal to null)

 




 

 

Hi All,

 

Writing my first test class here and fallen at the first hurdle!

 

To be able to test my class I need to instantiate a load of test objects first of all, so I have written a little class to do that which works fine.

 

The class I want to test is a (will be a) shopping cart that does nothing but instantiate so far.

 

I've started writing the test class to go alongside for my TDD. First I've instantiated all the test objects and written my first test method. However, Force.com IDE complains that objects are not available in my class. So when I try to save  

 

 

@isTest
private class TMDR_ShoppingCartTest {



	testBuildObjects tbo = new testBuildObjects();
	Account a = tbo.createAccount();
	Contact c = tbo.createContact(a.id);
	Opportunity o = tbo.createOpportunity(a.id,c.id);
	OpportunityContactRole ocr = tbo.createOpportunityContactRole(c.id,o.id);
	OpportunityLineItem oli = tbo.createOpportunityLineItem(o.id);
	OpportunityLineItem oli2 = tbo.createOpportunityLineItem(o.id);
	OpportunityLineItem oli3 = tbo.createOpportunityLineItem(o.id);
		
	static testMethod void testInstantiate() {
			
			System.Debug('########Starting Shopping cart tests###########');
			TMDR_ShoppingCart cart = new TMDR_ShoppingCart(o.id);
		
	}

}

 

 

 

 Force.com complains that o.id does not exist!

 

This must be a simple one. Can you help?

 

TIA

 

 

 

 

I had an APEX class which sends out a specified email to the given address with some lead details, then updates the lead.

I've completed the class with a simple function, it inserts a completed task  assigned to the lead.

The class works fine in Sandbox but deployment is failed. In the result I get the next failures: all my active triggers are listed with problem: "Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required"

 

What's wrong?

 

Thanks for the answers!

Hi,

I have enabled inline editing feature in my SFDC instance which works fine for all the objects. I tried overriding New/Edit button on Opportunity  which calls an  S-Control and takes back to the Opportuinty Layout after  processing. Once the S-Control moves back to the Opportunity, Inline Editing feature gets disabled for that opportunity and it doesnt works.

Should we pass on some hidden parameter to the opportunity page while transfering control to the opportunity which keeps that inline editing feture enabled?

Please suggest..

Thanks in advance.


Message Edited by GreatG on 12-20-2007 03:03 AM
  • December 20, 2007
  • Like
  • 0

In the rules it says SF may close sign up if there are 6000 "registrants / teams". Does that mean that up to 6000 people can register or up to 6000 teams?

Is there a limit to the number of members that can be in a team?

I have a requirement to show/hide "child" inputfields on a page based on the values of parent inputfields. Currently I am doing this with an actionsupport on the parent field that re-renders the child fields when the parent changes. This works fine but it's a bit slow and I was hoping to replace this with javascript remoting.

However, afaik there is no way for me to add/remove inputfields by manipulating the DOM such that they are not part of the form submit. I.E. if someone makes a change to an inputfield and later I hide that field I don't want any page level validation to run on that field or for the changes the user made to be saved.

 

Is there a way to do this or do I need to stick with re-rendering the fields?

This is a brand new windows 7 install and so far I have been completely unable to get the force.com IDE working on this machine.

 

I am getting the following error when trying to create a force.com project:

 

com.salesforce.ide.api.metadata.types.Metadata$JaxbAccessorF_fullName cannot be  cast to com.sun.xml.bind.v2.runtime.reflect.Accessor

 

Specifically, I am able to create the project in eclipse and fetch the component metadata but when I click finish I get this error. This occurs on DE and sandbox orgs alike.

 

I've tried everything I could possibly think of to get rid of it but nothing seems to solve it. This error persists across all versions of eclipse that I've tried it on (galileo, helios, helios 64-bit, stand alone force.com IDE). I've even gone back to a system restore point and completely re-installed the JDK and eclipse from scratch and this error still occurs.

 

ANY information that anyone has about the root cause of this error or what might be causing it would be greatly appreciated.

 

 

I am building a questionnaire with about 500 fields (questions) that need to be translated into about a dozen languages. 

 

I was hoping to use the translation workbench and put the question text into the field labels but the 40 character limit on field labels is way too small. I.E. I have a field "Time with Employer" with associated question text "How long have you been with your current employer (in years and months)?"

 

My other idea was to put the question text into custom labels but I wasn't able to access the custom labels dynamically which is a requirement because all my fields are being created with dynamic vf bindings.

 

I.E.

 

<apex:repeat value="{!fields}" var="f">
{!$Label[f.custom_label_name__c]} <!--labels can't be accessed dynamically like this-->
<apex:inputField value="{!mapToObject[f.API_Object_Name__c[f.API_Field_Name__c]}">
</apex:repeat>

 

 

Has anyone found a way to dynamically reference a customlabel or gotten salesforce to increase the field label character limit?

 

There's a field called package license ID on the license object in the license management app from salesforce. According to the description it's used to track uninstalls.

 

Is there any way for me to see the value of this field in the org where I have installed the package? I think it has to be in there somewhere because when I uninstall the package salesforce is presumably using this field to go and update the license record in my LMA org.

I have a very simple visualforce page that I'd like to add to my managed package that prints out:

 

your installed package version is: 1.1

I realize an admin can just look this up or I can store this type of info in a custom setting but bear with me. 

 

So far I've found two possible ways to do this in code but both of them have drawbacks.

 

1) Have a function along the following lines:

 

if(Package.Version.Request == Package.Version.1.0))
  version = '1.0';
else if(Package.Version.Request == Package.Version.1.1))
  version = '1.1';
else if(Package.Version.Request == Package.Version.2.0))
  version = '2.0';		

This works but I would have to update this function every time I create a new package version.


2) output the package.version.request object directly onto a visualforce page. I can output the following: 

 

your installed package version is: Version[$namespace.1.1]

 

It's fairly straightforward to parse the numbers out of here but this will stop working if salesforce changes hows they output this object. 

 

It's ridiculous but there aren't any functions like Package.Version.GetMajorNumber or Package.Version.GetMinorNumber. Does anyone know of a better method of doing this?

There are a number of interesting ideas I've had for things I could do if I could easily work with the metadata api: mass updating field-level security, creating object definitions based on csv's, xmldiff's between sandbox and production.

 

Except for the php toolkit is there anything that works with the metadata api? Beatbox is exactly what I want (written in python and can be easily ported to GAE) but only appears to support the web services api.

I'm trying to deploy custom and standard profiles (including field level security) from one sandbox to another. I get the following error message:

 

 

Problem: duplicate value found: <unknown> duplicates value on record with id: <unknown>

 

 

Deleting a profile and then re-creating it by deploying works fine but I obviously can't do this for the standard profiles. My guess is that some part of the profile that should be unique is being re-created when it should be overwritten.

 

Anyone else hit this issue?

 

  • September 28, 2010
  • Like
  • 0

I'm getting an Internal System Error when I try and clone an AccountShare record. Is this expected behaviour?

 

 

AccountShare share = new AccountShare();
Sobject temp = share.clone();

//Internal System Error: 484031483-1083 (1704813194)

 

 

I'm offloading my apex sharing logic into groups so instead of creating/deleting sharing records I will be creating the group and then creating/deleting group members as needed.

 

My only concern is that there is some sort of limitation in the group object that I'll start hitting when we have 100,000 groups in our org. Has anyone done something similar?

 

--Greg

Whenever a new Task is created the assigned to (ownerid) field is filled in on the edit page. Is there a way to leave this blank by default and force the user to select a user? The only solution I've found so far is re-creating the edit page as a visualforce page.

I use a number of outputpanels ( with layout="none" ) in the plainTextEmailBody component of a visualforce email template for some simple conditional logic. However, since API 18 came out I get the following error message:

 

 

Error occurred trying to load the template for preview: <messaging:plainTextEmailBody> cannot contain <apex:outputPanel>.. Please try editing your markup to correct the problem.

 

My email templates API version field is set to 15.0 but I guess it is ignoring this and using API 18 instead?

 

Has anyone else experienced the same issue? Is there a solution besides changing all my email templates to not use outputpanels in the plaintext component? 

 

--Greg 

 

Message Edited by grigri9 on 03-08-2010 04:50 PM

I have some code that sends out an email. If I run that code from inside salesforce it works fine. However, if I run that code as the public sites user I get the following SendEmailResult error.

 

SendEmail failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []

 

However, all the mailing objects ID's (who, what, template and orgwide) are exactly the same when I send it from inside salesforce and from the website so I don't understand how it could be giving an error in one case but not the other.

 

 Here's the code that sends the email:

 

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 

mail.setTemplateId(template);

mail.setwhatId(what);

mail.setTargetObjectId(who);

mail.setSaveAsActivity(true);

mail.setOrgWideEmailAddressId(orgwide);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail});

 

for(Messaging.SendEmailResult res : r){

if(res.isSuccess() == false)

System.debug(res.geterrors().get(0).getMessage());

}

 

 Am I misunderstanding the error or is there some other ID field that could be screwing up the email?

 

 

Message Edited by grigri9 on 11-17-2009 09:08 PM

We have an external license key server that we use to fill in a license key field on Assets. The license key server is only able to return one license key at a time. The getLicenseKey function is called from a trigger and iterates through the Assets, returning a license key for each. However, if we run the trigger for anymore than 10 Assets we hit the 10 callouts governor limit.

 

Is there any way to avoid this governor limit by splitting the code into multiple Apex transactions somehow? 

I have some custom validation going on whenever someone creates Opportunity Products. I have a trigger that runs after insert that adds errors to any Opp Prods that fail those rules. However, If I throw an error on some records but not others my trigger runs again on the records that did not fail. 

 

 

Is there a way for me to prevent the trigger from running again if there is an error on any of the records? Basically, I want to set the Database.DML all_or_none parameter for people who are saving through the UI.

 

 

The Apex documentation says that "This argument is allowed only when a template is not used." However, I am able to use that field with an email template.

 

Does anyone know if this is correct behaviour and the docs are wrong, or is this a bug that I shouldn't rely on?

 

--Greg

I have the following trigger that simply calls a function in a class that gets a pdf blob.

 

 

trigger updOpportSendEmail on Opportunity (after insert, before update) { EditOpp.saveoppnew(trigger.new[0].ID); }

 

 

@future public static void SaveOppNew(String ID){ Opportunity OppObj = [select ID,StageName,AccountID from Opportunity where ID=:ID limit 1]; system.debug('*****'+OppObj.ID);

PageReference pdf = Page.Invoice_Email; pdf.getParameters().put('id',OppObj.ID); system.debug('*****before blob'); Blob pdfBlob = pdf.getContent(); system.debug('*****after blob');

}

 

The Id is getting pulled correctly and if I manually go the the Invoice_Email page for that opportunity everything works fine. Does anyone have any idea why pdf.getContent() is giving me the following exception?

 

 

System.VisualforceException: java.lang.NullPointerException

 

 

--Greg

 

I am trying to get the inputfields on a custom new page I've created to show the default field values.  Right now I'm manually assigning the default values to the appropriate fields in my constructor, but it seems like there should be a better way to do this. Anyone have any ideas?

 

I also have a pageblocktable of child objects on that page (for mass creation.) Is there a way to have the code field (a formula field based on the product field) show up when someone fills in the product field?

 

child object pageblocktable:

 

<apex:pageBlockTable border="0" cellpadding="6" value="{!NewItems}" var="item" id="rows">
<apex:column headervalue="Product">
<apex:inputField id="prod" value="{!item.Product__c}" required="false" /> </apex:column>
<apex:column headervalue="Code">

  The following outputfield remains blank no matter what I do. I want it to show the results of the code__c formula

<apex:OutputField value="{!item.Code__c}" />
</apex:column>
</apex:pageBlockTable>

 

 

--Greg

 

Message Edited by grigri9 on 02-15-2009 08:45 PM
Message Edited by grigri9 on 02-15-2009 08:45 PM

I have the following VF component that is just 2 table rows and a closing table tag.

 

<apex:component controller="pageExClass">
<tr style="" height="80%">
<td height="80%">&nbsp;</td>
<td height="80%">&nbsp;</td>
<td height="80%">&nbsp;</td>
<td height="80%">&nbsp;</td>
<td height="80%">&nbsp;</td>
<td height="80%">&nbsp;</td>
</tr>
<tr>
<td colspan="2" height="35">&nbsp;</td>
<td bgcolor="#c0c0c0" colspan="1" class="txtb big3">Total</td>
<td class="nobr txtb">{!NumMemoItems}</td>
<td colspan="1" height="35">&nbsp;</td>
<td bgcolor="#c0c0c0" colspan="1" class="nobr txtb"><apex:outputField value="{!MemoInfo.Total_Amount__c}"/></td>
</tr>
</table>

</apex:component>

 

 If is use it in a page being rendered to html it properly creates the table and rows like so: html table  if I render to pdf the table is broken like so:  pdf table

 

Copying and pasting the component into the page directly fixes the issue. Does anyone know if there is some html being automatically created when you insert a component?

 

--Greg

 

Just wondering if the code is just used for judging or if it then becomes Open Source?

The purpose is to trigger on the SFDC "useraccountteammember" object. since this object is not exposed to write a trigger on, what I did is to write an apex batch job and copy useraccountteammember object to the custom object. and write a trigger on the custom object.

so Whenever the useraccountteammember changes, the custom object records change. (this is verfiied working fine). However, the changed record on the custom object does not fire the trigger on the custom object. (there is no trace on the system log at all that the trigger is fired)

 

Does anyone know if anything can possibly go wrong?  Thanks for your reply. 

  • November 17, 2011
  • Like
  • 0

Today I ran into a situation where an apparent transaction rollback occurred, so my AfterInsert trigger did not create records as I expected.  It made me wonder if rollback is recorded in the debug log.  I searched the debug log for "rollback" but didn't find anything.  Is rollback recorded in some other way?  I have the standard settings on the debug log filters.  I looked at all the highest settings but didn't find any rollbacks apart from SAVEPOINT_ROLLBACK, which did not appear in my logs.

 

 

Here are the details:

I have an AfterInsert trigger on CampaignMember that creates Opportunity records.  A 3rd party application (Eventbrite Connector) creates CampaignMember records.  If the Eventbrite Connector throws an when creating a CampaignMember record -- i.e. trying to add a contact that is already a campaign member -- then my trigger does create Opp records for the other CampaignMembers in the batch, but then all Opps get rolled back with no warning or errors.

 

thanks

david

 

trigger CEWSowner on PSC_CEWS__c (before insert) {
    PSC_CEWS__c  [] CEWSList = trigger.new;
    List <PSC_CEWS__c> updatedListToInsert= new List <PSC_CEWS__c>();
       
    for(PSC_CEWS__c CEWS : CEWSList){
         List<User> lookupCEWSUser = [select ID from User where CAI__c =: CEWS.CAI__c Limit 1];
         if(lookupCEWSUser.size() > 0){
         CEWS.Ownerid = lookupCEWSuser[0].Id;
         updatedListToInsert.add(CEWS);
         }
     }
    if(updatedListToInsert.size() > 0) {
    insert updatedListToInsert;
    }
}

 So I have a custom object 'PSC_CEWS__c' that is upserted/inserted with a unique identifier for each user 'CAI__c.'     Before insert, i want to match the CAI__c to the correct User in Salesforce, and make that person the record owner.   So far, this actually does nothing.  I have something typed wrong, but have looked at it long enough and am thinking I'm missing something real basic here.

 

Any thoughts?

  • November 12, 2011
  • Like
  • 0

Hi

 

I am moving my new objects,code,pages from test environment to production. I have around 8 objects and each object have number of new fields. If i add the profiles along with the new objects from force.com IDE to production does the field level security  also moves to production? 

 

Appreciate if you can anyone answer for this as i have a deployment scheduled tomorrow.

Hello,

 

I have created a trigger that runs a class to update the account on an asset when an inactive tick box is ticked.

 

Here is my class:

 

public with sharing class Inactive_asset_class {

   public static void Inactive_asset(Asset[] cont){

      ASSET a = [select asset.AccountId FROM ASSET where Inactive__c=true ];
      a.Accountid = '0012000000oX453';
      update a.account;
   }
}

 

Here is my trigger:

 

trigger inactive_asset on Asset (after update){
    Inactive_asset_class.Inactive_asset(Trigger.new);

}

 

Here is my test:

@isTest
private class InactiveTriggerTest {

    static testMethod void myUnitTest() {
       
       //create a test asset
       
       Asset test_asset = new Asset(id='02i2000000KU6mR',accountid='0012000000foauZ',name='0012000000foauZ',Asset_Tag__c = '18668',Inactive__c=false);
       
       test_asset.Inactive__c=true;
       UPDATE (test_asset);
       

  
      }
}

 

 

Unfortunately the trigger is failing to deploy with this failure, any ideas?  I just can't suss this out!

 

Run Failures:
  InactiveTriggerTest.myUnitTest System.DmlException: Update failed. First exception on row 0 with id 02i2000000KU6mRAAT; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, inactive_asset: execution of AfterUpdate

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

Class.Inactive_asset_class.Inactive_asset: line 7, column 14
Trigger.inactive_asset: line 2, column 5: []

 

  • November 11, 2011
  • Like
  • 0

Hi,

I am trying to automatically assign a new user to a Chatter Group called 'Everyone'.  The code below works as long as I do not select a role; however, when I select a role I get the following error.  Does anyone have a clue what this error means or if there is a code that can do what I am trying to do?

 

22:29:46.425
(425800000)|EXCEPTION_THROWN|[24]|System.DmlException: Insert failed.
First exception on row 0; first error: MIXED_DML_OPERATION, DML
operation on setup object is not permitted after you have updated a
non-setup object (or vice versa): CollaborationGroupMember, original
object: User: []
22:29:46.426
(426685000)|FATAL_ERROR|System.DmlException: Insert failed. First
exception on row 0; first error: MIXED_DML_OPERATION, DML operation on
setup object is not permitted after you have updated a non-setup object
(or vice versa): CollaborationGroupMember, original object: User: []

 

 

 

trigger User_trigger on User (after insert, before insert, after update, before update) {
    if ( Trigger.isInsert ) {    
        if ( Trigger.isAfter ) {
            List<CollaborationGroupMember> cgm = new List<CollaborationGroupMember>();              
            Id cgID = [ Select Id 
                      FROM CollaborationGroup 
                      WHERE Name = 'Everyone' LIMIT 1 ].ID;
System.debug('zzz: ' + cgID);    
            for ( user u: Trigger.new ) {
                cgm.add(new CollaborationGroupMember (CollaborationGroupId = cgID, MemberId = u.id));    
            }    
            insert cgm;          
        }
    }
}

 



This seems like a layup but cant figure out the syntax.

Since I cant use a formula field to reference cross-objects on standard objects (we like the case to be related to the opportunity) I need to populate two fields that I will use in a simple mail template.

How do i reference the value that is in case field Order_Number__c?

trigger addOppFields on Case (before insert) {
Case mycase=trigger.new[0];
Opportunity opp=[select ID,Webpartner__c from Opportunity where name = :mycase.Order_Number__c];
mycase.XMWebPartner__c=opp.Webpartner__c;
mycase.Merge_OpportunityID__c=opp.ID;

 

Hi,

 

Would it be possible to retrieve the criteria that triggers a workflow rule from within an Apex Class?  I'm wanting to display a string similar to what you see on the WF pages on a VF page:

 

(Plan Process: Plan Stage Name equals Implementation) and (Plan Process: 1st Payroll Upload Date not equal to null)

 




 

 

When JSON support was added in APEX, I was one of those guys who jumped up and down. Started using heavily for one of my integration project and everything was fine and dandy for couple week. Since yesterday, I have been noticing some weired behavior. The first time I noticed it, I thought it was one of those APEX issues I love to call "APEX weirdness" and hoped that it will fix itself (READ: getting fixed without us knowing). That hasn't happened. :(

 

Here is the issue. 

 

My JSON parsing code looks like this:

class SomeApexWrapper {

public static SomeApexWrapper getInstance(String jsonString)

JSONParser parser = JSON.createParser(jsonString);       

SomeApexWrapper w = (SomeApexWrapper) parser.readValueAs(SomeApexWrapper.class);

}

}

 

This code was working fine until two days ago. It stops working If I change any class that uses this class to parse json string. The error I get is "[Source: java.io.StringReader@21363a13; line: 1, column: 1] Don't know the type of the Apex object to deserialize"

 

Just saving the SomeApexWrapper  class again fixes the issue. 

 

Has anyone had/having this issue? Is there a permanent solution for this?

  • November 07, 2011
  • Like
  • 0