• Rebecca Vanderslice
  • NEWBIE
  • 10 Points
  • Member since 2014
  • Application Administrator
  • CareerBuilder


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
I want to show the results of a SOQL query to a user including those records that are not owned by the user.  But with the current user owned records appearing first in the list.  Then within the group of records owned by the current user, order by a value field.

Is there a creative way to put a temp column into the SOQL so that i can order by 1 or 2 first and then by value? Here's what we are doing currently but i want to try to eliminate have to create 2 queries.
 
private List<Site_Account__c> createSiteAccountsList() {
List<Site_Account__c> siteAccountsOwnedByLoggedInUser = 
[SELECT TotalValue__c, Owner.Name, OwnerId, Name, Contact_Id__r.Name, Contact_Id__c, AccountDID__c, Currency__c, AccountType__c
  FROM Site_Account__c 
  WHERE Account_Id__c =: selectedAccountId AND OwnerId =: UserInfo.getUserId()
  ORDER BY TotalValue__c DESC LIMIT 1000];

 List<Site_Account__c> siteAccountsNotOwnedByLoggedInUser = 
[SELECT TotalValue__c, Owner.Name, OwnerId, Name, Contact_Id__r.Name, Contact_Id__c, AccountDID__c, Currency__c, AccountType__c
   FROM Site_Account__c 
   WHERE Account_Id__c =: selectedAccountId AND OwnerId !=: UserInfo.getUserId()
   ORDER BY OwnerId, TotalValue__c DESC LIMIT 1000];

        List<Site_Account__c> siteAccounts = new List<Site_Account__c>();
       
        siteAccounts.addAll(siteAccountsOwnedByLoggedInUser);
        siteAccounts.addAll(siteAccountsNotOwnedByLoggedInUser);
        return siteAccounts;
    }
Any creative ideas are welcome!
 
I want to show the results of a SOQL query to a user including those records that are not owned by the user.  But with the current user owned records appearing first in the list.  Then within the group of records owned by the current user, order by a value field.

Is there a creative way to put a temp column into the SOQL so that i can order by 1 or 2 first and then by value? Here's what we are doing currently but i want to try to eliminate have to create 2 queries.
 
private List<Site_Account__c> createSiteAccountsList() {
List<Site_Account__c> siteAccountsOwnedByLoggedInUser = 
[SELECT TotalValue__c, Owner.Name, OwnerId, Name, Contact_Id__r.Name, Contact_Id__c, AccountDID__c, Currency__c, AccountType__c
  FROM Site_Account__c 
  WHERE Account_Id__c =: selectedAccountId AND OwnerId =: UserInfo.getUserId()
  ORDER BY TotalValue__c DESC LIMIT 1000];

 List<Site_Account__c> siteAccountsNotOwnedByLoggedInUser = 
[SELECT TotalValue__c, Owner.Name, OwnerId, Name, Contact_Id__r.Name, Contact_Id__c, AccountDID__c, Currency__c, AccountType__c
   FROM Site_Account__c 
   WHERE Account_Id__c =: selectedAccountId AND OwnerId !=: UserInfo.getUserId()
   ORDER BY OwnerId, TotalValue__c DESC LIMIT 1000];

        List<Site_Account__c> siteAccounts = new List<Site_Account__c>();
       
        siteAccounts.addAll(siteAccountsOwnedByLoggedInUser);
        siteAccounts.addAll(siteAccountsNotOwnedByLoggedInUser);
        return siteAccounts;
    }
Any creative ideas are welcome!
 

I made my first Visualforce page which is a Visualforce Email Template. I'm having a problem writing a test class with 100% coverage. Currently, I'm at 50% and it's only got to cover four lines. I'm not sure what I'm doing wrong. Here's the test class. I added the create account, opportunity and opportunity line item but it didn't change my code coverage.

@isTest
private class TestGetBloomerProductsController {

      public static testMethod void myUnitTest() {
      	Account a = new Account(Name='Testing Account', 
	    		Industry='Nonprofit', 
	    		Type = 'Client');
	    insert a;
	    
      	Opportunity oppty = new Opportunity(
      		name='wendy test',
      		Type = 'New Client',
      		StageName = 'Close/Won',
      		Reason_Won_Lost__c='Design',
      		CloseDate=System.today(),
      		AccountId=a.id);
      	insert oppty;
      	
      	OpportunityLineItem oli = new OpportunityLineItem(
      		UnitPrice = 0.00,
      		Quantity = 1,
      		PricebookEntryId = [select Id From PricebookEntry Where Name = 'Bloomerang 1,001-5,000 Records' LIMIT 1].id,
      		OpportunityId = oppty.Id);
      	
        PageReference pageRef = Page.success;
        Test.setCurrentPage(pageRef);
        getBloomerProductsController controller = new getBloomerProductsController();
    }
}

 Here's the controller class:  (only lines 4 and 7 are covered and I need to cover 10 and 11)

public class getBloomerProductsController {
 2 	  
 3 	   //a list to hold the bloomerproducts
 4 	   public List<OpportunityLineItem> BloomerangProducts {get; set;}
 5 	  
 6 	   // get the oppty id
 7 	   public id OpptyID {
 8 	   get;
 9 	   set {
 10 	   OpptyID = value;
 11 	   BloomerangProducts = [Select PricebookEntry.Name From OpportunityLineItem WHERE HasBloomerang__c = true and OpportunityID =: OpptyID];
 12 	   }
 13 	   }
 14 	  }

 

 

 Here's the component:

<apex:component id="getBloomerProducts" controller="getBloomerProductsController" access="global">	
	<apex:attribute name="OpportunityID" description="This is the Opportunity Id." type="Id" assignTo="{!OpptyID}"/> 	
 	<apex:repeat value="{!BloomerangProducts}" var="blp" >
 		<br>
	    	<apex:outputText value="Product: "/><apex:outputField value="{!blp.PricebookEntry.Name}"/>
	    </br>	                    
	</apex:repeat>	
</apex:component>

 

 

I created a trigger to update a field in Case to either New or Read based on attached emailmessages status.

 

if there are any new emails attached to case, the case email status should be "new".

 

If there are no New emails the case email status should be "Read".

 

everything is working fine except, the trigger is not getting fired when they open the new email to read, the emailmessage status is getting updated from New to Read, but the trigger is not getting fired to update the case email status.

 

please check the below code.

trigger CaseEmailStatusUpdate on EmailMessage (after insert, after update) {

	ID caseId;
	list<EmailMessage> emails = new list<EmailMessage>();
	set<string> status =  new set<String>();
	Case c = new Case();

	
	for( EmailMessage e : trigger.new){
	
		caseId = e.ParentId;
	}
	
	emails = [ SELECT Id, ParentId, Status, Subject FROM EmailMessage where parentId = :caseId];
	c = [ Select Id, Case_Email_Status__c From Case where Id = :caseId];
	
	for( EmailMessage e : emails){
			
			status.add(e.Status); 
		
	}
	
	if(status.size() > 0 && status.Contains('0')){
	
		c.Case_Email_Status__c = 'New';
		
	}else if (status.size() > 0 && !status.Contains('0')){
	
		c.Case_Email_Status__c = 'Read';
		
	}
	
	update c;
	
	
}

 

  • March 27, 2013
  • Like
  • 0

Hi All

 

I have written a trigger as below

trigger testChangeOwnerTrigger on Case (before insert) { for(Case newCase : Trigger.New){ newCase.OwnerId ='005R0000000IufqIAC'; } }

 

Here the 'created use'r and 'new owner user' has the same profile.

 

This trigger is working correctly when I create case with System Administrator profile user, but when create case with other profile user then it throw an error "Insufficient Privileges You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary. Click here to return to the previous page "

 

I checked the profile & it has all data modification permissions.

 

Any idea?

 

Thanks