• Rstrunk
  • NEWBIE
  • 55 Points
  • Member since 2013

  • Chatter
    Feed
  • 2
    Best Answers
  • 2
    Likes Received
  • 1
    Likes Given
  • 33
    Questions
  • 23
    Replies
I have a listButton that is calling a visualforce page.  

The visualforce page is using a standard Controller for CHILD_OBJ.  The page attribute RECORDSETVAR is set.  

The idea is that a user goes PARENT_OBJ and goes down to the related list and checks boxes for certain records, then clicks the custom listButton that launches my VF page.  

On this page, there is another button that will open another VF page that allows the user to modify certain aspects of the record.  

Once this edit is made, I need to ability to go BACK to the VF page that contains the list, with a now updated record from the edits that were just made.

inline editing is not an option here.

Hello All, 

   I'll start off by saying I'm not the best coder in the world(as you will see below :-p ) but I have written triggers and test classes in the past.  I wrote this trigger below and for the life of me, I can't write a test class that gets more than 25% code coverage.  I don't know why.  In previous attempts at the test class I feel like I coded for the appropriate scenarios, yet some of the lines still remain red.  So I wanted to come here and just post the trigger to see someone elses take on a test class for it.  Maybe I have been doing things really wrong.  

 

Here is the trigger:

 

trigger standardChange on Case(before insert, before update){

  if(trigger.isBefore && trigger.isInsert){
    if(StandardChange_Helper.ranFlag == false){
      set<ID> ParentCases = new Set<ID>();
      list<Case> SoqlParentResults = new list<case>();

      for(case tmpCase:trigger.new){
        if(tmpCase.Standard_Change_Related_Case__c != null && tmpCase.type == 'Change'){
          ParentCases.add(tmpCase.Standard_Change_Related_Case__c);
        }
      }
      SoqlParentResults = [Select id, Standard_Change_Related_Case__c FROM Case c WHERE ((c.ID IN:ParentCases) or (c.Standard_Change_Related_Case__c IN:ParentCases))];

      For(Integer i = 0; i < trigger.new.size(); i++){
        if(trigger.new[i].type == 'Change' && trigger.new[i].Standard_Change_Related_Case__c != null){
          Integer subCaseCount = 0;
          for(Integer counter = 0; counter < soqlParentResults.size(); counter++){
            if(trigger.new[i].Standard_Change_Related_Case__c == soqlParentResults.get(counter).id ){
              subCaseCount += 1;
            }
            else if(soqlParentResults.get(counter).Standard_Change_Related_Case__c == trigger.new[i].Standard_Change_Related_Case__c){
              subCaseCount += 1;
            }
          }
          trigger.new[i].Standard_Change_Request_Iteration__c = (subCaseCount + 1);
        }
      }
      StandardChange_Helper.ranFlag = true;
    }
  }
  else if(trigger.isBefore && trigger.isupdate){
    if(StandardChange_Helper.ranFlag == false){
      set<ID> ParentCases = new set<ID>();
      list<Case> SoqlParentResults = new list<case>();

      for(case tmpCase:trigger.new){
        if(tmpCase.Standard_Change_Related_Case__c != null && tmpCase.type == 'Change'){
          ParentCases.add(tmpCase.Standard_Change_Related_Case__c);
        }
      }

      SoqlParentResults = [Select id, Standard_Change_Related_Case__c FROM Case c WHERE ((c.ID IN:ParentCases) or (c.Standard_Change_Related_Case__r.id IN:ParentCases))];    

      For(Integer i = 0; i < trigger.new.size(); i++){
        if(trigger.new[i].type == 'Change'){
          //if parent case was just deleted
          if(trigger.new[i].Standard_Change_Related_Case__c == null && trigger.old[i].Standard_Change_Related_Case__c != null){               
            trigger.new[i].Standard_Change_Request_Iteration__c = 0;
          }
          //there is a parent case and there was not before
          else if(trigger.new[i].Standard_Change_Related_Case__c != null && trigger.old[i].Standard_Change_Related_Case__c == null){              
            Integer subCaseCount = 0;
            for(Integer counter = 0; counter < soqlParentResults.size(); counter++){
              if(trigger.new[i].Standard_Change_Related_Case__c == soqlParentResults.get(counter).id ){
                system.debug('before subcasecount = :' + subCaseCount);
                subCaseCount += 1;
                system.debug('after subcasecount = :' + subCaseCount);
              }
              else if(soqlParentResults.get(counter).Standard_Change_Related_Case__c == trigger.new[i].Standard_Change_Related_Case__c){
                subCaseCount += 1;
              }
            }               
            trigger.new[i].Standard_Change_Request_Iteration__c = subCaseCount + 1;             
          }
          //old parent field had a value and new parent field also has a value
          else if(trigger.new[i].Standard_Change_Related_Case__c != null && trigger.old[i].Standard_Change_Related_Case__c != null){
            //parent has not changed
            if(trigger.new[i].Standard_Change_Related_Case__c == trigger.old[i].Standard_Change_Related_Case__c){
              /*  COMMENTED OUT TO KEEP THE ITERATION NUMBER THE SAME AS WHAT IT WAS INITIALLY SET TO.  
              THIS WILL PREVENT THE ITERATION NUMBER FROM CHANGING IF THE STANDARD CHANGE PARENT DOES
              NOT CHANGE AND ADDITTIONAL CASES HAVE BEEN ADDED AS SUBCASES.  

              Integer subCaseCount = 0;
              for(Integer counter = 0; counter < soqlParentResults.size(); counter++){
                if(trigger.new[i].Standard_Change_Related_Case__c == soqlParentResults[counter].id ){
                  subCaseCount += 1;
                }
              }
              trigger.new[i].Standard_Change_Request_Iteration__c = subCaseCount;
              */
            }
            //When parent case has been changed to a new case
            else{
              Integer subCaseCount = 0;
              for(Integer counter = 0; counter < soqlParentResults.size(); counter++){
                if(trigger.new[i].Standard_Change_Related_Case__c == soqlParentResults[counter].id ){
                  subCaseCount +=1;
                }
                else if(soqlParentResults.get(counter).Standard_Change_Related_Case__c == trigger.new[i].Standard_Change_Related_Case__c){
                  subCaseCount += 1;
                }
              }
              trigger.new[i].Standard_Change_Request_Iteration__c = subCaseCount + 1;
            }
          }
        }
      }
      StandardChange_Helper.ranFlag = true;
    }
  }
}

 

 If anyone decides to give it a shot I really appreciate your time and effort!

 

Thanks, 

 

Robert 

Certified Adminstrator

Certified Developer

 

Hi all, 

   From time to time I see people post their triggers and test classes in order to figure out why it isn't behaving as expected.  Looks like it's my turn :-)

 

Here is my trigger:

trigger UpdateLastVisitDate on Task (before insert) {
    system.debug('######################  ENTERING TASK TRIGGER  ################################');
    list<id> eventRelatedIds = new list<id>();
    list<account> relAccounts = new list<account>();
    list<contact> relContacts = new list<contact>();
    date n = date.today();
    
    system.debug('######################  TRIGGER.NEW :'+TRIGGER.NEW+'  ################################');
    
    for(integer i =0; i < trigger.new.size(); i++){
        SYSTEM.DEBUG('TRIGGER.NEW.TYPE : ' + TRIGGER.NEW[I].TYPE);
        if(trigger.new[i].type == 'Visit-BD'){
            SYSTEM.DEBUG('TRIGGER.NEW.WHOID : ' + TRIGGER.NEW[I].WHOID);
            if(trigger.new[i].whoId != null){
                eventRelatedIds.add(trigger.new[i].whoId);
            }
            SYSTEM.DEBUG('TRIGGER.NEW.WHATID : ' + TRIGGER.NEW[I].WHATID);
            if(trigger.new[i].whatId != null){
                eventRelatedIds.add(trigger.new[i].whatId);
            }
        }
    }
    
    SYSTEM.DEBUG('eventRelatedIds : ' + eventRelatedIds);
    if(eventRelatedIds != null && eventRelatedIds.size() > 0){
        relAccounts = [select id, Last_Visit__c from Account where id IN:eventRelatedIds];
        relContacts = [select id, Last_Visit__c from Contact where id IN:eventRelatedIds];
    }
    
    SYSTEM.DEBUG('relAccounts : ' + relAccounts);
    if(relAccounts != null && relAccounts.size() > 0){
        for(integer i = 0; i < relAccounts.size(); i++){
            relAccounts[i].last_visit__c = n;
            SYSTEM.DEBUG('relAccounts[i].last_visit__c : ' + relAccounts[i].last_visit__c);
        }
        update relAccounts;
    }
    
    SYSTEM.DEBUG('relContacts : ' + relContacts);
    if(relContacts != null && relContacts.size() > 0){
        for(integer i = 0; i < relContacts.size(); i++){
            relContacts[i].Last_Visit__c = n;
            SYSTEM.DEBUG('relContacts[i].Last_Visit__c : ' + relContacts[i].Last_Visit__c);
        }
        update relContacts;
    }
    system.debug('######################  LEAVING TASK TRIGGER  ################################');
}

 

And here is my TestClass:

@istest(SeeAllData=true)
private class TestLastVisitUpdate{
    static testmethod void createTasks(){
        integer createTask = 0;
        Account tmpAccount = new Account(Name = 'Test Account', last_Visit__c = null);
        if(tmpAccount != null){insert tmpAccount; createTask += 1;}
        Contact tmpContact = new Contact(LastName = 'Test Name', Account = tmpAccount, Speciality__c = 'N/A', last_Visit__c = null);
        if(tmpContact != null){insert tmpContact; createTask += 1;}
        
        if(createTask == 2){
            List<Task> tasks = new List<Task>();
            tasks.add(new Task(
                ActivityDate = Date.today().addDays(7),
                Subject = 'Sample Task',
                WhatId = tmpAccount.id,
                type = 'Visit-BD',
                OwnerId = UserInfo.getUserId(),
                Status='In Progress'));
                
            tasks.add(new Task(
                ActivityDate = Date.today().addDays(7),
                Subject = 'Sample Task',
                WhoId = tmpContact.Id,
                type = 'Visit-BD',
                OwnerId = UserInfo.getUserId(),
                Status='In Progress'));
            if(tasks.size() > 0 && tasks != null){
                test.starttest();
                insert tasks;
                system.debug('############### ACCOUNT INFO:' + tmpAccount + '####################');
                system.debug('############### CONTACT INFO:' + tmpContact + '####################');
                system.assertnotequals(tmpAccount.last_visit__c , null);
                system.assertnotequals(tmpContact.last_visit__c , null);
                test.stopTest();
            } 
            system.debug('############### TASK INFO:' + tasks + '####################');
        }   
        createTask = 0;
    }
}

 

I don't understand why the assertion fails.  The debug statement shows the value of the last_visit__c field is populated while inside the trigger, but when it comes back to the class the field is somehow null if that makes sense.  

 

I'm sure it is a very basic mistake I made.  Any help would be appreciated!!!

 

Thanks, 

Anyone know of any good books or resources that I can use to learn a lot about web services in general?  I have a degree in Computer Programming, and a degree in Computer Networking technologies, however, I was never introduced to web services and it seems like that is the blunt of what I will be doing in my current position.  

 

I have looked at the W3 Schools tutorials, but I would like a more comprehensive book/resource and all I have been able to find are mostly dated back in early 2000.  The latest book I found was published 6 years ago.  

 

The goal I would like to achieve is to create custom integrations from salesforce to external web services.

 

I have looked at the force.com integration pages, but to be honest a lot of the jargon and references are outside of my grasp.  

 

Any help would be greatly appreciated.  

 

Thanks, 

 

 

 

   Since apex callouts are asynchronous, can I have a trigger that will prevent a record from being saved if the return value of the callout meets a certain criteria?

 

An example being:

  When a record is being saved, the trigger calls out to a web service using the value in one of the fields on that record.  If the web service returns 0 I want the record to not be allowed to be saved.  If the record returns a 1 I want the record to be saved.  

 

Anyone have experience with matters such as this? 

 

 

       I always give kudos and if the reply is a solution, I always mark it as such.  

 

 

So a strange thing has started happening recently with @mentions for my org.  When I start to do an @mention I see a lot more names than there has been historically.  The names that showup are names of our customer portal users.  Those users do not have sharing access to the record, so if I actually click on one of the new names I will get a message that says they cannot see it.    

 

For example, in last week I could type @jun   and only one name would appear that I could select.  Now, when I type @jun I get a list of about 5 names.  

 

Any help would be appreciated.  

 

Thanks,  

 

 

I have seen that there is no straight forward way to EDIT the change owner page for cases.  I have also saw posts where people say it is possible to make a visualForce page to override it.  Can someone give me an example?  Basically I need to get rid of the "Send Notification Email" checkbox.(we have apex that sends emails).  From what I have found this is a very common problem but not too many resolutions.  

 

Any help would be greatly appreciated.  

 

 

Thanks, 

Hi everyone, 

 

    I've been playing around with an apex trigger and class that will basically create a rollup field that counts the number of subCases that are related to a ParentCase.  Since I am new to APEX I am having a tough time.  I can get the trigger to work fine when I am not trying to "Bulkify" it.  But once I started trying this thing got a little out of hand lol.  Anyway HEre is the trigger and the class and the error I am getting.  Any help would be greatly appreciated.

 

 

ERROR: 

Error:Apex trigger NAME caused an unexpected exception, contact your administrator: NAME: execution of BeforeUpdate caused by: System.StringException: Invalid id: : Trigger.NAME: line 5, column 1

 

 

 

TRIGGER

 

Trigger NAME on Case (before update){
	List<String> parentIDs = new List<ID>();

	for(Integer i = 0; i < trigger.new.size(); i++){
		if(trigger.new[i].Standard_Change_Related_Case__c != null && trigger.new[i].Standard_Change_Related_Case__c != ''){
			parentIDs.add(trigger.new[i].Standard_Change_Related_Case__c);
		}
	}
	
	if(parentIDs.size() > 0 && parentIDs.size() != null){
		testClass.findAndUpdate(parentIDs);
	}
}

 

 

CLASS

Public Class testClass{	

	public static void findAndUpdate(List<String> parentIDs){
		list <case> casesTOupdate = new list <case>();
		list <case> subCaseList = new list<case>();
		
		if (parentIDs.size() > 0 && parentIDs.size() != null){
			For(integer i = 0; i < parentIDs.size(); i++){
				if(i < 100){ //limits the number of iterations for governor limits on SOQL queries
					for(list<Case> tmpCaseList: [Select id, Standard_Change_Request_Iteration__c 
												FROM Case c 
												WHERE c.Standard_Change_Related_Case__r.id =: parentIDs.get(i)]){
												
						subCaseList.addAll(tmpCaseList);
					}
					if(subCaseList.size() > 0 && subCaseList.size() != null){
						integer recordCount = subCaseList.size() + 1;
						for(integer h = 0; h < subCaseList.size(); h++){
							subCaseList.get(h).Standard_Change_Request_Iteration__c = recordCount;
						}
						case tmpCase = [Select id, Standard_Change_Request_Iteration__c 
										FROM Case c 
										WHERE c.id =: parentIDs.get(i)];
										
						tmpCase.Standard_Change_Request_Iteration__c = recordCount;
						subCaseList.add(tmpCase);
						casesTOupdate.addAll(subCaseList);
					}
					subCaseList.clear();
				}
			}			
			update casesTOupdate;
		}
	}
}

 

 

Sorry for the bad Formatting, When I paste it over it gets all screwy.

Good morning everyone!

 

   So I encountered an issues and it seems that it would be very common, so I thought you guys might be able to help me out.  

 

I created a trigger that runs on UPDATE, however, anytime a record is inserted the update trigger fires.  I believe I know why it happens but I need to prevent it.  I believe that when a record is inserted, workflow rules with field updates cause the record to be updated thus fireing the UPDATE trigger. 

 

So my question is, what can I do to my trigger to prevent the workflow rule from making my UPDATE trigger fire on INSERT?

 

I give kudos and follow up on all posts so if you can help I will return the favor.

 

Thanks, 

 

    So I am new to apex and salesforce and I have been going through a lot of apex.  I know all you experienced devs just cringed a little lol, dont wory I am not modifying anything.  Anyway, the code I am looking at is very sloppy from a styling standpoint.  There appears to be no structured way that the coders have stuck to in order to make the code easily readible.  There is no consistant use of tabbing or even consistancy in the amount of whitespace between words or blocks.  So I have also see, and this is the point of the post, a lot of lines that run on and on. All the code in the first example is shown below EXCEPT it is all one line.  So in order to see it you would have to horizontally scroll quite a bit.    

 

BusinessHours bHr = [Select b.WednesdayStartTime, b.WednesdayEndTime, b.TuesdayStartTime, b.TuesdayEndTime, b.TimeZoneSidKey, b.ThursdayStartTime, b.ThursdayEndTime, b.SystemModstamp, b.SundayStartTime, b.SundayEndTime, b.SaturdayStartTime, b.SaturdayEndTime, b.Name, b.MondayStartTime, b.MondayEndTime, b.LastModifiedDate, b.LastModifiedById, b.IsDefault, b.IsActive, b.Id, b.FridayStartTime, b.FridayEndTime, b.CreatedDate, b.CreatedById From BusinessHours b WHERE b.IsDefault=true AND b.IsActive = true LIMIT 1];

 

My question is, can a newline be entered after the comma that separates the fields in the query? I do not have the ability to test it for myself so I wanted to turn to you guys for assistance.  

 

    So I am looking to register for an upcomming DEV - 501 course offering in my area.  I noticed that there are two online courses that become available to me once I register(they are bundled with dev501).  The online courses should be completed prior to showing up for the class.  Since the course offering has a start date that is fairly close, I was wondering how long those two online courses take.  I do not want to have to blow through them and then showup unprepaired on day 1.  

 

Any feedback would be greatly appreciated.  

 

 

      So I used an APEX clas to allow a user to create a case on an account they do not have access to.  The Class is called from a VF page.  

 

The problem I am having is that once the case is created, the users profile somehow gains View All and Modify All for every object in the org.  This profile should not have view and modify all on ANY object in the org.  Is it because the class uses without sharing?  I'll post my code below.

 

//This Class is used to get the contact record of the current logged in user for use in a visualforce page.  


public without sharing class CC_getContact {
  public Contact theContact { get; set; } // You can use theContact on your page.

  public CC_getContact(ApexPages.StandardController controller) {
    Contact[] c = [SELECT Id FROM Contact WHERE FirstName = :UserInfo.getFirstName() AND LastName = :UserInfo.getLastName() and Email = :UserInfo.getUserEmail()];
    // Make sure you select all the fields you need.
    if(!c.isEmpty()) {
      theContact = c[0];
    }
  }
}

 

 

Any insight would be greatly appreciated.  

 

    Good morning/afternoon/evening everyone.  

 

I have recently encountered an issue and have been working with the premiere support for SFDC on the matter, however, it looks like there isn't going to be a non-programmatic solution.  So I thought I drop a line in here to see if anyone has encountered and crafted a solution/workaround for my issue.  I do give Kudos and always follow up on my threads.

 

Anyway, enough time wasting, here is my issue:

 

     The service cloud implementation I am working with requires that there be a few fields on the contact object of the EMAIL data type.  One of those fields is managerEmail__c.  All contacts in this implementation are actual employees of the organization, so they obviously have managers that also have their own contact record.  So, when a manager submits an email to case, the E2C process just looks for contact records with the email address that was sent in.  Since the managers email address is listed on multiple records the created case does not have the contact information populated.  Just to recap the managers email address is listed on the managers actual contact record in the EMAIL field.  It is also listed on a lot of other contacts as the managerEmail__c field.  

 

  So in summation, I would like to know if anyone knows of a way to have email-to-case ignore custom fields and only look at the standard EMAIL field on the contact object?

 

Any help would be greatly appreciated!

 

 

I need to create a soql query that will query the AccountShare object and return any records that have related users that are not assigned to specific profiles.  The profile IDs are 00eE0000000d2WD , 00eE0000000dh09 , 00eE0000000eQAK.

 

Any thoughts on how to do this?

 

 

 

 

I am a bit of a noob so my question may be simple for someone to answer.  I do give kudos and follow up on threads for those who care about that. 

 

Basically my issue is this:

 

I have a VF page, custom tab and APEX class that is meant to allow a user to go to the tab and see a related list of cases for their contact record.  Their contact record is under an account tha tthey are not supposed to have access to so I thought having the without sharing keyword in the class would work but I am getting an error when I go to that tab as that logged in user.  Since the class operates at the system level why am I getting error messages based on the sharing settings?  Any thoughts would be appreciated.  (Oh, the code works because when I go to that tab as the admin it works as intended)

 

Below is my VF page and Class.

 

<apex:page standardController="Case" extensions="CC_getContact">
    <apex:tabpanel >
        <apex:tab label="Cases">           
                <apex:relatedList list="Cases" subject="{!theContact}"/>
                <style type="text/css">.actionColumn {display:none; visibility:hidden}</style>          
        </apex:tab>
    </apex:tabpanel>

</apex:page>

 

//This Class is used to get the contact record of the current logged in user for use in a visualforce page.  


public without sharing class CC_getContact {
  public Contact theContact { get; set; } // You can use theContact on your page.

  public CC_getContact(ApexPages.StandardController controller) {
    Contact[] c = [SELECT Id FROM Contact WHERE FirstName = :UserInfo.getFirstName() AND LastName = :UserInfo.getLastName() and Email = :UserInfo.getUserEmail()];
    // Make sure you select all the fields you need.
    if(!c.isEmpty()) {
      theContact = c[0];
    }
  }
}

 

The target profile has access to the tab and VF page.  Is there some permission issues posibly?  

 i want the functionlaity of dropdown(select list) and a button to  browse file from computer both on the same page...

Hello all, 

 

     I am trying to do what I think would be very simple but since I have no experience with APEX my attempts have been unsuccessful.  

 

I need an apex class that will act as an extension to a standard controller on a VF page.  

 

  I need the apex class to:

 

         Query the contact object to find a CONTACT RECORD that has the same first name, last name and email address as
                     the 
CURRENT LOGGED IN USER.  

         Save the contact record ID in a variable that can be accessed in the VF page. 

 

 

It seems very easy but I am a noob with apex.  

 

Someone please help!