• Chance Allred
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hello, I am fairly new and am experimenting with Apex & Visualforce.

I managed to figure out how to display a list of all the users in my org, but I can't figure out how to display a specific user.

Apex Class:
public class UserResultsController {
    
    public List<String>getListOfUsers(){
		List<string> ourUsers = new list<string>();
			
        	for(User a:[SELECT Name FROM User]){
				ourUsers.add(a.Name);
			}
        
		return ourUsers;
	}
 
}
Apex Page:
<apex:page controller="UserResultsController" >
    
   <apex:repeat value="{!ListOfUsers}" var="usl"> 
       <apex:outputText value="{!usl}"/> <br/> 
   </apex:repeat>
        
</apex:page>

Is there a way to either populate the data about a specific user using their User Id or doing a query for a specific user?

I know I can display the current logged in user data by using: {!$User.FirstName} for instance, but I want to display a specific user, not the current logged in user.

Help is greatly appreciated. 
Hello all,

I am having some trouble with an Apex Trigger test class I'm writing. I am using a developer sandbox and am getting the following error:
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: a0D6A0000015UKi: []

What I am trying to do is update a Lookup field that looks up to a Rate Sheet based on certain criteria. (Rate_Sheet__c = API Name)

I wrote the trigger and had no errors that I could see but when writing the test class it kept giving me the Insufficient Access error. Not really sure what the problem is. Under sharing settings, my org wide defaults gives public read/write access to all objects needed.

Please see the following Apex Trigger and Test Class code:
trigger UpdateRatesheetLookup on Quote (before insert, before update) {

    for (Quote quo : Trigger.new) {
       
        if (quo.TotalPrice < 3000 && quo.Buyout_Type__c == 'FMV') {
            // Sets Rate Sheet Lookup
            quo.Rate_Sheet__c = 'a0D6A0000015UKi';
            
        } else if (quo.TotalPrice < 10000 && quo.Buyout_Type__c == 'FMV') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKj';
            
        } else if (quo.TotalPrice >= 10000 && quo.Buyout_Type__c == 'FMV') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKk';
            
        } else if (quo.TotalPrice < 3000 && quo.Buyout_Type__c == 'Promo FMV') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKl';
            
        } else if (quo.TotalPrice < 10000 && quo.Buyout_Type__c == 'Promo FMV') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKm';
            
        } else if (quo.TotalPrice >= 10000 && quo.Buyout_Type__c == 'Promo FMV') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKn';
            
        } else if (quo.TotalPrice < 3000 && quo.Buyout_Type__c == '$1-out') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKo';
            
        } else if (quo.TotalPrice < 10000 && quo.Buyout_Type__c == '$1-out') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKp';
            
        } else if (quo.TotalPrice >= 10000 && quo.Buyout_Type__c == '$1-out') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKq';
            
        } else {
            quo.Rate_Sheet__c = Null;
        }
    }
}

// Problem is happening at insertion of the myQuote instance.
@isTest
private class UpdateRateSheetLookupTest {
    
    @isTest static void updateQuote() {
        
        // Create an Account & Set Required Fields
        Account myAccount = new Account();
        myAccount.Name    = 'Sample Account';
        insert myAccount;
        
        // Create an Opportunity on the Account & Set Required Fields
        Opportunity myOpportunity = new Opportunity();
        myOpportunity.Name        = 'Sample Opportunity';
        myOpportunity.CloseDate   = Date.today();
        myOpportunity.StageName   = 'Proposal';
        myOpportunity.AccountId   = myAccount.Id; // Relates to id of account above.
        insert myOpportunity;
            
        // Fire the UpdateRatesheetLookup Trigger
        // Create a Quote associated with Opportunity & Set Required Fields
        Quote myQuote          = new Quote();
        myQuote.Name           = 'Sample';
        myQuote.OpportunityId  = myOpportunity.Id; // Relates to id of opportunity above.
        //myQuote.TotalPrice   = 2500;
        myQuote.Buyout_Type__c = 'FMV';
       	insert myQuote; // FLAG: PROBLEM HERE
        
        // Update the Quote
        myQuote.Description = 'Test';
       	update myQuote;
    }
}

Any help with this would be greatly appreciated. 
Thanks in advance!
 
Hello, I am fairly new and am experimenting with Apex & Visualforce.

I managed to figure out how to display a list of all the users in my org, but I can't figure out how to display a specific user.

Apex Class:
public class UserResultsController {
    
    public List<String>getListOfUsers(){
		List<string> ourUsers = new list<string>();
			
        	for(User a:[SELECT Name FROM User]){
				ourUsers.add(a.Name);
			}
        
		return ourUsers;
	}
 
}
Apex Page:
<apex:page controller="UserResultsController" >
    
   <apex:repeat value="{!ListOfUsers}" var="usl"> 
       <apex:outputText value="{!usl}"/> <br/> 
   </apex:repeat>
        
</apex:page>

Is there a way to either populate the data about a specific user using their User Id or doing a query for a specific user?

I know I can display the current logged in user data by using: {!$User.FirstName} for instance, but I want to display a specific user, not the current logged in user.

Help is greatly appreciated. 
Hello all,

I am having some trouble with an Apex Trigger test class I'm writing. I am using a developer sandbox and am getting the following error:
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: a0D6A0000015UKi: []

What I am trying to do is update a Lookup field that looks up to a Rate Sheet based on certain criteria. (Rate_Sheet__c = API Name)

I wrote the trigger and had no errors that I could see but when writing the test class it kept giving me the Insufficient Access error. Not really sure what the problem is. Under sharing settings, my org wide defaults gives public read/write access to all objects needed.

Please see the following Apex Trigger and Test Class code:
trigger UpdateRatesheetLookup on Quote (before insert, before update) {

    for (Quote quo : Trigger.new) {
       
        if (quo.TotalPrice < 3000 && quo.Buyout_Type__c == 'FMV') {
            // Sets Rate Sheet Lookup
            quo.Rate_Sheet__c = 'a0D6A0000015UKi';
            
        } else if (quo.TotalPrice < 10000 && quo.Buyout_Type__c == 'FMV') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKj';
            
        } else if (quo.TotalPrice >= 10000 && quo.Buyout_Type__c == 'FMV') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKk';
            
        } else if (quo.TotalPrice < 3000 && quo.Buyout_Type__c == 'Promo FMV') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKl';
            
        } else if (quo.TotalPrice < 10000 && quo.Buyout_Type__c == 'Promo FMV') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKm';
            
        } else if (quo.TotalPrice >= 10000 && quo.Buyout_Type__c == 'Promo FMV') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKn';
            
        } else if (quo.TotalPrice < 3000 && quo.Buyout_Type__c == '$1-out') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKo';
            
        } else if (quo.TotalPrice < 10000 && quo.Buyout_Type__c == '$1-out') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKp';
            
        } else if (quo.TotalPrice >= 10000 && quo.Buyout_Type__c == '$1-out') {
            quo.Rate_Sheet__c = 'a0D6A0000015UKq';
            
        } else {
            quo.Rate_Sheet__c = Null;
        }
    }
}

// Problem is happening at insertion of the myQuote instance.
@isTest
private class UpdateRateSheetLookupTest {
    
    @isTest static void updateQuote() {
        
        // Create an Account & Set Required Fields
        Account myAccount = new Account();
        myAccount.Name    = 'Sample Account';
        insert myAccount;
        
        // Create an Opportunity on the Account & Set Required Fields
        Opportunity myOpportunity = new Opportunity();
        myOpportunity.Name        = 'Sample Opportunity';
        myOpportunity.CloseDate   = Date.today();
        myOpportunity.StageName   = 'Proposal';
        myOpportunity.AccountId   = myAccount.Id; // Relates to id of account above.
        insert myOpportunity;
            
        // Fire the UpdateRatesheetLookup Trigger
        // Create a Quote associated with Opportunity & Set Required Fields
        Quote myQuote          = new Quote();
        myQuote.Name           = 'Sample';
        myQuote.OpportunityId  = myOpportunity.Id; // Relates to id of opportunity above.
        //myQuote.TotalPrice   = 2500;
        myQuote.Buyout_Type__c = 'FMV';
       	insert myQuote; // FLAG: PROBLEM HERE
        
        // Update the Quote
        myQuote.Description = 'Test';
       	update myQuote;
    }
}

Any help with this would be greatly appreciated. 
Thanks in advance!