• sfdc_Devl
  • NEWBIE
  • 25 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 4
    Replies
Hi,

I have created a visual force page. There are two objects Job Application and Candidate.
I'm displaying the name of Job Application in VF Page. When a name is clicked it should display candidate's first name, but its not displaying. Here is the code I have written.

VF Page
<apex:page controller="D_Controller">
 <apex:form >
  <apex:datalist value="{!JA}" var="item"> 
    <apex:commandLink action="{!JAclicked}" rerender="CandidateDetails">
      <apex:outputtext value="{!item.Name__c}" />
     <apex:param name="id" value="{!item.id}" assignTo="{!selectedCandidate}"/>
    </apex:commandLink>
  </apex:datalist>
 </apex:form>
 <apex:outputPanel id="CandidateDetails">
  <apex:repeat value="{!CandidateInfo}" var="item">
   <p>Custom Control Demo "{!item.First_Name__c}" </p>
  </apex:repeat>
 </apex:outputPanel>
</apex:page>

Controller
public class D_Controller 
{
 public id selectedCandidate{get;set;}
 public list<Candidate__c> CandidateInfo{get;set;}
 public list<Job_Application__c> getJA()
 {
   return [select Name__c, Position__c, Candidate__c from Job_Application__c limit 5];
 }
 public void JAclicked()
 {
  CandidateInfo = [select First_Name__c, Last_Name__c from Candidate__c where ID = :selectedCandidate] ;
 }
}


Please let me know hwat should I modify
Hi All,
I have created a trigger that when an order is in the Status[Order Submitted] and the create case field is true i want a case to be created.
However there are multiple cases being created against the record 
Please see below triger and classes. :
My Trigger
triggerHandler 
triggerFunction

trigger caseOrder on ccrz__E_Order__c (after insert, after update) {
     if(trigger.isInsert){
        caseOrderTriggerHandler.isAfterInsert(Trigger.new);
    }
        if(trigger.isUpdate){
            caseOrderTriggerHandler.isAfterInsert(Trigger.new);
        }

}

public class caseOrderTriggerHandler {
    public static void isAfterInsert (List<ccrz__E_Order__c>ords) {
        caseOrderTriggerFunction.createCase(ords);
    }

}

public class caseOrderTriggerFunction {
    
 
    public static void createCase(List<ccrz__E_Order__c>ords){
        Date ordCreatedDate = date.today();
        List<ccrz__E_Order__c> todaysOrds = [SELECT id, ccrz__OrderStatus__c, Create_Case__c,ccrz__OrderDate__c,ccrz__Contact__c,ccrz__Account__c
                                             FROM ccrz__E_Order__c
                                             WHERE id IN :ords
                                             AND ccrz__OrderDate__c = :ordCreatedDate];
        
        List<Case> myCase = new List <Case>();
        
        for(ccrz__E_Order__c myOrds : todaysOrds) {
            
            if(myOrds.ccrz__OrderStatus__c == 'Order Submitted' && myOrds.Create_Case__c == true ) {
                
                case c = new case();
                c.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('General Enquiry').getRecordTypeId();
                c.Reason = 'General Enquiry';
                c.Case_Reason__c ='orders';
                c.Status = 'New';
                c.Subject = 'order Submitted status';
                c.Case_Sub_Reason__c ='Incomplete Order Creation';
                c.Description ='Order Id: '+myOrds.Id+'related to account Id: '+myOrds.ccrz__Account__c+' has failed in SAP';
                c.ContactId = myOrds.ccrz__Contact__c;
                c.AccountId = myOrds.ccrz__Account__c;
                myCase.add(c);
                
                
            } 
        }
        if(mycase.size() == 1 ) {
            insert myCase;
        }
        
        
    }
    
        
}




 
Hey Team,

My trigger works correctly when changing one record but when I use the data loader it is only assigning 1 sales rep for all the records. I have seen others that have had this same issue and it appears to be something with the mapping, but after a long time of comparing answers in other posts I'm not seeing my error. Please let me know where I am going wrong.
 
trigger AssignDistSales1 on Distributor_Sales__c ( before insert, before update) 
{
    //get set of 3 digit zips from Distributor Sales to be inserted or updated
    Set<String> ZIP = new Set<String>();
    for(Distributor_Sales__c distsales : Trigger.new){
        if(distsales.X3_Digit_Zip__c != null){
            ZIP.add(distsales.X3_Digit_Zip__c);
        }
    }
    
    //list of territories needed to map to Distributor Sales
    List<Territory__c> potentialTerr =  [SELECT X3_Digit_Zip__c, Sales_Rep_for_Later_Assignment__c FROM Territory__c WHERE X3_Digit_Zip__c in :ZIP];
    
    //map that lets me search for territories by their zip
    Map<String,Territory__c> DistToTerrMap = new Map<String, Territory__c>();
        for (Territory__c t: potentialTerr) {
        DistToTerrMap.put(t.X3_Digit_Zip__c, t);
        
    //match the distributor sales 3 digit zip territory by 3 digit zip
    for(Distributor_Sales__c distsales : Trigger.new){
        distsales.Sales_Rep_for_Later_Assignment__c = DistToTerrMap.get(t.X3_Digit_Zip__c).Sales_Rep_for_Later_Assignment__c;
      }
   }
}

 
Hi,

I have created a visual force page. There are two objects Job Application and Candidate.
I'm displaying the name of Job Application in VF Page. When a name is clicked it should display candidate's first name, but its not displaying. Here is the code I have written.

VF Page
<apex:page controller="D_Controller">
 <apex:form >
  <apex:datalist value="{!JA}" var="item"> 
    <apex:commandLink action="{!JAclicked}" rerender="CandidateDetails">
      <apex:outputtext value="{!item.Name__c}" />
     <apex:param name="id" value="{!item.id}" assignTo="{!selectedCandidate}"/>
    </apex:commandLink>
  </apex:datalist>
 </apex:form>
 <apex:outputPanel id="CandidateDetails">
  <apex:repeat value="{!CandidateInfo}" var="item">
   <p>Custom Control Demo "{!item.First_Name__c}" </p>
  </apex:repeat>
 </apex:outputPanel>
</apex:page>

Controller
public class D_Controller 
{
 public id selectedCandidate{get;set;}
 public list<Candidate__c> CandidateInfo{get;set;}
 public list<Job_Application__c> getJA()
 {
   return [select Name__c, Position__c, Candidate__c from Job_Application__c limit 5];
 }
 public void JAclicked()
 {
  CandidateInfo = [select First_Name__c, Last_Name__c from Candidate__c where ID = :selectedCandidate] ;
 }
}


Please let me know hwat should I modify

Hi,

 

We have a Scheduler Class for a Batch Class, both of which are working fine as evidenced by the fact that they have both successfully fired on schedule the last three days.  The Test Class, however, seems to be written incorrectly / not invoking properly.  The text class is below:

 

@isTest

class TestStampForecastLastUpdated {
	
	static testMethod void testStampForecastLastUpdated() {
		
		// Declare Local Variables
		final string							accountRecordType = 'Distributor';
		Id										accountRecordTypeId;
		Map<String, Schema.RecordTypeInfo>		accountRecordTypes = new Map<String, Schema.RecordTypeInfo>();
		CronTrigger								cronTrigger;
		String 									jobId;
		final Date								monthEnd = date.valueOf('2008-02-29 00:00:00');
		final Date								today = System.today();
		Product2								product;
		
		// Get Account Record Type Ids
		accountRecordTypes = Schema.SObjectType.Account.getRecordTypeInfosByName();
		accountRecordTypeId = accountRecordTypes.get(accountRecordType).getRecordTypeId();

		// Create an Account
		Account a1 = new Account (Name = 'Acme', Product_Discount_Amount__c = 9, RecordTypeId = accountRecordTypeId);
		Insert a1;
		
		// Get a Product
		product = [SELECT Id FROM Product2 WHERE IsActive = true AND Forecast__c = true LIMIT 1];
		
		// Create a Forecast record in the past and one in the future
		Forecast__c f1 = new Forecast__c (Account__c = a1.id, Backlog_Quantity__c = 1, Backlog_Amount__c = 100, Est_Forecast_Rev__c = 100, Last_Updated__c = date.valueOf('2008-02-15 00:00:00'), Month_End_Date__c = monthEnd, Product__c = product.Id, Quantity__c = 1, Shipped__c = 1, Shipped_Amount__c = 100, Shipped_and_Backlog__c = 150);
		Forecast__c f2 = new Forecast__c (Account__c = a1.id, Backlog_Quantity__c = 1, Backlog_Amount__c = 100, Est_Forecast_Rev__c = 100, Last_Updated__c = date.valueOf('2008-02-15 00:00:00'), Month_End_Date__c = today, Product__c = product.Id, Quantity__c = 1, Shipped__c = 1, Shipped_Amount__c = 100, Shipped_and_Backlog__c = 150);
		insert f1;
		insert f2;
		
		// Execute the batchable test
		Test.startTest();

		// Schedule the test job
		String scheduleExpression = '0 0 0 3 9 ? 2022';
		jobId = System.schedule('testScheduleStampForecastLastUpdated', scheduleExpression, new ScheduleStampForecastLastUpdated());
		
		// Get the CronTrigger info
		cronTrigger = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE Id = :jobId];
		
		// Assert that the expressions are the same
		System.assertEquals(scheduleExpression, cronTrigger.CronExpression);
		
		// Assert that the Cron job has not started
		System.assertEquals(cronTrigger.TimesTriggered, 0);
		
		// Assert that the Forecasts have their original values
		System.assertEquals([SELECT Last_Updated__c FROM Forecast__c WHERE Id = :f1.Id].Last_Updated__c, date.valueOf('2008-02-15 00:00:00'));
		System.assertEquals([SELECT Last_Updated__c FROM Forecast__c WHERE Id = :f2.Id].Last_Updated__c, date.valueOf('2008-02-15 00:00:00'));
		
		// Stop the test
		Test.stopTest();
		
		// Assert that the Forecasts have their proper values
		System.assertEquals([SELECT Last_Updated__c FROM Forecast__c WHERE Id = :f1.Id].Last_Updated__c, date.valueOf('2008-02-15 00:00:00'));
System.debug('f2 = ' + [SELECT Status__c FROM Forecast__c WHERE Id = :f2.Id]);
		System.assertEquals([SELECT Last_Updated__c FROM Forecast__c WHERE Id = :f2.Id].Last_Updated__c, System.today());
	}
}

 

The last assertion fails, although the System.debug line shows that it should have been processed.  Again, the Scheduler and Batch are working properly, which leads me to believe that this Test Class is constructed improperly.

 

Relevant code from the Scheduler and Batch below, although again, they have fired properly as scheduled every day since scheduled.

 

global class ScheduleStampForecastLastUpdated implements Schedulable {

	global void execute (SchedulableContext sc) {

		stampForecastLastUpdated sflu = new stampForecastLastUpdated('SELECT Last_Updated__c FROM Forecast__c WHERE Status__c = \'Active\'');
		database.executebatch(sflu);
	}
}

 

global class StampForecastLastUpdated implements Database.Batchable<sObject>{

	global final string	query;
	date				today = date.today();

	global StampForecastLastUpdated(String query) {
		this.query = query;
	}
	
	global Database.QueryLocator start(Database.BatchableContext BC) {
		return Database.getQueryLocator(query);
	}

	global void execute(Database.BatchableContext BC, List<sObject> scope) {
		List<Forecast__c> forecasts = new List<Forecast__c>();

		for (sObject s : scope) {
			Forecast__c f = (Forecast__c)s;
			f.Last_Updated__c = today;
			forecasts.add(f);
		}
		update forecasts;
	}

	global void finish(Database.BatchableContext BC) {
	}
}

 

 

Thanks,

Marc

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

 

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

 

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

 

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

 

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

 

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