• Vadim Rudkov
  • NEWBIE
  • 60 Points
  • Member since 2013

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 18
    Replies

Hi experts

 

I just started working in a salesforce company as a developer.

This is my trigger.I have a trigger on case object which was written by my old developer,

 

http://wiki.developerforce.com/page/Autocreating_Contacts_From_Web_To_Case

This is what he used.

 

It works fine now.I should include new use case in this trigger where i have to also check with web phone number.

If email match is not found then i should try to find match on contact phone number.If more than one contact has the phone number, pick the one with the most recent created date and  associate the Case with that contact.

 

I dont understand how i can get this.Please help.!!!

 

Hi All,

 

I am new to Apex Programming.

 

I am trying to fetch the required fields from Account Object. Person Acccount is enabled in our Client's Sandbox instance. I am trying to fetch the reuired fields using code in the discussion mentioned below (Is Nillable Code):

 

http://boards.developerforce.com/t5/Apex-Code-Development/Detect-a-required-field-in-Apex/m-p/152845#M21730

 

But the Account Name(Standard) field which is required at the field level is not listed at all for me.When I created a Custom Field which is marked Required at the field level, that corresponding required field is listed properly.

 

To fetch the Required fields for Person Account I called the Describe method from the Contact object. Last Name was listed by this method. 

 

But when I use the same code in my Developer instance where Person Account is not enabled then the Account Name is listed as Required field.

 

Any help is greatly appreciated!!!

 

Thanks,

Raghu

 

Is this happening becase Person Account is enabled in our Client's instance?

Hi all,
I am sending a single email from Apex code. Although I do not have any erros, the email doesn't get sent. As you can see from the code snippet, it is pretty uncomplicated. Wanted to do a test send before I get to the complicated stuff. There are not error messages but the email doesn't get sent. Any ideas???

Messaging.Singleemailmessage mail = new Messaging.Singleemailmessage();
mail.setToAddresses(new String[] {'terence1122@gmail.com'});
mail.setReplyTo('noreply@privatebudget.com');
mail.setSenderDisplayName('Private Budget App');
mail.setSubject('Private Budget records for ' + Date.today().month() + ' ' + Date.today().year());
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setPlainTextBody('This is a test');
system.debug('@@@@ sendEmail - mail : ' + mail);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

The sytem debug produces the following
@@@@ sendEmail - mail : Messaging.SingleEmailMessage[getBccAddresses=null;getCcAddresses=null;getCharset=null;getDocumentAttachments=null;getFileAttachments=null;getHtmlBody=null;getInReplyTo=null;getOrgWideEmailAddressId=null;getPlainTextBody=This is a test;getReferences=null;getTargetObjectId=null;getTemplateId=null;getToAddresses=(terence1122@gmail.com);getWhatId=null;isUserMail=false;]

I am working on the dev org and executing the class which sends the mail from execute anonymous. 
Thanks
I want to print some msg , 2 miniutes after scheduling ?

public class sceduleUpdate implements Schedulable{
    
public void UpdateStatus(){

   
  sceduleUpdate su = new sceduleUpdate();
   
  String day = string.valueOf(system.now().day());
             String month = string.valueOf(system.now().month());
         String hour = string.valueOf(system.now().hour());
         String minute = string.valueOf(system.now().minute() + 2);
         String second = string.valueOf(system.now().second());
         String year = string.valueOf(system.now().year());

 
  String JobName = 'Update';
         String strSchedule = second +' ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
       
  string curMinute = string.valueOf(system.now().minute());
                System.debug('Job Schedule for Execution at '+hour+' :'+curMinute+' '+Minute);      



  System.schedule(JobName, strSchedule, su);
                System.debug('after schedule');
}

public void execute(SchedulableContext sc){
    
         String hour = string.valueOf(system.now().hour());
         String minute = string.valueOf(system.now().minute());
            system.debug('Hi code have been executed '+hour+' :'+minute+'');
   
       
    }


}
------------------------------------------------------------------
another class



@istest
public class callSchedule {
     public static testmethod void main(){
       
        sceduleUpdate Obj = new sceduleUpdate();
        obj.updateStatus();
 
     }
}
we have total_sum__c in account and sum__c in contact
i want a trigger that will calculate the sum of all the contacts and display the total sum in total_sum__c

this is only for insert trigger , not working

trigger rollupsun on Contact (after insert,after delete, after update)
{
set<id> conid = new set<id>();

    if(Trigger.isInsert|| Trigger.isUpdate)
        for(contact c: trigger.new)
         conid.add(c.accountid);
       
        
        Account a =new account();
    for (AggregateResult ar : [select sum(sum__c) total from contact where Id in : conid  group by id])
    {
        a.Total_Sum__c = (decimal)ar.get('total');
    }
}

I have a problem with my testing and I'm getting error of Too many SOQL queries: 101. I noticed that I have many For-loops in my files but this one is the worst because it's runned almost in every file. I would like to know how could I get these queries together and simplified.  I'm not so familiar with SOQL, and noticed that I can't create JOIN with these three BusinessHours + Account + Contract.

 

     // Get the default business hours
        BusinessHours defaultHours = [select Id from BusinessHours where IsDefault=true];
        
        Account costCenter = [select Id, Name, Account_Top_Parent__c from Account where Id =: relatedSetup.Cost_Center__c];
        System.Debug('CC Id: ' + costCenter.Id);
        System.Debug('CC Name: ' + costCenter.Name);
        
        Account mainAccount = [select Id, Name, Videra_Account_Number__c from Account where Id =: costCenter.Account_Top_Parent__c];
        System.Debug('MA Id: ' + mainAccount.Id);
        System.Debug('MA Name: ' + mainAccount.Name);
        
        Contract contract = [select Id, AccountNumber__c, Business_Hours__c, Status from Contract where AccountNumber__c =: mainAccount.HLD_Account_Number__c];
        System.Debug('Contract Id: ' + contract.Id);
        System.Debug('Contract Business Hrs: ' + contract.Business_Hours__c);
        System.Debug('Contract Acc Number: ' + contract.AccountNumber__c);

 

 

 

  • August 02, 2013
  • Like
  • 0

I have wrote some code for my page.

 

My page have  500 records.Each record different field values.I want to show the count of each record basis of field values.

 

So On page load, In controller I have  iterate each record and build two(values have taken from 2 different objects) dynamic soql and get the result count.But it exceed 50 th record it throws error(Query exception 101 soql queries).

 

How to avoid this in page load?Its urgent

 

 

 

 

Hi,

 

I need to send Remainder mails to users based on specific period of time using apex ccode.Could you please help me on this. As i am new to this sales force idont have idea.

 

Please share sample code or links which will be useful to complete my Task.

 

 

Regards

Lakshmi Prasanna.

Hi,

Iam trying to find a way to check if a sales rep is connected to company's VPN from Salesforce.com. Is there a way we can do that. Iam exposing one of our internal application within Salesforce and for accessing that app, the user needs to be in VPN. I need to first check if the user logged in to VPN and if not, I want to display a message asking him to log in to VPN. 

Appreciate your help

JP.

Hi experts

 

I just started working in a salesforce company as a developer.

This is my trigger.I have a trigger on case object which was written by my old developer,

 

http://wiki.developerforce.com/page/Autocreating_Contacts_From_Web_To_Case

This is what he used.

 

It works fine now.I should include new use case in this trigger where i have to also check with web phone number.

If email match is not found then i should try to find match on contact phone number.If more than one contact has the phone number, pick the one with the most recent created date and  associate the Case with that contact.

 

I dont understand how i can get this.Please help.!!!

 

Hi,

 

My first attempt at batching and I am coming up with an error. I have referenced other similar issues but I'm not getting anywhere.

 

Calling from a trigger I have a set of IDs that translate directly to User.Id.

 

 

Trigger:

trigger AddCurrtoTrans on lmscons__Transcript__c (after insert, after update) {
	    /*
	    	adds a curriculum to a transcript when transcript is created
	        need to call a future class to enter a new curriculum assignment record 
	        for each new user added in a given trigger context.
       */

	set<id> setTrainees = new set<id>();
	//string strQuery = '';

	if (trigger.isInsert || trigger.isupdate)
	{
		// filter thoruugh the transcripts to find IDs (future classes cannot take cObjects)
		for (lmscons__Transcript__c lT : trigger.new)
		{
	        setTrainees.add(lT.lmscons__Trainee__c);
	    }
	    system.debug('setTrainees ' + setTrainees);
		//CreateOnBoarding.addCurrtoTrans(setTrainees);
	    //list<User> listTrainees = new list<User>([Select id from User where id in :setTrainees]);

		//RunAssignmentRulesBatch Create = new RunAssignmentRulesBatch(strQuery);
		database.executeBatch(new RunAssignmentRulesBatch(setTrainees), 100 );
	}
}

 

 

Class

global class RunAssignmentRulesBatch implements Database.Batchable<sObject>, Database.Stateful, Database.AllowsCallouts {

	global final string strQuery;
	global final set<id> Trainees;

	public RunAssignmentRulesBatch(set<id> Trainees)
	{
		system.debug('Trainees '+Trainees);
		if (system.Test.isRunningTest()) {
			this.strQuery = 'SELECT Id FROM User WHERE Id = \'' + UserInfo.getUserId() + '\' LIMIT 1';
		}
		else
		{
			strQuery = 'SELECT u.Id, u.Department, u.Division from User u where u.ID in :Trainees and u.ContractorY_N__c = FALSE and u.IsActive=TRUE';
			system.debug('strQuery constructor'+strQuery);
		}
	}

	global Database.QueryLocator start(Database.BatchableContext BC) {
		system.debug('strQuery start'+strQuery);
		return  Database.getQueryLocator(strQuery);
	}

	global void finish(Database.BatchableContext BC) {
	}

	global void execute(Database.BatchableContext BC, list<User> Trainees) {
		system.debug('Trainees in execute '+Trainees);
		addAssignmentBatch(BC, Trainees);
	}
    global void addAssignmentBatch(Database.BatchableContext BC, list<User> Trainees)
    {
        /*

            curr.ass requires:
                curriculum | this will be determined by the lmscons__Transcript__c.lmscons__Trainee__c
                transcript | this is passed in by the trigger
                trainess | this is passed in by the trigger
                Trainees to transcript relationship | this is passed in by the trigger

            Analytic Development On-boarding Program
            Pre-Sales On-boarding Program (retired)
            Product Development On-boarding Program
            Professional Services (PS) On-boarding Program
            PTO On-boarding Program
            PTO On-boarding Program - General
            Quality Assurance On-boarding Program
            Sales On-boarding Program
            Scores Delivery On-boarding Program

        */

        system.debug('Trainees in addAssignmentBatch '+Trainees);

        for (User trainee: Trainees)

 

logfile

14:16:47.047 (47406000)|METHOD_EXIT|[1]|RunAssignmentRulesBatch
14:16:47.047 (47640000)|SYSTEM_METHOD_ENTRY|[21]|System.debug(ANY)
14:16:47.047 (47698000)|USER_DEBUG|[21]|DEBUG|strQuery startSELECT u.Id, u.Department, u.Division from User u where u.ID in :Trainees and u.IsActive=TRUE
14:16:47.047 (47712000)|SYSTEM_METHOD_EXIT|[21]|System.debug(ANY)
14:16:47.047 (47739000)|SYSTEM_METHOD_ENTRY|[22]|Database.getQueryLocator(String)
14:16:47.049 (49583000)|SOQL_EXECUTE_BEGIN|[22]|Aggregations:0|SELECT u.Id, u.Department, u.Division from User u 
14:16:47.051 (51344000)|EXCEPTION_THROWN|[22]|System.NullPointerException: Attempt to de-reference a null object
14:16:47.051 (51562000)|SYSTEM_METHOD_EXIT|[22]|Database.getQueryLocator(String)
14:16:47.051 (51628000)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

anyone can help me with this batch, the problem is that I'm not finding the records of the entity EventRelation to update the records of the other entity.

 

Thanks,

 

global void execute(Database.BatchableContext BC, List<sObject> scope){
// Create a map for the chunk of records passed into method.
Map<ID, Informe_icex__c> iMap = new Map<ID, Informe_icex__c>((List<Informe_icex__c>)scope);
System.Debug('iMap Records : ' + iMap);

List<EventRelation> eRList = [SELECT Id,response,Status,RelationId,EventId,RespondedDate FROM EventRelation WHERE Id IN
:iMap.keySet()];
System.Debug('EventRelation Records 1 : ' + eRList);

List<Informe_icex__c> listToBeUpdated = new List<Informe_icex__c>();
for(Informe_icex__c i : iMap.values()){
System.Debug('EventRelation Records 2 : ' + eRList);
System.Debug('Informe_Icex Records: ' + i);
if(!eRList.isEmpty()){
i.Comentarios_Invitados__c = eRList[0].response;
i.Estado_Invitado__c = eRList[0].status;
listToBeUpdated.add(i);

}
}
if(listToBeUpdated.size()>0){
update listToBeUpdated;

}

  • July 16, 2013
  • Like
  • 0

Hello All,

 

Our support agents our requesting a "Custom Button" on the Case E-Mail template.  What they would like is the ability to click a "Send E-Mail and Close Case" button.  Once clicked the e-mail would be sent to the customer and the agent would be redirected to the Case Close page.

 

Has anyone tackled a similar request?  I am a novice to Apex Code and Visualforce, so any assistance is greatly appreciated.

 

Thanks,

Hi All,

 

I am new to Apex Programming.

 

I am trying to fetch the required fields from Account Object. Person Acccount is enabled in our Client's Sandbox instance. I am trying to fetch the reuired fields using code in the discussion mentioned below (Is Nillable Code):

 

http://boards.developerforce.com/t5/Apex-Code-Development/Detect-a-required-field-in-Apex/m-p/152845#M21730

 

But the Account Name(Standard) field which is required at the field level is not listed at all for me.When I created a Custom Field which is marked Required at the field level, that corresponding required field is listed properly.

 

To fetch the Required fields for Person Account I called the Describe method from the Contact object. Last Name was listed by this method. 

 

But when I use the same code in my Developer instance where Person Account is not enabled then the Account Name is listed as Required field.

 

Any help is greatly appreciated!!!

 

Thanks,

Raghu

 

Is this happening becase Person Account is enabled in our Client's instance?