• Nagendra Prasad Ch
  • SMARTIE
  • 875 Points
  • Member since 2014
  • Salesforce Developer
  • Accenture

  • Chatter
    Feed
  • 27
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 158
    Replies
Hi
I'm new to salesforce.
Can anyone help in writing the test class.
global class tridentUpdateOverduePGLWebService
{    
    webservice static SFAResponse updateOverdue(Overdue_element[] OverdueRec) 
    {       
        //HttpRequest req = new HttpRequest();   
        //req.setHeader('Content-Type','application/x-www-form-urlencoded');
        SFAResponse objResponse = new SFAResponse();
        Exceptions__c excep = new Exceptions__c();                          // to capture web service failure exceptions.
        list<OverDue_PGL__c> OverdueLst = new list<OverDue_PGL__c>{};
        
    for (Integer i=0; i<OverdueRec.size();i++)
    {
        OverDue_PGL__c OverDueObj= new OverDue_PGL__c();
        
        OverDueObj.CustomerName_name1_new__c= OverdueRec[i].CustomerName_name1_new;
        OverDueObj.Total_Outstanding_INR_DMBTR_new__c = OverdueRec[i].Total_Outstanding_INR_DMBTR_new;
        OverDueObj.Payment_Term_Zterm_new__c = OverdueRec[i].Payment_Term_Zterm_new;
        OverDueObj.Overdue_Amount_INR_ovr_amt_new__c = OverdueRec[i].Overdue_Amount_INR_ovr_amt_new;
        OverDueObj.Ageing_Days_days_new__c = OverdueRec[i].Ageing_Days_days_new;      
        OverDueObj.Excise_Invoice_exnum_new__c = OverdueRec[i].Excise_Invoice_exnum_new;      
        OverDueObj.Item_Text_sgtxt_new__c = OverdueRec[i].Item_Text_sgtxt_new;
                              
        OverdueLst.add(OverDueObj);
        system.debug('Values taken');
  }

    if (Overduelst.size()>0)
    {                     
        try
            {
                insert OverdueLst;                
                objResponse.Status = true;
                objResponse.Description = 'Record Updated';
                system.debug('Record Updated');     
            }    
       catch(exception e)
            {
                system.debug('Error');
                excep.Record_Id__c = OverdueLst[0].CustomerName_name1_new__c;
                excep.error__c = e.getmessage();
                insert excep;
                
              //objResponse.SFDCId = OverdueLst.CustName;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
            }
     }
     else
     {        
      objResponse.Status = false;
      objResponse.Description ='No Item found to update';
      system.debug('Record not Updated');
     }
   return objResponse;                                                  // this will return result.
   }
        global class Overdue_element
      {
        webservice string CustomerName_name1_new;
        webservice string Total_Outstanding_INR_DMBTR_new;
        webservice string Payment_Term_Zterm_new;
        webservice string Overdue_Amount_INR_ovr_amt_new;
        webservice string Ageing_Days_days_new;
        webservice string Excise_Invoice_exnum_new;
        webservice string Item_Text_sgtxt_new;
    }
     global class SFAResponse
    {
      //webservice Id SFDCId;       
        webservice Boolean Status; 
        webservice String Description;
    }
}

need urgently.
Please guide and help
trigger OpportunityCreator on Account (after insert) {
 
 if(Trigger.isInsert)
 {
   List<Opportunity> oCreate=new List<Opportunity>();
   List<Activity_Plan__c> actplanList=new List<Activity_Plan__c>();
   for(Account acc :Trigger.New)
   {
    
    Opportunity op=new Opportunity();
    Activity_Plan__c apobj =new  Activity_Plan__c();
    
   //op.accountId=acc.Id; 
    op.Name=acc.Name;
    op.CloseDate=Date.today();
    op.StageName='Prospecting';
    apobj.name=acc.Name;
    apobj.Object__c=acc.Name;
   
   oCreate.add(op);  
   actplanList.add(apobj);
 } 
 
 insert oCreate;
 insert actplanList;
  
 }
 

}

 
Hi All,

I am trying to check if Lead to insert is duplicate and if it is then store it in separate custom object(Duplicate_Lead__c). but in query it is returning the record i am inserting i.e. for every lead i insert this trigger is matching its fields with itself and creating duplicate record in custom object.
How to avoid this? Also i want to update a checkbox on duplicate Lead record, is it possible in same after trigger?

trigger LeadDuplicateTrigger on Lead(after insert) {
List Exleads = [Select id, name, email, MobilePhone, Program__c From Lead];
List DupLeads = new List ();
for(Lead l : Trigger.new){
for(Lead Ele : Exleads){
if(( (l.email == Ele.email) && (l.Program__c==Ele.Program__c) ) || ( (l.MobilePhone == ELe.MobilePhone) && (l.Program__c==Ele.Program__c) )){
Duplicate_Lead__c DPLead = new Duplicate_Lead__c();
DPLead.Name = ‘Duplicate Of’+’ ‘+ Ele.Name;
DPLead.Admission_Stage__c = l.Admission_Stage__c;
DPLead.Admission_Status__c = l.Admission_Status__c;
DPLead.Agency__c = l.Agency__c;
DPLead.Initial_Owner__c = l.Initial_Owner__c;
DPLead.Initial_program__c = l.Initial_program__c;
DPLead.Program__c = l.Program__c;
DPLead.Lead_State__c = l.Lead_State__c;
DPLead.Test_Score__c = l.Test_Score__c;
DupLeads.add(DPLead);
}
}
}
Insert DupLeads;
HI all,
 in @future method parameters we cannot use object as parameters.if i need to updated 10 users so it fires 10 times but the requirement is all the 10 records updated at a time means method was called only one time 
plz help  to reloslove this ,thanks in advance .

Thanks & Regards
Ravindra
Hello All,
 I’m having some trouble wrapping my head around wrapper classes (pun intended). The basics of what I’m trying to accomplish is to create a map where the key is a concatenation of two strings and the value is a wrapper list that holds multiple primitives. I have done some reading but can’t seem to get it working. The error I’m getting is line 30 “Method does not exist or incorrect signature: [List<OfficerStats_CampaignUpdate.CampAggWrperBooked>].add(String, Date, Integer, Integer, Integer)”. Can someone please help me understand what I’m doing wrong.
 
public class OfficerStats_CampaignUpdate {
    
    public list <Campaign> triggerVarNew;
    public list <Campaign> triggerVarOld;
    
	// Main Class Constructor    
    public OfficerStats_CampaignUpdate (list<Campaign> triggerContNew, list<Campaign> triggerContOld){
        triggerVarNew = triggerContNew;
        triggerVarOld = triggerContOld;
        
		// Get list of effected dates and add to set (from new and old trigger records)
        set<date> EffectedDates = new set<date>();    
        for(Campaign TriggValNew : TriggerVarNew){EffectedDates.add(Date.valueof(TriggValNew.End_Date_Time__c));}
        for(Campaign TriggValOld : TriggerVarOld){EffectedDates.add(Date.valueof(TriggValOld.End_Date_Time__c));}
        
        // get agg result list of campaings within specific dates
        list <aggregateResult> CampaignAggResult = ([SELECT Count(id) countid, sum(New_Memberships__c) Memberships, DAY_ONLY(End_Date_time__c) EventDate, sum(referral_total__c) Referrals, Booked_by__c BookedBy, GROUPING(Booked_By__c) GRPBooked  
                                                     FROM Campaign
                                                     WHERE Status = 'Completed'
                                                     AND DAY_ONLY(End_Date_Time__c) in : EffectedDates
                                                     GROUP BY CUBE (Booked_By__c, DAY_ONLY(End_Date_time__c))
                                                     ORDER BY GROUPING (Booked_by__c)]);
        
		// For each agg result line, check to see if bookedby is null, if not null add to list, then add list to    map value   
        map <string,CampAggWrperBooked> WrapperMap = new map <string,CampAggWrperBooked>();
        
        for (AggregateResult ar : CampaignAggResult){
            if(ar.get('BookedBy') != null){
            	list <CampAggWrperBooked> BookedWrapperList =  new list <CampAggWrperBooked>();
                    BookedWrapperList.add(string.valueof(ar.get('bookedBy')), date.valueof(ar.get('EventDate')), integer.valueof(ar.get('Memberships')), integer.valueof(ar.get('Referrals')), integer.valueof(ar.get('countid')));
                
            }
            
        }
        
    }
      
	// Wrapper Class
    public class CampAggWrperBooked {
        public string BookedBy;
        public date EndDate;
        Public integer SumOfMembers;
        public integer SumOfReferrals;
        Public integer EventCount;
		// Wrapper Constructor            
        public CampAggWrperBooked(string BookedByWrap, date EndDateWrap, integer SumOfMembersWrap, integer SumOfReferralsWrap, integer EventCountWrap){
            this.BookedBy = BookedByWrap;
            this.EndDate = EndDateWrap;
            this.SumOfMembers = SumOfMembersWrap;
            this.SumOfReferrals = SumOfReferralsWrap;
            this.EventCount = EventCountWrap;
        }            
    }   
}


 

Hi Everyone,

Hopefully this is dead easy,

I have got an apex class to get a list of contacts, what I need to do is then display that list of names in an email sent from apex,
I have got everything working but cannot get the list to populate if more than one contact is in the list.
 

Does anyone know how I can display the list?

...

List<Contacts> cons = [SELECT Id, Name FROM Contact WHERE......

//Further down in the code

htmlBody = htmlBody.replace('[ListOfContacts]', cons.Name);  //This needs to display the list

Thanks for your help,
Joe
Hi,
I'm looking for help with creating a formula field which will display a user name who changed value on the specific date/time type field. I can not use last modified by because record can be edited by many other users. All what I'm trying to acheve is to display user name who changed date/time on my particular field.

Thanks for any ideas.
Lukas
User-added image

As the above page showing, If i click on the button, the corresponded output should be taken to respected detailed page. But it does not taking into respected output. I tried with following Controller and VF page.
Controller :
public class Redirect_Main1 {

   public List<Account> accs { get; set; }
   public ID aid;
    
    public void access(){
        accs = [select id,name,phone,Industry from account];
        for(Account acc:accs){
            aid = acc.id;
        }
        }
       public String getAccess2(){
         return 'https://ap2.salesforce.com/'+aid;
         }
   }
 
VF Page :
<apex:page Controller="Redirect_Main1" action="{!access}">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accs}" var="a">
                <apex:column value="{!a.Id}"/>
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Phone}"/>
                <apex:column value="{!a.Industry}"/>
                <apex:column >
                    <apex:commandButton value="Click" action="{!access}"/>
                        <apex:param name="account" assignTo="{!aid}" value="{!access2}"/>
               </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
I have tried maximum up to my best, but i could not get respected output. May be i think so, i committed wrong with <apex;param> component. Please let me know where i did mistake.
Hi,

I get the below error when executing the trigger for the challenge:

Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, DynastyRoot: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.DynastyRoot: line 8, column 1: []

The challenge is:To complete this challenge, you need to add a trigger for Opportunity. The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'.
The Apex trigger must be called 'ClosedOpportunityTrigger'
With 'ClosedOpportunityTrigger' active, if an opportunity is inserted or updated with a stage of 'Closed Won', it will have a task created with the subject 'Follow Up Test Task'.
To associate the task with the opportunity, fill the 'WhatId' field with the opportunity ID.
This challenge specifically tests 200 records in one operation.


Code:

trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {

    List<Task> taskList = new List<Task>();
    
    for(Opportunity opp : Trigger.new) {
        
        //Only create Follow Up Task only once when Opp StageName is to 'Closed Won' on Create
        if(Trigger.isInsert) {
            if(Opp.StageName == 'Closed Won') {
                taskList.add(new Task(Subject = 'Follow Up Test Task', WhatId = opp.Id));
            }
        }
        
        //Only create Follow Up Task only once when Opp StageName changed to 'Closed Won' on Update
        if(Trigger.isUpdate) {
            if(Opp.StageName == 'Closed Won' 
            && Opp.StageName != Trigger.oldMap.get(opp.Id).StageName) {
                taskList.add(new Task(Subject = 'Follow Up Test Task', WhatId = opp.Id));
            }
        }       
    }

    if(taskList.size()>0) {        
        insert taskList;        
    }    
}

 
How to write @Test Class for Following Controller :

public with sharing class ReportController { 
                   
    Public Id lookupid{get;set;}
    public Question_Bank_Page__c obj1{get;set;}
    public Question_Option__c lookup;
    public List<Question_Option__c> OptionList{get;set;}
    public List<Question_Option__c> OptionList2{get;set;}
    public Question_Option__c Option{get;set;}
    private ApexPages.StandardController controller;
   
    public PageReference lookupid() {
        
        System.debug('****************Lookup id new*1************************'+obj1.Feedback__c);
        return null;
    }
    public ReportController(ApexPages.StandardController controller) {
        obj1= (Question_Bank_Page__c)controller.getRecord();
         System.debug('****************Lookup id new*2************************'+obj1.Feedback__c); 
    }
    public PageReference PassingParameter(){
        lookupid=obj1.Feedback__c;
        system.debug('++++++++++++++++LOOKUP ID++++++++++++++++++++'+lookupid);
        
        OptionList=[Select Customer_Name__c, CreatedDate, Customer_Email__c, Customer_Phone__c, Response__c, Question__r.Related_Feedback__r.Feedback_Name__c, 
        Question__r.Related_Feedback__r.Count_Question__c, Question__r.Related_Feedback__r.Feedback_Taken_by_Contact__c, Question__r.Question__c, 
        Question__r.Related_Feedback__r.CreatedDate From Question_Option__c where Question__r.Related_Feedback__c=:lookupid Limit 1];
        system.debug('++++++++++++++++++++OPTION LIST++++++++++++++++++++'+OptionList);
        
        OptionList2=[Select Customer_Name__c, CreatedDate, Response__c, Question__r.Question__c From Question_Option__c where Question__r.Related_Feedback__c=:lookupid];
        system.debug('++++++++++++++++++++OPTION LIST++++++++++++++++++++'+OptionList2);
        return null;
    }
Thanks in advance,

if(searchbyname.length()==0){
    }else{
    
     if(accname==null){
            lstAcct=[Select id,name from Account WHERE  Lock__c=:false AND name LIKE  : searchbyname  ORDER BY Name ASC];

     }else{
    lstAcct=[Select id,name from Account WHERE Sales_Mgr__c= : accname AND Lock__c=:false AND name LIKE  : searchbyname  ORDER BY Name ASC];
   }
    }


I want to execute this code with single query.help me.
Hello,

I am very new to triggers and code and will need some help with a test class.  I have found the below trigger on the web and added it to my sandbox.  I have tested it and it works great.  The trigger updates a "Contract Status" checkbox on the account if there is an active contract associated to it.  Additionally, it will set the checkbox to false if there are no active contracts. 

I am now trying to use a changset to push this into production but I think I need to create a test class to validate it in Prod.  I could be wrong with this assumption.  Can someone please help create a test class or guide me through the process to push this into production?
 
trigger AaronPTest on Contract (after insert, after Update) {
 
    Set<Id> setAccountId = new Set<Id>();  
 
    List<Account> lstToUpdate = new List<Account>();
 
    for(Contract rec : Trigger.New)
 
    {
 
        setAccountId.add(rec.AccountId);
 
    }
 
    List<Account> lstAccount = [SELECT Id,(SELECT Id FROM Contracts WHERE Contract_Status__c = true),Contract_Status__c FROM Account Where Id IN:setAccountId];
 
    for(Account acc : lstAccount)
 
    {
 
        if(acc.Contracts.size() > 0 && !acc.Contract_Status__c){
 
            acc.Contract_Status__c = true;
 
            lstToUpdate.add(acc);
 
        }
 
        else if(acc.Contracts.size() == 0 && acc.Contract_Status__c)
 
        {
 
            acc.Contract_Status__c = false;
 
            lstToUpdate.add(acc);
 
        }
 
    }
 
         Database.update(lstToUpdate);
}
 
 
Thanks,
 
Aaron
 
 
Is it possible to write a trigger on EmailMessage object? I would like to track count of the emials that have been sent from salesforce.

Thanks In Advance.
Difference In Between Apex PageMessage, PageMessages and Message VF Pages Tags in Salesforce
Hello,

I have error while deploying VF and Apex from one sandbox to another.

Component Errors
API Name: ACandidatePrint_v2
Type: Visualforce Page
Error Message: Apex class 'PrintController' does not exist

but "PrintController" is available in change set, i am deploying, but i dont get why i have this error
 
I'm new to salesforce I'm learning soql.Please explain, FOR REFERENCE and FOR VIEW difference
I have a list of old records open and closed on which there is no sharing (these records are old requests that I want to share with groups) . How can I achieve this using apex code?
I have one scenario: In a class of students starting from alfabets a A TO Z ,if i select an alfabet M....i need the student name staring with M and with their marks in ascending order...how i will achieve this by using trigger
I have two classes. in the first class account object having two lookup fields like "ship from" and "ship to". but these lookup object is one that is Address__c object. these lookup fields have different records.
totalrecords.totalamount(Address__C.Ship_To__c, Address__C.Ship_From__c, contact.type);
my requirement is how to pass these two object values to second class in this first set object parameter.
testcal(Set<Address__c>AddressSet, string type)
like below method
public static Decimal testcal(Set<Address__c>AddressSet, string type){ }
please check below my code
list<Account> someAddress = [SELECT ID, Ship_To__c, Ship_From__c FROM Account WHERE Id = :someID]; 

Set<Id> addressIds = new Set<Id>();

 for(account acc:someAddress ){ 

addressIds.add(acc.Ship_To__c); 
addressIds.add(acc.Ship_From__c); 

} 
Set<Addresss__c> addresses = new Set<Addresss__c>([SELECT Id, Other_Fields__c FROM Addresss__c WHERE ID IN :addressIds]);

 for(account acc1:newvalues()){

 TestCal(addresses, Contact.Type);

 }
i had written like this but it is not passing particular account to particlur address. i got list of address in set but account for loop how to pass particular address to particular account. 
 
why we can not do any DML on other object in Before Insert or before update Trigger
I have created a data case and i am calling that method in my test class.but the problem is i have created a list in my data class and i am assigning list to case object in my test class.So it is giving me illegal assignment from list to case error.how to solve this?
Hi
I'm new to salesforce.
Can anyone help in writing the test class.
global class tridentUpdateOverduePGLWebService
{    
    webservice static SFAResponse updateOverdue(Overdue_element[] OverdueRec) 
    {       
        //HttpRequest req = new HttpRequest();   
        //req.setHeader('Content-Type','application/x-www-form-urlencoded');
        SFAResponse objResponse = new SFAResponse();
        Exceptions__c excep = new Exceptions__c();                          // to capture web service failure exceptions.
        list<OverDue_PGL__c> OverdueLst = new list<OverDue_PGL__c>{};
        
    for (Integer i=0; i<OverdueRec.size();i++)
    {
        OverDue_PGL__c OverDueObj= new OverDue_PGL__c();
        
        OverDueObj.CustomerName_name1_new__c= OverdueRec[i].CustomerName_name1_new;
        OverDueObj.Total_Outstanding_INR_DMBTR_new__c = OverdueRec[i].Total_Outstanding_INR_DMBTR_new;
        OverDueObj.Payment_Term_Zterm_new__c = OverdueRec[i].Payment_Term_Zterm_new;
        OverDueObj.Overdue_Amount_INR_ovr_amt_new__c = OverdueRec[i].Overdue_Amount_INR_ovr_amt_new;
        OverDueObj.Ageing_Days_days_new__c = OverdueRec[i].Ageing_Days_days_new;      
        OverDueObj.Excise_Invoice_exnum_new__c = OverdueRec[i].Excise_Invoice_exnum_new;      
        OverDueObj.Item_Text_sgtxt_new__c = OverdueRec[i].Item_Text_sgtxt_new;
                              
        OverdueLst.add(OverDueObj);
        system.debug('Values taken');
  }

    if (Overduelst.size()>0)
    {                     
        try
            {
                insert OverdueLst;                
                objResponse.Status = true;
                objResponse.Description = 'Record Updated';
                system.debug('Record Updated');     
            }    
       catch(exception e)
            {
                system.debug('Error');
                excep.Record_Id__c = OverdueLst[0].CustomerName_name1_new__c;
                excep.error__c = e.getmessage();
                insert excep;
                
              //objResponse.SFDCId = OverdueLst.CustName;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
            }
     }
     else
     {        
      objResponse.Status = false;
      objResponse.Description ='No Item found to update';
      system.debug('Record not Updated');
     }
   return objResponse;                                                  // this will return result.
   }
        global class Overdue_element
      {
        webservice string CustomerName_name1_new;
        webservice string Total_Outstanding_INR_DMBTR_new;
        webservice string Payment_Term_Zterm_new;
        webservice string Overdue_Amount_INR_ovr_amt_new;
        webservice string Ageing_Days_days_new;
        webservice string Excise_Invoice_exnum_new;
        webservice string Item_Text_sgtxt_new;
    }
     global class SFAResponse
    {
      //webservice Id SFDCId;       
        webservice Boolean Status; 
        webservice String Description;
    }
}

need urgently.
Please guide and help
create VF page for importing the excel sheet to Salesforce. 
 
Please don’t use the Apex and everything should in VF page.


Note: If CSV file having Id , it should update the old record's .
If don't have an Id it's should create a new record in salesforce.


Thanks In Advance.
Hi,

   i'm trying to get the records from external third party application to salesforce case object.
   i'm getting the records from the below REST callout now i'm trying to develop the Aex batch job but i'm stucked at execute() method
  how to develop the execute() based on REST callout

   for the rest callout see below code

  @future (callout=true) global static void getIncident(String subject){
Http http = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
string text = subject;
req.setEndpoint('https://myinstance.service-now.com/api/now/table/incident?sysparm_fields=impact%2Cincident_state%2Cshort_description%2Csys_id%2Ccontact_type&sysparm_limit=2&u_sftype=true');
req.setMethod('GET'); req.setHeader('Content-Type', 'application/json');
String username = 'admin';
String password = 'abcd';
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
res = http.send(req); System.debug('jsonrResult :' + res.getBody());
Deserialization.ResponseResult res1= (Deserialization.ResponseResult)JSON.deserialize(res.getBody(), Deserialization.ResponseResult.class); System.debug('Results == :' + res1 );
List<Case> casesToUpsert = new List<Case>();
for(Deserialization d : res1.result ){
Case c = new Case();
c.Priority = d.impact;
c.Status = d.incident_state;
c.Subject = d.short_description;
c.ServiceNowId__c = d.sys_id;
c.Origin = d.contact_type;
casesToUpsert.add(c);
} system.debug('Cases to UPsert ::: ' +casesToUpsert);
if(casesToUpsert.size()>0){
Database.upsert(casesToUpsert,false) ;
}
How to develop my Execute() based on my REST callout class

this is my batach class
global class ServiveNowBatch implements Database.Batchable, Database.AllowsCallouts{
global Database.QueryLocator start(Database.BatchableContext BC){
String query = 'SELECT Id, Priority, Status, Subject, ServiceNowId__c, Origin FROM Case WHERE Status=1 LIMIT 50';
return Database.getQueryLocator(query);
} global void execute(Database.BatchableContext BC, List<Case> scope){

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

help me to develop the execute()

Thanks In Advance
Hello. First time poster. I feel like this is an easy problem but I seem to be stuck at actually updating the records. So essentially, I need to create a class that will, for each account in system, update Contact_Email_List__c (which I have created) with the list of email ids (comma separated) from Contact related list of account.
public class EmailListMaker {   
    public void EmailListMaker(){
        List<String> emails = new List<String>();
        for (Contact em : [Select Email FROM Contact ORDER BY Name]){
            emails.add(em.Email);
        }
        String emailList = String.join(emails, ', ');           
        upsert emailList Account.Fields.Contact_Email_List__c;
    }
}

It gives the following problem, "DML requires SObject or SObject list type: String". I feel like I need to transfer the string to a SObject but I can't seem to figure out how. 



 
Hi All,

I am writing a basic program by using selectcheckboxes tag. But Once i click the button and panel is rerendered. the below is list is not displaying the selected values. what i m missing?


VF Page
 
<apex:page controller="selectcheckcon">
    <Apex:form>
    <apex:pageBlock title="Select checkboxes">
        <apex:pageMessages  id="page" />
        <apex:pageBlockSection title="Demo of select checkboxes">
            <apex:outputLabel value="Select the countries"/>
            <apex:selectCheckboxes value="{!countries}">
                <apex:selectOptions value="{!items}">
                </apex:selectOptions>
            </apex:selectCheckboxes>
        </apex:pageBlockSection>
        
       
        <apex:pageBlockButtons>
            <apex:commandButton action="{!test}" rerender="out,page" status="status" value="Click me!"></apex:commandButton>
        </apex:pageBlockButtons>
        
        
    </apex:pageBlock>
</Apex:form>

 <apex:outputPanel id="out">
                <apex:actionStatus startText="Fetching Data..."  id="status">
                <apex:dataList value="{!countries}" var="con">
                    {!con}
                </apex:dataList>
                </apex:actionStatus>
            </apex:outputPanel>
</apex:page>

Controller class:
 
public class selectcheckcon {
    
    public String[] countries = new String[]{};
    
    
    public String[] getcountries(){
        
        return countries;
    }
    
    public void setcountries(string[] country){
        
        countries = country;
    }
    
    
    public selectcheckcon(){
        
       
    }
    
    public list<selectoption> getItems(){
        
        list<selectoption> options =  new list<SelectOption>();
        
        options.add(new SelectOption('USA','USA'));
        options.add(new SelectOption('INDIA','INDIA'));
        options.add(new SelectOption('AUS','AUS'));
    
        return options;
    }
    
    public pageReference test(){
        
        return null;
    }

}

 
Hello All,
I have a custom childobject(Reservation) and a  lookup parent object(User). I am trying to prepopulate the look up field with the current user attributes. My lookup field accepts the values in the form of "UserFirstName UserLastName". So I tried to invoke the default values through constructor like below.

VisualForce Page:
<apex:page standardController="Reservation__c" extensions="ReservationClass" >
    <apex:sectionHeader title="New Reservation" />
    <apex:form >
       <apex:pageBlock>
        <apex:pageBlockSection >
            <apex:inputField value="{!order.User__c}"/>
  </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>
Custom Controller
public class ReservationClass {
    public Reservation__c res{get; set;}
    public String FName = UserInfo.getFirstName()  ;
    public String Lname = UserInfo.getLastName();
    public string UserName = FName + ' ' + Lname ;

public ReservationClass (ApexPages.StandardController stdController) {
    res = (Reservation__c) stdController.getRecord();
    res.User__c =  userName ;
  }
}
The above code throws an error
"Invalid id: Shravya Rama
 An unexpected error has occurred. Your development organization has been notified."

 
 When I select accname and click the FIND button i need to display those name records . There is no error , but I didn't get the records. Plz check and suggest me where is the problem and also i nned to display these records in another VF page. How it is ? I think Using page reference  ri8 ?


VF code:

<apex:page controller="accountfiltercon">
    <apex:form >
        <apex:pageBlock>
          <apex:pageBlockSection title="select picklist field value">
    <apex:selectList size="1" value="{!selectedname}"> 
        <apex:selectOptions value="{!selectedaccnamefields}"/>  
    </apex:selectList>
      </apex:pageBlockSection>  
         <apex:pageBlockSection title="List of Account Records">
             <apex:pageBlockTable value="{!arecs}" var="item">
                 <apex:column value="{!item.id}"/>
                 <apex:column value="{!item.name}"/>
                 <apex:column value="{!item.billingcity}"/>
                 <apex:column value="{!item.phone}"/>
             </apex:pageBlockTable>
             <!--apex:pageBlockButtons-->
                 <apex:commandButton value="FIND" action="{!pf}"/>
             <!--/apex:pageBlockButtons-->
         </apex:pageBlockSection>   
     </apex:pageBlock>       
    </apex:form>
</apex:page>

Apex Code:

public class accountfiltercon {
    Public string selectedname{get;set;}
    public list<account> arecs{get;set;}
        Public List<Selectoption> getselectedaccnamefields(){
            List<Selectoption> pickname = new List<selectoption>();
            pickname.add(new selectOption('', '- None -'));
            for(Account acc :[SELECT id,name,phone,type,industry,billingcity FROM Account]){
            pickname.add(new selectoption(acc.id,acc.name));
            }
            return pickname; 
        }
    public void pf(){
        list<list<sobject>> lf=[find:selectedname in all fields returning account(id,name,billingcity,phone)];
    
    
    arecs=[select id,name,billingcity,phone from account where name=:selectedname];
    }
}
trigger OpportunityCreator on Account (after insert) {
 
 if(Trigger.isInsert)
 {
   List<Opportunity> oCreate=new List<Opportunity>();
   List<Activity_Plan__c> actplanList=new List<Activity_Plan__c>();
   for(Account acc :Trigger.New)
   {
    
    Opportunity op=new Opportunity();
    Activity_Plan__c apobj =new  Activity_Plan__c();
    
   //op.accountId=acc.Id; 
    op.Name=acc.Name;
    op.CloseDate=Date.today();
    op.StageName='Prospecting';
    apobj.name=acc.Name;
    apobj.Object__c=acc.Name;
   
   oCreate.add(op);  
   actplanList.add(apobj);
 } 
 
 insert oCreate;
 insert actplanList;
  
 }
 

}

 
I have a situation as below.

I have an object OBJECT 1 and couple of fields in it. Two Fields among them are Field1 [Check Box] and Field2 [Date Field]. When I create a new record for OBJECT 1, I want Field2 to be read only and on checking the Field 1 to true, I want Field 2 to be visible and Editable. I tried using WF rules but It didn't work as the rules applied only after saving the record. I want while filling the details while creating new record. 
Flow would be,
1: Click New Record Button on Object 1
2: You see Field 2 is read only.
3: You check Field 1 to true
4: And you want Field 2 to be visible and editable now.
5: User picks the date in Field 2 and saves the record.

I beleive it is possible using Triggers But I want help in creating and achieveing using Triggers. I am asking this as I am two weeks old in Salesforce :-)


Regards,
Abhi
Hi All,

I have created onebatch apex as mentioend below.I want to scheduled the class everday midnight automatically.Can any one help me to create a Automatic scheduled class.

BatchApex:
global class OpportunitySplit implements Database.Batchable<Sobject>{
    global OpportunitySplit(){
    }
        //START Method
        global Database.QueryLocator start(Database.BatchableContext BC){
        DateTime dt = DateTime.now().addHours(-24);
        String query = 'SELECT Id,name,Total_Account_Manager__c,Total_Channel_Manager__c FROM Opportunity WHERE LastModifiedDate = ToDay ';
        return Database.getQueryLocator(query);
        }
        //execute Method
        global void execute(Database.BatchableContext BC,List<Opportunity> lstOpp){

            Map<Id,Integer> MapIdOppTosumAcMngr = new Map<Id,Integer>();
            Map<Id,Integer> MapIdOppTosumChMgnr = new Map<Id,Integer>();
            Map<Id,Opportunity> MapOpportunity = new Map<Id,Opportunity>(lstOpp);
            Opportunity objOppToUpdate;
            
            List<Opportunity> lstOppToUpdate = new List<Opportunity>();           
            for(OpportunitySplit objOppSplit : [SELECT Id, Role_Name__c, OpportunityId FROM OpportunitySplit WHERE Role_Name__c IN (' Account Manager',' Channel Manager') AND OpportunityId IN: MapOpportunity.keySet()]){                                     
                system.debug('====objOppSplit===='+objOppSplit);
                
                if(objOppSplit.Role_Name__c == 'Account Manager'){
                   
                    MapIdOppTosumAcMngr.put(objOppSplit.OpportunityId, MapIdOppTosumAcMngr.containsKey(objOppSplit.OpportunityId) ? (MapIdOppTosumAcMngr.get(objOppSplit.OpportunityId)+1): 1);
                }
                else{
                      
                     MapIdOppTosumChMgnr.put(objOppSplit.OpportunityId,MapIdOppTosumChMgnr.containsKey(objOppSplit.OpportunityId) ? (MapIdOppTosumChMgnr.get(objOppSplit.OpportunityId)+1): 1);
                    }
            }
            for(Opportunity objOpp : MapOpportunity.values()){
                objOppToUpdate = new Opportunity(Id = objOpp.Id);
                objOppToUpdate .Total_Account_Manager__c = MapIdOppTosumAcMngr.containsKey(objOpp.Id) ? MapIdOppTosumAcMngr.get(objOpp.Id) : 0;
                objOppToUpdate .Total_Channel_Manager__c = MapIdOppTosumChMgnr.containsKey(objOpp.Id) ? MapIdOppTosumChMgnr.get(objOpp.Id) : 0;
                
                lstOppToUpdate.add(objOppToUpdate );
            
                system.debug('====objOppToUpdate===='+objOppToUpdate);
            }
                if(!lstOppToUpdate.isEmpty())
                    
                    update lstOppToUpdate;         
        }
         //finish Method
                global void finish(Database.BatchableContext BC){
                    
                }
}

Thanks in Advance
Hello,

 I am writing a code where if checkbox is checked then mail will send to desired user otherwise it will show an error "Please select checkbox". Can i get javascript for this?

<apex:pageBlockTable value="{!searchResults}" var="accWrap" id="table"">
 <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
<apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/> 
<apex:column colspan="5" value="{!accWrap.acc.Name}" />
<apex:column colspan="5" value="{!accWrap.acc.Email}" />
<apex:column colspan="5" value="{!accWrap.acc.Phone}" />
</apex:pageBlockTable>
Current workflow rule:
NOT( ISBLANK(Employee_Name__c) ) &&  Send_SMS__c  = True &&  Subject  <> 'Job Centre Workshop'

Would like to send out sms every time a person is added to an event.