• Hermes Yan 11
  • 10 Points
  • Member since 2014

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
  • 10
Here i was getting Contact object Custom fields.If suppose one custom field is not there in below comparing object(Person object).How to avoid this custom fields and same fields how to update?
  for (Schema.SObjectField objField: Schema.getGlobalDescribe().get('Contact').getDescribe().fields.getMap().values()) {
                DescribeFieldResult fr = objField.getDescribe();
                if (fr.isUpdateable()) //isCreateable())
                    if (fr.getName().endsWith('__c')) {
                        String str = fr.getName();
                        String contactcustomFields = str.replaceAll('__c', '__pc');
                        pAccount.put(contactcustomFields, Ocontact.get(str));
                        //update pAccount;
                        System.debug(pAccount.put(contactcustomFields, Ocontact.get(str)));

Help me.....
I want in my test trigger to update an opportunity.
How can  I get the Opportunity.id that I have just inserted instead of taking the opportunity.name?
private class TestFireApproval_Trigger {

    private static testMethod void triggersTestFireApprovalAFEA(){
        Profile p = [select id from profile where name='Standard User'];
        User u = new User(alias = 'standt', email='standarduser4@testorg.com',emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
        localesidkey='en_US', profileid = p.Id, timezonesidkey='America/Los_Angeles', username='TESTUSER23@testorg.com');
        System.runAs(u) {  

//Create a new Opportunity for AFEA

        Opportunity Op = new Opportunity();

 // Fill in mandatory fields       
        Op.stageName ='Idea Action';
        Op.CurrencyIsoCode ='EUR';
        Op.Accountid ='00120000003XRRY';//'Amcor Ltd';
        Op.Business_group__c = 'Amcor Flexibles Europe & Americas';
        Op.Business_Unit__c ='FAME and extrusion';
        Op.Division__c ='AF Cambe';
        Op.Manufacturing_plant__c ='Cambe';
        Op.Step_change__c ='N/A';
        Op.industry__c ='Capsules';
        Op.Sub_Segment__c ='Capsules';     
        Op.Type = 'Volume Change';
        Op.Detailed_Action_Type__c = 'New Amcor Product Innovation';
        Op.Action_Risk__c ='Low';
        Op.budgeted_Action__c ='No';
        Op.Value_Plus_Site_Review__c = 'No';
        Op.ongoing__c ='Yes';
        Op.Customer_Value__c ='No';
        Op.CloseDate = system.today();        
        Op.Unadj_Expected_Annual_Impact__c = 30000;
        Op.Expected_Implementation_Date__c = system.today();
        Op.Expected_Impact_Date__c = system.today();
        Op.Expected_PM_of_New_Volume__c =30;
        Op.Expected_Units_Annually__c =100000;
        Op.Unit_of_Measure__c ='MSI';
        Op.Expected_Sales_Revenue__c =500000;
        Op.name ='TestFireApproval1'+ system.now();
        Op.Actual_Implementation_Date__c = system.today();
            insert Op; 

        catch (System.DmlException e){
            System.debug('we caught a dml exception: ' + e.getDmlMessage(0));  
           // String OpId1;
          //  OpId1 = Op.Id; 

//--> Select the record        
        Opportunity B1 = [Select Id,
                           from Opportunity 
                            where name ='TestFireApproval1'];
                            //--->Where Id =  OpId1 ;
            // ----->How to find the Id of Opportunity above?? 

            update B1;

Hi All,

I'm working on some test code for a trigger that flags a check box is the owner's user role and the invitee user role are part of a list defined in a custom setting. The trigger works as expected, however, when testing the trigger, I am not getting the isGroupEvent flag to populate. I've found several posts around this issue, but the solutions posted have not worked for me. Below is the code, any suggestions would be VERY appreciated.
private class testEventUpdateTrigger {
    private testMethod static void testEventTrigger(){
        //find users with appropriate roles to generate joint meeting flag
        User BHFAUser = [SELECT id, UserRoleId, UserRole.Name FROM User WHERE UserRole.Name = 'Financial Advisor BHFA - Arizona FA' LIMIT 1];
        User preferredUser = [SELECT id, UserRoleId, UserRole.Name FROM User WHERE UserRole.Name = 'Preferred - AZ Premier Bankers' LIMIT 1];
        //test 1 - insert an event & verify that the joint meeting flag was set to false.
            Event e1 = new Event(Subject='Test', StartDateTime = date.today(), DurationInMinutes = 60);
            insert e1;
            //Add an Event Relation Record
            EventRelation er1 = new EventRelation(EventId = e1.id, RelationId = preferredUser.id, IsInvitee=true,
            insert er1;
            e1.Description = 'invited new user';
            update e1;

            system.debug('is group event flag>>>'+e1.IsGroupEvent);
            //this assert is failing


Hello- I'm hoping for some help with a visualforce page.  I can't seem to find the answers in the documentation. 

What I need to do is diplay a specific subset of cases on a public visualforce page.  I need to be able to include the comments as well.  I can successfully display cases but can't quite get it to the point where it only displays the ones I need. (specific record type and 2 types)

For some reason the code (as shown at the bottom) shows right across the bottom of the screen and I just can't figure out how to add the comments in a column too. I've tried creating a custom controller, but my apex fell short of success. 

<apex:page id="GraniteChangeLog2" standardController="Case" recordSetvar="cases" sidebar="false" showHeader="false" standardStylesheets="true">
 <body style="background-image:url('{!$Resource.Logo}');" />
    <apex:define name="head">
        <title>Granite State College-Change Log v2</title>
    <apex:define name="content">
        <apex:variable var="width" value="850"/>
        <apex:variable var="border" value="0"/>
        <apex:variable var="cellspacing" value="0"/>
        <apex:variable var="cellpadding" value="5"/>
 <apex:form >  

    <apex:pageBlock >
    <b><h1>Change Management Cases</h1></b>
        <apex:pageBlockTable value="{!cases}" var="c">    
            <apex:column value="{!c.casenumber}"/>
            <apex:column value="{!c.CreatedDate}"/>
            <apex:column value="{!c.status}"/>
            <apex:column value="{!c.subject}"/>
            <apex:column value="{!c.type}"/>
            <apex:column value="{!c.BusinessCase__c}"/>
            <apex:column value="{!c.RiskAssesment__c}"/>
            <apex:column value="{!c.RollbackPlan__c}"/>
            <apex:column value="{!c.TestPlan__c}"/>
            <apex:column value="{!c.IsClosed}"/>

  public class retrieveCase {

        public List getCases() {
        return [SELECT status, subject FROM Case
                WHERE RecordTypeID='012M0000000D62J' AND status != 'Closed' limit 5];



Thank you.
I have the test class below that only has 72% code coverage and I can't seem to increase it anymore. My trigger fires to make all Contacts related to an Account inactive, when a Account has been made inactive using a checkbox (this part seems to be covered). When the checkbox is unchecked then it reserves and makes all Contacts active (this part is not covered in bold below). I have tried various ways i.e. updating the Account, inserting a Contact with the inactive flag equals true with the latest version below. but still doesn't get past 72%.

Test Class

private class TestUpdateContactToActiveOrInactive {

static testMethod void UpdateContactToActiveOrInactive() {
          Account acc = new Account();
          list<RecordType> rt = [SELECT Id FROM RecordType WHERE Name = 'Customer' and SobjectType='Account'];
          acc.Name = 'test acct';
          acc.Industry = 'Retail';
          try {
              insert acc;
          } catch (DmlException e) {}
          Contact c = new Contact();
          c.AccountId = acc.id;
          c.LastName='test cont';
          c.MobilePhone= '(0)00 0000 0000';
           try {
              insert c;
          } catch (DmlException e) {}
          acc.Inactive__c = True;
          try {
          Update acc;         
          } catch (DmlException e) {}    
          Account acc1 = new Account();
          list<RecordType> rt1 = [SELECT Id FROM RecordType WHERE Name = 'Customer' and SobjectType='Account'];
          acc1.Name = 'test acct1';
          acc1.Industry = 'Retail';
          acc1.Inactive__c = True;
          try {
              insert acc1;
          } catch (DmlException e) {}    
          Contact c1 = new Contact();
          c1.AccountId = acc1.id;
          c1.LastName='test cont1';
          c1.MobilePhone= '(0)00 0000 0000';
          c1.Inactive_Contact__c = True;
           try {
              insert c1;
          } catch (DmlException e) {}         
          acc.Inactive__c = False;
          try {
          Update acc1;         
          } catch (DmlException e) {}           

JSONParser parser = JSON.createParser(res.getbody());
        while(parser.nextToken() != null){
        if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getCurrentName() == 'originalTeamId')){
               String returnteam = parser.getText();
    if(returnteam != null){
        teams[0].OldTeamId__c = returnteam;

Per the documentation (http://www.salesforce.com/us/developer/docs/dbcom_apex230/Content/apex_methods_system_jsonparser.htm), the getText() method "Returns the textual representation of the current token or null if there's no current token. No current token exists, and therefore this method returns null, if nextToken has not been called yet for the first time or if the parser has reached the end of the input stream."

In my debug above, getCurrentToken() returns a value, and nextToken() is called in the while loop. Why is getText() null in the debug?

Please suggest !!!

Posting this in order to help others who, months from now, might Google "OP_WITH_INVALID_USER_TYPE_EXCEPTION" and find this explanation.


We wrote an Apex trigger on the User object, to insert a custom object record anytime a user updates their Chatter status.  This was done to fulfill a client's requirement to audit all Chatter activity.


The trigger worked fine, until one day the client signed up some Chatter Free users.  When such a user tried to update their status, they got a pop-up with an OP_WITH_INVALID_USER_TYPE_EXCEPTION error.


We scratched our collective heads for awhile.  After all, Apex triggers run in "system mode," right?  That is supposed to mean that "object and field-level permissions of the current user are ignored."  And yet this trigger seemed like it was running in "user mode," enforcing restrictions based on who the current user was.


The root cause turned out to be that a Chatter Free user cannot be the owner of a custom object record, and SFDC by default sets the current user as a new record's first owner.  We discovered this when we realized, via experiment, that Apex triggers fired as the result of actions by Chatter Free users could definitely update an existing record, but were having problems creating records.


So the simple solution was to explicitly set the owner of the new record to some fully-licensed user prior to inserting it.