• lovetolearn
  • NEWBIE
  • 30 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 64
    Questions
  • 124
    Replies

Hi, 

 

I have the following SOQL query: 

 

Select Id, AccountID, (Select Id, CreatedDate From Tasks ORDER BY CreatedDate DESC LIMIT 1) From Case c

The goal is to returns the Created Date and the ID and all of the tasks that are associated with the Case. I was wondering how do I get the Id value of the Task that is returned by this query?

Hi, 

 

I have an objected called Helper__c. On my Case, there is a lookup field to this object. My goal is to update the three custom fields on the Helper__c object whenever a Helper record is selected. The custom fields are Total Number of Cases, Date of Last Case and Last Case Number. I wrote a trigger for this, but my the trigger is bulk-safe and I always get SOQL Query limit errors during mass updates. Please help me correect the following code:

 

Trigger:

 

trigger helperCases on Case (after insert, after update, after delete) {
    
    if(trigger.isUpdate || trigger.isInsert){
        for(Case c: trigger.new){
            if(c.helper__c == null){
                
            }else if(c.helper__c != null){
                testUpdate.testHelperUpdate(c.Helper__c);
            }
        }
    }if(trigger.isUpdate){
    	for(Case c : trigger.old){
            if(c.Helper__c == null){
    			
    	    }else if(c.Helper__c !=null){
    		testUpdate.testHelperUpdate(c.Helper__c);
    	    }
    	}
    }if(trigger.isDelete){
        for(Case c: trigger.old){
            if(c.Helper__c == null){
                
            }else if(c.Helper__c != null){
                testUpdate.testHelperUpdate(c.Helper__c);
            }
        }   
    }
}

 

Apex Class:

 

public class testUpdate{
     public static void testHelper(Id helperId){
        Double numberofCases;
        String cNum;
        LIST<CASE> c = [SELECT ID, CaseNumber, CreatedDate FROM CASE WHERE Helper__c =: helperID ORDER BY CaseNumber DESC];
        numberofCases = c.size();
        Helper__c helper = [SELECT ID,  all_cases__c, Last_case__c, Last_case_date__c FROM Helper__c WHERE ID =: HelperID];
        helper.all_cases__c = numberofCases;
        if(c.size()>0){
            cNum = c[0].ID;
            Helper.last_case__c = cNum;
            Helper.Last_case_date__c = c[0].CreatedDate;
        }else{
            Helper.last_case__c = null;
            Helper.Last_case_date__c = null;
        }
        update helper;

     }
}

 Thank you.

Hi, 

 

I see that there is not setToAddressses method for the MassEmailMessage class like there is for SingleEmailMessage. Is there then any way to specify the recipicent's email address for mass emails?

 

Thanks in advance.

Hi,  

 

I installed the Birthday Reminder app from the Appexchange store. The code is unmanaged and I was trying to change the field from which the code is pulling the email address from for the recipient. I tried a couple of different ways, but none of them worked. Please help. Here is the code:

 

global class BirthdayCronJob implements Schedulable{ 
	
		global void execute(SchedulableContext SC) {
      		    sendmail(); 
                }
		
		public List<Id> getBirthdayEmailAddresses(Integer Month, Integer Day) 
     	{ 
        	List<Id> mailToIds = new List<Id>();
        	 
        	
	        Contact[] c = [SELECT Id, email, Birthdate, Send_Birthday_Email__c, HasOptedOutOfEmail
	        				FROM Contact 
	        				WHERE DAY_IN_MONTH(Birthdate) = : Day 
						AND CALENDAR_MONTH(Birthdate) = : Month   
	        				];
        
			       
    	    for(Contact recipient : c) {
    	    		    	    		
    	    		if (recipient.Send_Birthday_Email__c == true && recipient.HasOptedOutOfEmail == false)
    	    		{
    	    			mailToIds.add(recipient.Id);	
    	    			System.Debug('\n*******Recipient: '+ recipient.email);
    	    			 
    	    		} else {
    	    			
    	    			System.Debug('\n*******NO Recipient');
    	    		}
	        	
        	}
        	return mailToIds;
     	}
        public void sendMail() 
    	{
		String debugAddress = 'eyewell@salesforce.com';
		String BirthdayEmailTemplateName = 'Happy_Birthday';
		String AnniversaryEmailTemplateName = 'Celebrating_your_Anniversary';			
		String debugMessage;
        	String[] toAddresses;

    		Integer DayOfEvent   = date.today().day();
			Integer MonthOfEvent = date.today().month();
 
        	List<Id> BirthdayIdsList = getBirthdayEmailAddresses(MonthOfEvent,DayOfEvent);

        	EmailTemplate birthdayTemplate = [select Id,Name,Subject,body from EmailTemplate where DeveloperName = :BirthdayEmailTemplateName];
		
        	if(birthdayTemplate != null && BirthdayIdsList.isEmpty() == false)
        	{

           		Messaging.MassEmailMessage birthdayMail = new Messaging.MassEmailMessage();
    
            	birthdayMail.setTargetObjectIds(BirthdayIdsList);
            	birthdayMail.setTemplateId(birthdayTemplate.Id);
            	birthdayMail.setUseSignature(false);
            	birthdayMail.setSaveAsActivity(true);

            	try {
            		Messaging.sendEmail(new Messaging.MassEmailMessage[] { birthdayMail });
            	}catch(Exception e)
            	{
            		System.Debug(e);
            	}
           
        	}
        	else
        	{
            	        System.Debug('BirthdayCronJob:sendMail(): Either an email template could not be found, or no Contact has a birthday today');
        	}


}

 So instead of the native Force.com Email field, I want to use a custom email field called "Secondary Email." I tried changing the SOQL statement, but it still didnt work. 

Hi, 

 

I am trying to schedule an Apex class to run daily. The Apex class is supposed to update query for the number of Cases against a Member record, then update a field with this number. The Apex class ran at it's scheduled time (I checked the Schedule Jobs queue and it showed me that it indeed did run). However, the field was not updated. Please help me. Here is my code: 

global class accCaseCnt implements Schedulable{
    
    global void execute (SchedulableContext sc){
        updateAcc();
    }
    
    
    public void numAccCase(ID accID){
        Map<ID, Integer> accMap = new Map<ID, Integer>();
        
        Account[] acc = [SELECT Id FROM Account WHERE Id =: accID];
    
        LIST<AggregateResult> totalCases = [SELECT AccountID, Count(ID) cnts FROM Case WHERE AccountID =: accID GROUP BY AccountID];
    
        for(AggregateResult ar: totalCases){
            accMap.put(String.valueOf(ar.get('AccountID')), Integer.valueOf(ar.get('cnts')));
        }
    
        for(Account a: acc){
            acc.Total_Cases__c = accMap.get(acc.Id);
        }
    }
    
    public void updateAcc(){
        Integer i;
        Integer x = 0;
        
        List<Account>accList = new List<Account>([SELECT ID FROM Account]);
        
        for(i = 0; i<=accList.size(); i++){
            numAccCase(accList[x].id);
            x++;
        }
    }    
}

 Thank you.

Hi, 

 

I am trying to write a trigger that will count all the Case record for a Worker__c custom object record. I have about 6000 records that i need to update in one shot. Here is the error message that I keep getting: Compile Error: Initial term of field expression must be a concrete SObject: Integer on my last line of code. Here is my code:

 

trigger WorkerBulkUpdate on Worker__c (after update) {
    
    Set<ID> workerID = new Set<ID>();
    for (Worker__c worker: Trigger.new){
        workerID.add(worker.ID);
    
    Map<Worker__c, Integer> caseMap = new Map<Worker__c, Integer>();
    
    for(AggregateResult ar: [SELECT Worker__c, Count(ID) cnts FROM Case WHERE worker__c =: worker
                             GROUP BY Worker__c]){
        caseMap.put(worker, Integer.valueOf(ar.get('cnts')));
        
        if(worker.isUpdated__c == true){}
        worker.Number_of_all_cases__c = caseMap.get(worker).cnts;
    }
    }

 

Please help. Thank you. 

 

Please help with this error: Incompatible key type Object for Map. I am trying to find all Cases associated with a custom Worker object. Please also let me know if my trigger does not look right. Here is my code:

 

trigger TestWorkerBulkUpdate on Worker__c (before update) {
	
	Set<ID> workerID = new Set<ID>();
	for (Worker__c worker: Trigger.new)
		workerID.add(worker.ID);
 	
	Map<ID, Integer> caseMap = new Map<Id, Integer>();
	
	for(AggregateResult ar: [SELECT ID, Count(ID) cnts FROM Case WHERE Worker__c =: workerID])
		caseMap.put(ar.get('ID'), ar.get('cnts'));
	
	for (Worker__c worker: trigger.new)	
    	worker.Number_of_all_cases__c = caseMap.get(worker.ID).cnt;
}

 

 Thank you.

Hi,

 

I am trying to remove duplicates records after they have been inserted. Not sure where I went wrong, but the trigger only seems to work about 50% of the time. Here is my code:

 

trigger deleteEventDup on Events__c (after update, after insert) {
    for(Events e : trigger.new){  
       Events[] eDup = [SELECT ID FROM Events__c WHERE Case__c =: e.Case__c 
                        AND CreatedDateAndTime__c =: e.CreatedDateAndTime__c
                        AND Type_of_Events__c =: e.Type_of_Events__c  
                        ORDER BY Name ASC];
           if(eDup.size() >1){
            delete eDup[0];        
         }
    }
}

 Please help. Thank you.

Hi, 

 

I am trying to update a field on a record after its been inserted using a trigger. For some reason, the trigger is not firing. Here is my code: 

trigger eventType on Party_Event__c (after insert, after update) {
    for(Party_Event__c pe : trigger.new){
        String events = pe.Type_of_Events__c;
        DateTime startDate = pe.start_date__c;
        DateTime endDate = pe.end_date__c;
        
        if(startDate == null){
            events = 'No Specific Date';
        }
        
    }
}

 

Please help. Thank you. 

Hi, 

 

I am trying to display different outputText depending on the value selected in a picklist. I also want my picklist to load the last value that the user entered. If I use the default getter and setter method, I can't display the last value entered by the user. But if I write my own getter and setter, the outputText does not refresh. I think I am writing the setter method wrong. Here is my code: 

<apex:page controller="testEvents">
    <apex:form id="eventsForm">
        <apex:pageBlock id="eventPageBlock">
            <apex:pageBlockSection id="eventPageBlockSection">
                <apex:selectList label="Events:" id="status" size="1" multiselect="false" value="{!events}">
                    <apex:selectOption itemLabel="" itemValue=""/>
                    <apex:selectOption itemLabel="Morning Only" itemValue="Morning Only"/>
                    <apex:selectOption itemLabel="Evening Only" itemValue="Evening Only"/>
                    <apex:selectOption itemLabel="All Day" itemValue="All Day"/>
                    <apex:actionSupport event="onchange" reRender="Display" status="testStatus"/>
                </apex:selectList><br/>
                <apex:commandButton value="GOGOGOGO!!" action="{!createEventObj}"/>
            </apex:pageBlockSection><br/><br/>
            <apex:outputPanel id="Display">
                <apex:outputText value="This is what displays when you enter All Day Event" rendered="{!IF(events = 'All Day', true, false)}"/>
                <apex:outputText value="This is what displays when you enter anything else but All Day Events" rendered="{!IF(events != 'All Day', true, false)}"/>
            </apex:outputPanel><br/>
            <apex:actionStatus startText="Rerendering..." stopText="(All Set!)" id="testStatus"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

public class testEvents{
    public string events;
    LIST<Event_Obj__c> eventlist  = [SELECT ID, Title__c, Type_of_Event__c FROM Event_Obj__c WHERE ID = 'a0qR0000000U10w'];
    
    public void setevents(String events){
        this.events = events;
    }
    
     public String getevents(){
          return eventList[0].Type_of_Event__c;
     }
    
    public void createEventObj(){
        if(eventlist.size()==0){
            Event_Obj__c eobj = new Event_Obj__c (Number__c = '500R000000354zt', Type_of_Event__c = events);
            insert eobj;
        }else if(eventlist.size() >= 1){
            Event_Obj__c updateobj = [SELECT Type_of_Event__c FROM Event_Obj__c WHERE Number__c = '500R000000354zt' LIMIT 1];
            updateobj.Type_of_Event__c = events;
            update updateobj;
        }
    }
}

 Please help. Thank you. 

Hi, 

 

I am trying to use the OR operator with the following statement:

 

<apex:inputField value="{!object__c.field__c}" rendered="{!status='Before'}"/>

 The logic is display this inputfield if the the status is before or after. 

 

Please help. 

 

Thank you 

Hi,

 

I am trying to construct a page where the fields displayed is dependent on the value selected from the picklist. Below is as far as I got:

<apex:page controller="statusController">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:selectList size="1" id="Status" label="Status" multiselect="false" value="{!Status}">
                    <apex:selectOption itemLabel="Before" itemValue="Before"/>
                    <apex:selectOption itemLabel="During" itemValue="During"/> 
                    <apex:selectOption itemLabel="After" itemValue="After"/>                 
                </apex:selectList>
                <apex:actionSupport event="onchange" reRender="statusField"/>
            </apex:pageBlockSection>
                <apex:outputPanel id="statusField">
                    
                </apex:outputPanel> 
        </apex:pageBlock>    
    </apex:form>
</apex:page>


public class statusController {

    public String Status {get; set;}

}

 Not sure where to specify the conditions (If statments) and how to specify what fields to display. Please help. Thank you.

Hi,

 

I am having some trouble writing unit test for my apex class. I keep getting the error:System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Member__c]: [Member__c]. 

 

Here is my code: 

 

public class exNewFeedback {

    public Case requests {get; set;}
    public String details {get; set;}
    public String fbFrom {get; set;}
    public String fbSource {get; set;}
  
    
    public exNewFeedback(ApexPages.StandardController controller) {
        this.requests = (Case)controller.getRecord();
        this.requests = [SELECT ID, accountID, Supplier__c, User_Owner_Office__c FROM Case WHERE ID =: requests.ID][0];
    }
           
    public PageReference createRequest(){
        Feedback__c compliment = new Feedback__c();
        compliment.Member__c = requests.accountID;
        compliment.Request__c = requests.ID;
        compliment.Supplier__c = requests.Supplier__c;
        compliment.Escalated_to_Complaint__c = 'No';
        compliment.Relevant_office__c = requests.User_Owner_Office__c;
        compliment.Details__c = details;
        compliment.Feedback_From__c = fbFrom;
        compliment.Feedback_Source__c=fbSource;
        insert compliment;
     
        PageReference fbPage = new ApexPages.StandardController(compliment).view();
        fbPage.setRedirect(true);
        return fbPage;
    }
    
    static testMethod void testNewFeedback(){
           Account member = new Account(Name = 'Test User');
           insert member;
           LIST<Account> memberlist = [SELECT ID FROM Account LIMIT 1];
           System.assertEquals(1, memberlist.size());
           Contact c = new Contact(FirstName = 'Test', LastName='Test', Account = member, Region__c='Africa', 
                                   Newsletter_Preferences_taken_setup__c = 'Yes', Where_did_client_hear_of_us__c = 'Do Not Know',
                                   Membership_Status__c = 'N/a - Corporate Bus Dev Contact');
           insert c;
           List<Contact> clist = [SELECT ID FROM CONTACT LIMIT 1];
           System.AssertEquals(1, clist.size());
           Case request = new Case(Contact = c, Origin = 'Email', Status = 'Open');
           insert request;
           List<Case> requestlist = [SELECT ID FROM CASE LIMIT 1];
           System.AssertEquals(1, requestlist.size());
           Case requests = [SELECT ID, accountID, Supplier__c, User_Owner_Office__c FROM CASE WHERE 
                            ID =: request.ID];
           Apexpages.Standardcontroller stdCon = new apexpages.Standardcontroller(requests);
           exNewFeedback exFB = new exNewFeedback (stdCon);
           exFB.createRequest();   
    }
}

 Please let me know where I went wrong. Thank you. 

Hi, 

 

I am trying to increase my code coverage from 85% to 100%. The only section that is in red from the test result is the pagereference section. Here is my code:

 

public class exNewFeedback {

    public Case requests {get; set;}
    public String details {get; set;}
    public String fbFrom {get; set;}
    public String fbSource {get; set;}
    Feedback__c feedback;
    
    public exNewFeedback(ApexPages.StandardController controller) {
        requests = (Case)controller.getRecord();
    }
    
    public PageReference createRequest(){
        Feedback__c compliment = new Feedback__c();
        compliment.Member__c = requests.Contact.Account.Id;
        compliment.Request__c = requests.ID;
        compliment.Supplier__c = requests.Supplier__c;
        compliment.Escalated_to_Complaint__c = 'No';
        compliment.Relevant_office__c = requests.User_Owner_Office__c;
        compliment.Details__c = details;
        compliment.Feedback_From__c = fbFrom;
        compliment.Feedback_Source__c=fbSource;
        insert compliment;
     
        PageReference fbPage = new ApexPages.StandardController(compliment).view();
        fbPage.setRedirect(true);
        return fbPage;
    }
    
    static testMethod void testNewFeedback(){
           Account member = new Account(Name = 'Test User');
           insert member;
           LIST<Account> memberlist = [SELECT ID FROM Account LIMIT 1];
           System.assertEquals(1, memberlist.size());
           Supplier__c supplier = new Supplier__c(Name = 'Test Supplier', Status__c = 'Info Only', Category__c = 'Beauty', Type__c = 'Nails');
           insert supplier;
           LIST<Supplier__c> supplierlist = [SELECT ID FROM Supplier__c LIMIT 1];
           System.assertEquals(1, supplierlist.size());
           Case request = new Case(Origin = 'Email', Status = 'Open', Supplier__c = supplierlist[0].ID);
           insert request;
           LIST<Case> requestlist = [SELECT ID FROM Case LIMIT 1];
           System.assertEquals(1, requestlist.size());
           Apexpages.Standardcontroller stdCon = new apexpages.Standardcontroller(request);
           exNewFeedback exFB = new exNewFeedback (stdCon);
           exFB.createRequest();   
    }
}

Please help. Thank you.

Hi, 

 

I am trying to pass the value of an Apex InputField into an Apex class. Here is my VF markup: 

<apex:page standardController="SFDC_Employee__c" extensions="myTextController" >
    <apex:form >
        <apex:pageblock >
            <apex:pageblockSection >
                 <apex:inputField value="{!SFDC_Employee__c.Delete_Schedule_Days_Off_From__c}" id="startDate"/><br/>
                 <apex:commandButton value="Display" reRender="display"/><br/><br/>  
                 <apex:outputPanel id="display">
                    <apex:outputText value="The Date is {!startDate}" style="font-weight:bold"/><br/><br/>
                </apex:outputpanel>
            </apex:pageblockSection> 
        </apex:pageblock>
    </apex:form>
</apex:page>

 

My Apex Class:

 

public class myTextController {
    
    public myTextController(ApexPages.StandardController controller) {
    }
    public Date startDate {get; set;}

    }
}

 I keep getting a blank value for this. Please help. Thank you. 

Hi, 

 

I am trying to return the number of records associated with the user input. Here is my VF markup:

 

<apex:page standardController="SFDC_Employee__c" extensions="myTextController" >
    <apex:form >
        <apex:pageblock >
            <apex:pageblockSection >
                <apex:inputText id="myText" value="{!myText}" label="Employee Name">
                    <!---<apex:actionSupport event="onclick" reRender="display"/>--->
                </apex:inputText><br/>
                <apex:commandButton value="Display" reRender="display"/><br/><br/>  
                <apex:outputPanel id="display">
                    <apex:outputText value="You entered: {!ListSize}" style="font-weight:bold"/><br/><br/>
                </apex:outputpanel>
            </apex:pageblockSection> 
        </apex:pageblock>
    </apex:form>
</apex:page>

 

And here is my Apex class:

 

public class myTextController {
    
    public myTextController(ApexPages.StandardController controller) {
    }
    
    public String myText {get; set;}
    List<Schedule_Days_Off__c>sdolist=[SELECT Name FROM Schedule_Days_Off__c WHERE Employee_Name__r.Name =: myText];
    Integer x = sdolist.size();
    
    public Integer getListSize(){
        return x;
    }

}

 

The List returns values when I specific a certain name. For instance, if I change the SOQL statement to SELECT NAME FROM SCHEDULE_DAYS_OFF__C WHERE EMPLOYEE_NAME__R.NAME = 'TEST USER.' The List size is not 0. But when I do EMPLOYEE_NAME__R.NAME =: myText, and enter Test User on the VF page. The List size is 0. I think it may be my setter method, but I am not sure. Please help. Thank you. 

Hi, 

 

I am trying to write a Apex class to find all the SDO days associated with a user based on the user input on the VF page. I didn't get any errors from my code, but not sure why it is not working. Here is my code: 

 

public with sharing class exDeleteSDO {

    public exDeleteSDO(ApexPages.StandardController controller) {
    }
    
    public String sdoType{get; set;}
    public Date sdoFrom {get; set;}
    public Date sdoTo {get; set;}
    public string empName{get; set;}
    List<Schedule_Days_Off__c> sdolist;
    
	public void setempName (String empName){
		this.empName = empName;
		System.debug('This is the name' + empName);
	}
	public void setsdoType (String sdoType){
		this.sdoType = sdoType;
		System.debug('This is the type' + sdoType);
	}
	
	public void setsdoFrom (Date sdoFrom){
		this.sdoFrom = sdoFrom;
		System.debug('This is the date' + sdoFrom);
	}
	
	public void setsdoTo (Date sdoTo){
		this.sdoTo = sdoTo;
		System.debug('This is the date' + sdoFrom);
	}
	
	public PageReference deleteSDO(){
		sdolist = [SELECT ID FROM Schedule_Days_Off__c WHERE Employee_Name__c =: empName]; 
		try{
			delete sdolist;
		}
		catch(DmlException e){
		}
		return null;
	}
}

 Please help. Thank you. 

Hi, 

 

I keep getting this error: 'Save Error: unexpected token: ']'' for this SOQL statement: 

 

SELECT ID FROM Account Where Account_Start_Date__c >: startDate AND
Account_Start_Date__c <: endDate AND Account_Region_Text__c.contains(emplocation)];

 

Not sure where I went wrong wrong. Please help. Thank you. 

Hi, 

 

I am trying to create a SOQL with two AND conditons. It would look something similar to this: SELECT ID FROM Contact Where firstName ! = 'Test' AND lastName = 'User' AND Date_of_Birth__c != TODAY]. I know this syntax is not correct, but I am not sure what the correct syntax would be in this case. Please help. Thank you. 

 

Hi,

 

I am trying to create a trigger that creates junction object record only if it finds records in the query that i specified. For some reason the parameters that I specify in my query does not seem to be working right. Here is my code:

 

trigger testCreateHoliday on Leave_Request__c (after insert) {
    Leave_Request__c insertLR = new Leave_Request__c();
    Date startDate = insertLR.Request_Start_Date__c;
    Date endDate = insertLR.Request_End_Date__c;
    Decimal testnum = insertLR.testnum__c;
    List<Holiday__c> allHoliday=[SELECT ID FROM Holiday__c Where Holiday_Start_Date__c >: startDate AND
                                 Holiday_Start_Date__c <: endDate ORDER BY Holiday_Start_Date__c
                                 DESC];
    insertLR = trigger.new[0];
    Integer x = allHoliday.size();
    List<LR_and_Holiday__c> lrholidaylist = new List<LR_and_Holiday__c>();
    if(x > 0){
        for (Integer i = 1; i<=x; i++){
            LR_and_Holiday__c lrholiday = new LR_and_Holiday__c();
            lrholiday.Leave_Request__c = insertLR.ID;
            lrholiday.Holiday__c = allholiday[(x-1)].ID;
            lrholidaylist.add(lrholiday);
            x--;
        }
        Database.insert(lrholidaylist);
    }
}

I think it may be the way that I instaniated the Leave_Request object.

 

Please help.

 

Thank you.

Hi,


I was created " Bike Sells" customer object.
In this object i was created three fields.


1. Bike Model: Datatype (picklist)
2. Customer: Name datatype (Text)
3. Cost: datatype(Number)

My requirement is when i was select the 'Bike model' picklist values
click to submite the command button,i want to dispaly
the Customer Name, Cost  and Date Details of the paticuler Bike model piclist value.

 

Example: I select Picklist value: AUDI,It displays Audi car related customer Name and Cost.

 

How to find this problem?

 

 

 

 

 

 Code:


Visualforce:

 

<apex:page standardController="Car_Sells__c" recordSetVar="cs" extensions="stateExtension" sidebar="false">
    <apex:form >
        <apex:sectionHeader title="Car Sells Details"/>
        <apex:pageBlock title="Car Sells" mode="edit">
            <apex:pageBlockSection columns="1" showHeader="false">
                <apex:panelGroup >
                     <apex:outputLabel value="Select Car Model" for="accts" rendered="true"></apex:outputLabel>&nbsp;&nbsp;&nbsp;&nbsp;
                            <apex:selectList id="accts" value="{!Car_Sells__c.Car_Model__c}" size="1" title="Select State">
                                <apex:selectOptions value="{!accts}"></apex:selectOptions>
                            </apex:selectList>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                   <apex:commandButton action="{!doSearch}" value=" Show Customer Details" > </apex:commandButton>                    
                </apex:panelGroup>
            </apex:pageBlockSection><br/><br/><br/>
<apex:pageBlocksection colums="1" id="results">
<apex:pageBlockTable value="{!results}" var="item">
<apex:column value="{!item.Name}"/>
<apex:column value="{!item.Cost__c}"/>
<apex:column value="{!item.Date__c}"/>
</apex:pageBlockTable>
</apex:pageBlocksection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Apex code:

 

public class stateExtension {
    String accts;
   
    private final Car_Sells__c c; //User sobject
    
    //initializes the private member variable u by using the getRecord method from the standard controller
    
    public stateExtension(ApexPages.StandardSetController Controller) {
    
        this.c = (Car_Sells__c)Controller.getRecord();

    }
    
    //builds a picklist of Car_Sells__c  names based on their Car_Model__c
    public List<selectOption> getaccts() {

        List<selectOption> options = new List<selectOption>();
//new list for holding all of the picklist options
        options.add(new selectOption('', '- None -'));
//add the first option of '- None -' in case the user doesn't want to select a value or in case no values are returned from query below
        for (Car_Sells__c m : [SELECT Id, Name, Car_Model__c, Date__c FROM Car_Sells__c]) {
//query for Car_Sells__c records
            options.add(new selectOption(m.id, m.Car_Model__c));
//for all records found - add them to the picklist options
        }
        return options; //return the picklist options
    }

List<Car_Sells__c> mktsys;
   public void setAccts(String s) {
      accts =s;
   }
   public List<Car_Sells__c> getMktsys() {
      return mktsys;
   }
   public PageReference doSearch() {
      // Search by Exactly word
     mktsys = (List<Car_Sells__c>)[SELECT Id, Name, Cost__c FROM Car_Sells__c WHERE Car_Model__c =:accts];
 
       String qryString = 'SELECT Id, Name, Cost__c FROM Car_Sells__c WHERE Car_Model__c = :accts';
     mktsys = Database.query(qryString);
      return null;
   }

}

 

 

 

 

 

 

 

 

Thanks & Regards

SHIVA

 

 

 

 

 

 

 

 

 

 

 

 

 

Hey guys if can help me   i have a situation in which i need a apex logic to fit in a apex class which is already written

the situation is i need to write a trigger in which i have two custom fields which are in two different tabs so wen ever a custmer updated that particular field it has been updated automatically from the team site so now my job is to create a trigger tht wen ever it is update it should fire a trigger that shoots a email to that particular account user.

i need that logic it u guys can help me writing it 

 thanks

Hi everyone.....

i am new to the apex Test class..so plz help me on for writing the test class for below code

 

trigger autonumber1 on Account (before insert)
{
  for(account a:trigger.new)
  {
  
    List<account> ac=[select autonumber__c from account];
 if(ac[0].autonumber__c!=null)
  {
  a.autonumber__c=ac[0].autonumber__c+1;    
   }
   else
   a.autonumber__c=1200;
}
}

 

i am getting 60% code coverage but i got the failure message like...

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, autonumber1: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 0 Trigger.autonumber1: line 7, column 1: []

 

 

thanks in advance...

 

 

 

 

Hi

   I am trying to to create the VF page where I select the value and trying to get the value into controller. But I am not able to get the value my code:

 

<apex:page controller="SearchAndSendCtrl">
  <apex:form >
      <apex:pageBlock title="Seerch And Send Email">
      
          <apex:pageBlockSection >
              <apex:inputField value="{!ws.Worker_Name__c}"/>
              <apex:inputField value="{!ws.Work_Date_Time__c}"/>
          </apex:pageBlockSection>
          
          <apex:pageBlockButtons >
              <apex:commandButton value="Search" action="{!searchAction}"/>
              <apex:commandButton value="Send Email"/>
          </apex:pageBlockButtons>
          
      </apex:pageBlock>
  </apex:form>
</apex:page>

 

public class SearchAndSendCtrl
{

   
  //  Worker_details__c wd = new Worker_details__c();
    public Worker_details__c  wd {get;set;}
    public Work_Status__c ws {get; set;}       
    
    public SearchAndSendCtrl(){
        
    }
      
    public PageReference searchAction() {
            system.debug('Result of Name : ' + ws);
            system.debug('Result of Date : ' + ws);
            return null;
       }

    
    
}

 Please help me solve this issue. Please tell me what is need to be changed in this code.

Thanks

Anu

Hi, 

 

I have an objected called Helper__c. On my Case, there is a lookup field to this object. My goal is to update the three custom fields on the Helper__c object whenever a Helper record is selected. The custom fields are Total Number of Cases, Date of Last Case and Last Case Number. I wrote a trigger for this, but my the trigger is bulk-safe and I always get SOQL Query limit errors during mass updates. Please help me correect the following code:

 

Trigger:

 

trigger helperCases on Case (after insert, after update, after delete) {
    
    if(trigger.isUpdate || trigger.isInsert){
        for(Case c: trigger.new){
            if(c.helper__c == null){
                
            }else if(c.helper__c != null){
                testUpdate.testHelperUpdate(c.Helper__c);
            }
        }
    }if(trigger.isUpdate){
    	for(Case c : trigger.old){
            if(c.Helper__c == null){
    			
    	    }else if(c.Helper__c !=null){
    		testUpdate.testHelperUpdate(c.Helper__c);
    	    }
    	}
    }if(trigger.isDelete){
        for(Case c: trigger.old){
            if(c.Helper__c == null){
                
            }else if(c.Helper__c != null){
                testUpdate.testHelperUpdate(c.Helper__c);
            }
        }   
    }
}

 

Apex Class:

 

public class testUpdate{
     public static void testHelper(Id helperId){
        Double numberofCases;
        String cNum;
        LIST<CASE> c = [SELECT ID, CaseNumber, CreatedDate FROM CASE WHERE Helper__c =: helperID ORDER BY CaseNumber DESC];
        numberofCases = c.size();
        Helper__c helper = [SELECT ID,  all_cases__c, Last_case__c, Last_case_date__c FROM Helper__c WHERE ID =: HelperID];
        helper.all_cases__c = numberofCases;
        if(c.size()>0){
            cNum = c[0].ID;
            Helper.last_case__c = cNum;
            Helper.Last_case_date__c = c[0].CreatedDate;
        }else{
            Helper.last_case__c = null;
            Helper.Last_case_date__c = null;
        }
        update helper;

     }
}

 Thank you.

Hi, 

 

I see that there is not setToAddressses method for the MassEmailMessage class like there is for SingleEmailMessage. Is there then any way to specify the recipicent's email address for mass emails?

 

Thanks in advance.

I have a lookup custom field "referrer" on the lead object. When a lead refers someone, we enter a new lead and enter the referrer lead into the lookup field of the new lead. (So, lead-to-lead lookup relationship). We have another custom lead field that is a date-time, called "discount". When a lead has 4 new lead records that list the lead in the "referrer" lookup field, I want to insert the current date and time into the discount field.

 

I'm useless with code. Do we need a number field and add 1 with each lead or is there a way to just do a lookup to see if there are 4 each time a new lead is entered? Is this a simple trigger that anyone would be able to help me out with?

 

Thanks in advance.

Hi, 

 

I am trying to write a trigger that will count all the Case record for a Worker__c custom object record. I have about 6000 records that i need to update in one shot. Here is the error message that I keep getting: Compile Error: Initial term of field expression must be a concrete SObject: Integer on my last line of code. Here is my code:

 

trigger WorkerBulkUpdate on Worker__c (after update) {
    
    Set<ID> workerID = new Set<ID>();
    for (Worker__c worker: Trigger.new){
        workerID.add(worker.ID);
    
    Map<Worker__c, Integer> caseMap = new Map<Worker__c, Integer>();
    
    for(AggregateResult ar: [SELECT Worker__c, Count(ID) cnts FROM Case WHERE worker__c =: worker
                             GROUP BY Worker__c]){
        caseMap.put(worker, Integer.valueOf(ar.get('cnts')));
        
        if(worker.isUpdated__c == true){}
        worker.Number_of_all_cases__c = caseMap.get(worker).cnts;
    }
    }

 

Please help. Thank you. 

 

Please help with this error: Incompatible key type Object for Map. I am trying to find all Cases associated with a custom Worker object. Please also let me know if my trigger does not look right. Here is my code:

 

trigger TestWorkerBulkUpdate on Worker__c (before update) {
	
	Set<ID> workerID = new Set<ID>();
	for (Worker__c worker: Trigger.new)
		workerID.add(worker.ID);
 	
	Map<ID, Integer> caseMap = new Map<Id, Integer>();
	
	for(AggregateResult ar: [SELECT ID, Count(ID) cnts FROM Case WHERE Worker__c =: workerID])
		caseMap.put(ar.get('ID'), ar.get('cnts'));
	
	for (Worker__c worker: trigger.new)	
    	worker.Number_of_all_cases__c = caseMap.get(worker.ID).cnt;
}

 

 Thank you.

Hi,

 

I am trying to remove duplicates records after they have been inserted. Not sure where I went wrong, but the trigger only seems to work about 50% of the time. Here is my code:

 

trigger deleteEventDup on Events__c (after update, after insert) {
    for(Events e : trigger.new){  
       Events[] eDup = [SELECT ID FROM Events__c WHERE Case__c =: e.Case__c 
                        AND CreatedDateAndTime__c =: e.CreatedDateAndTime__c
                        AND Type_of_Events__c =: e.Type_of_Events__c  
                        ORDER BY Name ASC];
           if(eDup.size() >1){
            delete eDup[0];        
         }
    }
}

 Please help. Thank you.

Hi, 

 

I am trying to update a field on a record after its been inserted using a trigger. For some reason, the trigger is not firing. Here is my code: 

trigger eventType on Party_Event__c (after insert, after update) {
    for(Party_Event__c pe : trigger.new){
        String events = pe.Type_of_Events__c;
        DateTime startDate = pe.start_date__c;
        DateTime endDate = pe.end_date__c;
        
        if(startDate == null){
            events = 'No Specific Date';
        }
        
    }
}

 

Please help. Thank you.