• 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.
  • September 08, 2014
  • Like
  • 0
Hello all, 
   Everytime we refresh a sanbbox, there are many little things that need to be done before we consider it "Ready" for development.  One of those things is to set the Email Deliverability settings to "All Email."  I have a wrote a script that automates all of the other little things and the last piece is to change the email deliverability settings.  I am not sure if that setting is available via the API and wanted to check to see if someone can either slap my hand for trying or point me in the right direction.

So just to recap, I want to set the  Email Deliverability Settings (http://help.salesforce.com/apex/HTViewHelpDoc?id=emailadmin_deliverability.htm) using Apex via an anonymous block in the dev console.  

     Currently we have a manual process where a SFDC Admin takes an exported file from Active Directory and upserts that into Salesforce.
This happens daily.  We would like to automate this process.  I have heard of solutions where people have used the free version of Jitterbit to do this and was curious if anyone here could enlighten me in this area.  Possible alternatives are also welcome.  

Thanks, 
Hi everyone.

Not sure if I am in the right place(New UI look is really messing with me) but I have an chatter related trigger question.  

I was handed some requirements to write a trigger that would do the following:

Anytime a chatter post is made on a CASE that contains the string "#Outage" 
the trigger needs to automatically force all members of a specific chatter group to follow the case record that the post was made in

I havent had to write any code relating to chatter so I am not really sure how this would work.  

The concept seems really easy, would the new TOPIC TRIGGER feature work for this?



I'm not sure how to write a test class for a VF page and custom controller.  

 

 

HERE IS THE CONTROLLER

 

public class UploadContentController 
{
    public ContentVersion contentToUpload {get;set;}
    public ContentVersion contentToUpload1 {get;set;}
    Id memberId;
    public Blob fileContent {get;set;}
    public UploadContentController(ApexPages.StandardController controller) 
    {
        memberId = controller.getId();
        contentToUpload = new ContentVersion();
        contentToUpload1  = new ContentVersion();
    }
    public PageReference uploadContents() 
    {
        List<ContentWorkSpace> CWList = [SELECT Id, Name From ContentWorkspace WHERE Name = 'Contract Documents'];
        contentToUpload.VersionData = fileContent;
        insert contentToUpload;
      
        contentToUpload = [SELECT ContentDocumentId,ContractDocumentType__c FROM ContentVersion WHERE Id = :contentToUpload.Id];
        ContentWorkspaceDoc cwd = new ContentWorkspaceDoc();
        cwd.ContentDocumentId = contentToUpload.ContentDocumentId;
        cwd.ContentWorkspaceId = CWList.get(0).Id;
        insert cwd;
        List<Contract> con=[select id,accountid from contract where id=:memberId limit 1];
        contentToUpload.ContractDocumentType__c=contentToUpload1.ContractDocumentType__c;
        contentToUpload.RelatedAccount__c=con[0].accountid;
        contentToUpload.RelatedContract__c=con[0].id;
        update contentToUpload;
        PageReference pg = new PageReference('/' + memberId);
        pg.setRedirect(true);
        return pg;
    }
}

 

 

HERE IS THE VF PAGE

 

<apex:page standardController="Contract" extensions="UploadContentController">
<apex:sectionHeader title="Upload to Contract Library" subtitle="Upload Approved Contracts only."/>

<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection title="Upload a File">
        
            <apex:panelGrid columns="2">
                Select File :
                <apex:inputFile fileName="{!contentToUpload.PathOnClient}" value="{!fileContent}"/>
           </apex:panelGrid>
           <apex:panelGrid columns="2">
           Contract Document Type:
           <apex:inputField id="pick" value="{!contentToUpload1.ContractDocumentType__c}"/>
           </apex:panelGrid>

        </apex:pageBlockSection>
        <apex:pageBlockButtons location="bottom">
            <apex:commandButton value="Upload" action="{!uploadContents}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

I can write tests for triggers and such, but I am not too savvy on VF.

 

Any help would be appreciated.

 

Thanks, 

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

 

I ALWAYS GIVE KUDOS AND MARK SOLUTIONS AS SUCH

 

Hello all.

 

  I am having a very tough time trying to deactivate some triggers in production.  Details below:

 

We need to do an update on about 85000 case records.  I do not want triggers firing.  I created a changeset containing the deactivated versions of all case triggers.  When I click validate on the changeset, it fails because it says the code coverage is too low.  

 

So I assume that when a trigger is deactivated, it's code coverage no longer counts toward the org wide coverage.  Is there a way to force a deactivation of the triggers despite the coverage dropping below 75% for the org?

 

To me this seems like it would be a common issue, but I can't quite find any posts or resources on it.  

 

Any help would be greatly appreciated.  

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, 

 

 

My org frequently has many users working on the same cases.  So a lot of times one user has a case pulled up in edit mode, while another user pulls up the case and edits and saves it.  So when the first user tries to save the case, all changes they have made are lost and they get an error message saying the case was edited by another user during their edit session.  

 

I see many Salesforce Ideas on this same topic, but nothing has been done.  

 

Does anyone know of a way to easily code some sort of alert that will notify the first user that the record has been edited?  Or at least a way of keeping the changes the first user made to the recor?

 

 

 

 

 

   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 a custom field on the case object.  That custom field is named Last_Activity_Date__c.  It has a data type of Date/Time.

 

The Last_Activity_Date__c field is updated by a cross object field update.  The cross object field update is triggered from a

 

workflow rule on the caseComment object.  The workflow rule with field update is working correclty.  However, as a workflow

 

rule can only be triggered on insert or update, I would need a way to retro-actively go back and modify the Last_Activity_Date__c

 

on cases that are no longer having caseComment updates.  

 

 

 

 

So my thinking is that I could do a SOQL query and make a list of all cases where the Last_Activity_Date__c is less than the

lastModifiedDate on the most recent related case comment.  The problem is that I can't seem to create the query.  

 

Any help would be greatly appreciated!

 

 

 

 

I ALWAYS GIVE KUDOS AND IF A SOLUTION IS FOUND, I ALWAYS MARK IT AS SUCH.

 

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, 

  • September 27, 2013
  • Like
  • 0

 

 

I am trying to write a trigger and keep getting errors for too many soql queries.  Rather than post the code I decided to just list my requirements and see if anyone has some suggestions.  

 

First, a little background info:

 

1. The object is CASE

2. Custom lookup field on Case named Parent__c

     That field is a lookup to the case object.  (Will link multiple cases to one case).

3. Custom NUMBER field on Case named Iteration__c

     This field is meant to hold the number of cases that are related to it.  

 

 

The requirements:

 

For every case that is updated or inserted and has a value in Parent__c

I need the trigger to find all cases that have the same value in that field and update the the 

Iteration__c field with the number of total cases with that same value in Parent__c.  

The parent record will also need its iteration__c field updated with the same number.

 

 

The logic seems pretty straight forward, but when I try to Bulkify the trigger, I keep running into limit 

issues.  

 

Any suggestions would be greatly appreciated.

 

  • September 11, 2013
  • Like
  • 0

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.

  • September 03, 2013
  • Like
  • 0

Good morning, 

 

      So my question may be very basic in nature for a seasoned developer but I am not quite there yet.

 

I have a Case trigger that sends an sms page to the new owner of the case.  Looking at the order of execution, assignment rules will fire after a trigger so, to me, that would mean that the sms page would get sent to the wrong person in most cases.  Below is a shorthand flow of events as I see them:

 

 

New case is created

 

Triggers fire and send an sms page to the owner of the case(which will be the person who just created it)

assignemnt rules fire and change the owner to the intended owner.  

 

Case is commited to the DB

 

 

the new owner has not recieved the SMS

 

 

Any insight would be greatly appreciated.  

 

 

Thanks, 

 

 

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.  

Hello all, 
   Everytime we refresh a sanbbox, there are many little things that need to be done before we consider it "Ready" for development.  One of those things is to set the Email Deliverability settings to "All Email."  I have a wrote a script that automates all of the other little things and the last piece is to change the email deliverability settings.  I am not sure if that setting is available via the API and wanted to check to see if someone can either slap my hand for trying or point me in the right direction.

So just to recap, I want to set the  Email Deliverability Settings (http://help.salesforce.com/apex/HTViewHelpDoc?id=emailadmin_deliverability.htm) using Apex via an anonymous block in the dev console.  

     Currently we have a manual process where a SFDC Admin takes an exported file from Active Directory and upserts that into Salesforce.
This happens daily.  We would like to automate this process.  I have heard of solutions where people have used the free version of Jitterbit to do this and was curious if anyone here could enlighten me in this area.  Possible alternatives are also welcome.  

Thanks, 
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.
  • September 08, 2014
  • Like
  • 0

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, 

  • September 27, 2013
  • Like
  • 0

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.

  • September 03, 2013
  • Like
  • 0

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!

 

 

If I "use strict" in my code, will Visualforce Remoting blow up? Has anyone tried testing this to see what will happen? Are there any gotchas I should be made aware of?

 

I tried something like this:

 

"use strict";
(function(window,undefined) {
  var addEvent = function(...) { ... };
  var callbackHandler = function(...) { ... };

  var onWindowLoad = function(...) {
     Visualforce.remoting.Manager.invokeAction(
       "{!$RemoteAction.myClass.myMethod}",
       callbackHandler);
  };
  addEvent(window,"load",onWindowLoad,true);
})(window);

Where ... is not relevant. It runs, and the data comes back just fine, but I wanted some feedback on if there were any known issues where it might be possible that remoting fails entirely because of strict mode, perhaps even outside the realm of being able to use exception handling. Or, should I just forego strict mode and leave that for another day?