• HelloSan
  • NEWBIE
  • 120 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 54
    Questions
  • 26
    Replies
I want to calculate chat time i.e chat start time and chat window close time if it is greater than 5 mins then i must pop up chat survey. How can this be achieved?
I must calculate chat start time and if the chat continues more than 5 mins and will popup a survey link in the chat. If the chat time is greater than 5 minutes the link for survey should popup in the chatter.
i want to update the data from excel to salesforce,i want to know how vbscript going to help in updating data from excel to salesforce object automatically
i need a query to fetch records from account object where program__c(program__c is a picklist field on account form) field is equals to X,Y,Z
the qurey is as similar as 
eg : global database.querylocator start(Database.BatchableContext BC){ 
                query = 'select id,Program__c from Account where program__c';
trigger UpdateOpptyOnServiceupdate on Servic__c (after insert, after update)
{
Set<Id> oppid = new Set<Id>();
Map<Id,List<Service __c>> mpoppservice=new Map<Id,List<Service __c>>();
List<Opportunity> updatelist =  new list<Opportunity>();
String str =  null;
for(Service__c s:trigger.new)
{
if(s.Opportunity__c != null){
oppid.add(s.Opportunity__c);
}
List<Opportunity> opplist = [Select id,ServiceIncrement__c ,(Select id,Expired _Years__c from Service__r) From Opportunity where Id IN:oppid];

For(Opportunity opp:opplist)
{
mpoppservice.put(opp.id,opp. Service__r);   
}
for(Opportunity oppty:opplist)
{
Integer i = 0;   
Id temp = oppty.id;
List<Service __c>  slist= mpoppservice.get(temp);   
if(slist.size()!=0)
{
for(Service__c s1: slist)
{
str =s1. Expired _Years__c;
if(str != '<1' && str != null)   
{
i = 2;
}
if(i==2)   
{
oppty.ServiceIncrement __c = 'Yes';   
}
else
{
oppty.ServiceIncrement __c = 'No';   
}   
updatelist.add(oppty);   
}   
}
}
      try
        {
          update updatelist;
         }catch(Exception e) 
         { 
          for(Service__c s : trigger.new)
          {
          Id opid= s.Opportunity__c;
          Opportunity op = [select id,name from Opportunity where id=:opid];
          s.addError('“Updating opportunity associated to this service,but could not because the required fields are missing on opportunity”');
          }  
       }
 }
}
trigger UpdateOpptyOnServiceupdate on Servic__c (after insert, after update)
{
Set<Id> oppid = new Set<Id>();
Map<Id,List<Service __c>> mpoppservice=new Map<Id,List<Service __c>>();
List<Opportunity> updatelist =  new list<Opportunity>();
String str =  null;
for(Service__c s:trigger.new)
{
if(s.Opportunity__c != null){
oppid.add(s.Opportunity__c);
}
List<Opportunity> opplist = [Select id,ServiceIncrement__c ,(Select id,Expired _Years__c from Service__r) From Opportunity where Id IN:oppid];

For(Opportunity opp:opplist)
{
mpoppservice.put(opp.id,opp. Service__r);   
}
for(Opportunity oppty:opplist)
{
Integer i = 0;   
Id temp = oppty.id;
List<Service __c>  slist= mpoppservice.get(temp);   
if(slist.size()!=0)
{
for(Service__c s1: slist)
{
str =s1. Expired _Years__c;
if(str != '<1' && str != null)   
{
i = 2;
}
if(i==2)   
{
oppty.ServiceIncement __c = 'Yes';   
}
else
{
oppty.ServiceIncement __c = 'No';   
}   
updatelist.add(oppty);   
}   
}
}
      try
        {
          update updatelist;
         }catch(Exception e) 
         { 
          for(Service__c s : trigger.new)
          {
          Id opid= s.Opportunity__c;
          Opportunity op = [select id,name from Opportunity where id=:opid];
          s.addError('“Updating opportunity associated to this service,but could not because the required fields are missing on opportunity”');
          }  
       }
 }
}
Trigger testOrder on Order (after insert,after update,after delete)
{
//logic
update newopplist //newopplist is list of opportunities
}
How to handle  the exception on  update newopplist and throw customize error message

 
trigger UpdateOpptyOnServiceupdate on Servic__c (after insert, after update)
{
Set<Id> oppid = new Set<Id>();
Map<Id,List<Service __c>> mpoppservice=new Map<Id,List<Service __c>>();
List<Opportunity> updatelist =  new list<Opportunity>();
String str =  null;
for(Service__c s:trigger.new)
{
if(s.Opportunity__c != null){
oppid.add(s.Opportunity__c);
}
List<Opportunity> opplist = [Select id,ServiceIncrement__c ,(Select id,Expired _Years__c from Service__r) From Opportunity where Id IN:oppid];

For(Opportunity opp:opplist)
{
mpoppservice.put(opp.id,opp. Service__r);   
}
for(Opportunity oppty:opplist)
{
Integer i = 0;   
Id temp = oppty.id;
List<Service __c>  slist= mpoppservice.get(temp);   
if(slist.size()!=0)
{
for(Service__c s1: slist)
{
str =s1. Expired _Years__c;
if(str != '<1' && str != null)   
{
i = 2;
}
if(i==2)   
{
oppty.ServiceIncrement __c = 'Yes';   
}
else
{
oppty.ServiceIncrement __c = 'No';   
}   
updatelist.add(oppty);   
}   
}
}
      try
        {
          update updatelist;
         }catch(Exception e) 
         { 
          for(Service__c s : trigger.new)
          {
          Id opid= s.Opportunity__c;
          Opportunity op = [select id,name from Opportunity where id=:opid];
          s.addError('“Updating opportunity associated to this service,but could not because the required fields are missing on opportunity”');
          }  
       }
 }
}
trigger UpdateOpptyOnServiceupdate on Servic__c (after insert, after update)
{
Set<Id> oppid = new Set<Id>();
Map<Id,List<Service __c>> mpoppservice=new Map<Id,List<Service __c>>();
List<Opportunity> updatelist =  new list<Opportunity>();
String str =  null;
for(Service__c s:trigger.new)
{
if(s.Opportunity__c != null){
oppid.add(s.Opportunity__c);
}
List<Opportunity> opplist = [Select id,ServiceIncrement__c ,(Select id,Expired _Years__c from Service__r) From Opportunity where Id IN:oppid];

For(Opportunity opp:opplist)
{
mpoppservice.put(opp.id,opp. Service__r);   
}
for(Opportunity oppty:opplist)
{
Integer i = 0;   
Id temp = oppty.id;
List<Service __c>  slist= mpoppservice.get(temp);   
if(slist.size()!=0)
{
for(Service__c s1: slist)
{
str =s1. Expired _Years__c;
if(str != '<1' && str != null)   
{
i = 2;
}
if(i==2)   
{
oppty.ServiceIncement __c = 'Yes';   
}
else
{
oppty.ServiceIncement __c = 'No';   
}   
updatelist.add(oppty);   
}   
}
}
      try
        {
          update updatelist;
         }catch(Exception e) 
         { 
          for(Service__c s : trigger.new)
          {
          Id opid= s.Opportunity__c;
          Opportunity op = [select id,name from Opportunity where id=:opid];
          s.addError('“Updating opportunity associated to this service,but could not because the required fields are missing on opportunity”');
          }  
       }
 }
}
for(Account acc : acclist)
{
    for(Opportunity opp1 : opplist)
    {
        if(acc.id == opp1.AccountId)
        {
            maptest.put(acc.id,opp1.Opportunity);
        }
    }
}

global class BatchService implements Database.Batchable<SObject>, Database.Stateful{
    global String query;
    
    global database.querylocator start(Database.BatchableContext BC){ 
                query = 'select id,Accountid,RecordtypeId,Service_Type__c,Total_Amount__c,Initial_Amount__c  from Opportunity';
       return Database.getQueryLocator(query); 
    }
    global void execute(Database.BatchableContext BC, List<Opportunity> Opplist){  
    
       string str = null;
Set<Id> accountids = new Set<Id>();
Map<Id,String> mapacctname = new Map<id,String>();
Map<Id,String> mpstype = new Map<id,String>();
             for(opportunity opp:Opplist)
             {
                 mpstype.put(opp.id,opp.Service_Type__c);
             }

 for(opportunity opp1:Opplist)
{
    
if(opp1!=null)
{
if(opp1.accountId != null)
{
accountids.add(oppty.accountid);
}
List<Account> accounts = [Select id,name from Account where id in:accountids]; 
for(Account acc : accounts)
{
mapacctname.put(acc.id,acc.name);
}
RecordType r=[select id,name from RecordType Where id =:opp1.recordTypeId];
str = mapacctname.get(opp1.AccountId)+' '+mpstype.get(opp1.id)+' '+r.name;
list<Service__c> slist=[SELECT id,name,Accountname__c,Service_A1_Total_Amount__c,Service_A2_Total_Amount__c,Service_A3_Total_Amount__c,Service_A4_Total_Amount__c,Service_Type_Amount__c,Initial_A1_Amount__c,Initial_A2_Amount__c,Initial_A3_Amount__c,Initial_A4_Amount__c,Service_Type_Amount__c,Initial_Type_Amount__c,Service_Type__c from Service__c where name =:str];
   System.debug('before checking the slist  records');
    if(slist.size()==0)
    {
Service__c s=new Service__c();
s.name = mapacctname.get(opp1.AccountId)+' '+mpstype.get(opp1.id)+' '+r.name;
s.Accountname__c = opp1.AccountId;
s.Record_Type__c = r.name;
s.Service_Type__c = opp1.Service_Type__c;
        
if(opp1.Service_Type__c == 'A1')
{
s.Service_A1_Total_Amount__c = opp1.Total_Amount__c;
s.Initial_A1_Amount__c  = opp1.Initial_Amount__c; 
s.Service_Type_Amount__c = opp1.Total_Amount__c; 
s.Initial_Type_Amount__c = opp1.Initial_Amount__c;    
}
else if(opp1.Service_Type__c == 'A2')
{
s.Service_A2_Total_Amount__c = opp1.Total_Amount__c;
s.Initial_A2_Amount__c  = opp1.Initial_Amount__c; 
s.Service_Type_Amount__c = opp1.Total_Amount__c; 
s.Initial_Type_Amount__c = opp1.Initial_Amount__c;    
}
else if(opp1.Service_Type__c == 'A3')
{
s.Service_A3_Total_Amount__c = opp1.Total_Amount__c;
s.Initial_A3_Amount__c  = opp1.Initial_Amount__c; 
s.Service_Type_Amount__c = opp1.Total_Amount__c; 
s.Initial_Type_Amount__c = opp1.Initial_Amount__c;    

else if(opp1.Service_Type__c == 'A4')
{
s.Service_A4_Total_Amount__c = opp1.Total_Amount__c;
s.Initial_A4_Amount__c  = opp1.Initial_Amount__c; 
s.Service_Type_Amount__c = opp1.Total_Amount__c; 
s.Initial_Type_Amount__c = opp1.Initial_Amount__c;    
}
insert s;
}
else
{
list<Service__c> sold=[SELECT id,name,Accountname__c,Service_A1_Total_Amount__c,Service_A2_Total_Amount__c,Service_A3_Total_Amount__c,Service_A4_Total_Amount__c,Service_Type_Amount__c,Initial_A1_Amount__c,Initial_A2_Amount__c,Initial_A3_Amount__c,Initial_A4_Amount__c,Service_Type_Amount__c,Initial_Type_Amount__c,Service_Type__c from Service__c where name =:str];
       for(Service__c s1:sold ) 
  {
   if(opp1.Service_Type__c == 'A1')
{
s1.Service_A1_Total_Amount__c = opp1.Total_Amount__c;
s1.Initial_A1_Amount__c  = opp1.Initial_Amount__c;   
}
else if(opp1.Service_Type__c == 'A2')
{
s1.Service_A2_Total_Amount__c = opp1.Total_Amount__c;
s1.Initial_A2_Amount__c  = opp1.Initial_Amount__c;   
}
else if(opp1.Service_Type__c == 'A3')
{
s1.Service_A3_Total_Amount__c = opp1.Total_Amount__c;
s1.Initial_A3_Amount__c  = opp1.Initial_Amount__c;   

else if(opp1.Service_Type__c == 'A4')
{
s1.Service_A4_Total_Amount__c = opp1.Total_Amount__c;
s1.Initial_A4_Amount__c  = opp1.Initial_Amount__c;   
}
      s1.Service_Type_Amount__c =  s1.Service_A1_Total_Amount__c+s1.Service_A2_Total_Amount__c+s1.Service_A3_Total_Amount__c+s1.Service_A4_Total_Amount__c;
      s1.Initial_Type_Amount__c = s1.Initial_A1_Amount__c+s1.Initial_A2_Amount__c+s1.Initial_A3_Amount__c+s1.Initial_A4_Amount__c;        
 update s1;      
  } 
   }
    
}    
}
}
    global void finish(Database.BatchableContext BC){
        
           AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
      TotalJobItems, CreatedBy.Email
      FROM AsyncApexJob WHERE Id =
      :BC.getJobId()];
   // Send an email to the Apex job's submitter notifying of job completion.
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   String[] toAddresses = new String[] {a.CreatedBy.Email};
   mail.setToAddresses(toAddresses);
   mail.setSubject('Service Batch Job' + a.Status);
   mail.setPlainTextBody
   ('The batch Apex job processed ' + a.TotalJobItems +
   ' batches with '+ a.NumberOfErrors + ' failures.');
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}
I have a trigger whose code coverage is 56% in Sandbox , however while deploying in PROD the code coverage is reported as 0%.
Please help meto circumvent this issue, so that I can deploy the trigger in PROD
Hi,

I am getting below error in Apex trigger which updates field on parent obj based on value in child obj record

first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updateRegion: maximum trigger depth exceeded SampleMasterObject

Apex Trigger Code

trigger updateRegion on SampleMasterObject__c (after insert, after update) {

ID smoId;
String country;
//String region;

for(SampleMasterObject__c s : Trigger.New){

smoId = s.Id;
system.debug('@@@@@@smoId@@@@@@@@@@ : '+smoId);
}

List<SampleChild1__c> lsc = new List<SampleChild1__c>();
lsc = [Select Id, Country__c from SampleChild1__c where SampleMasterObject__c =: smoId];
system.debug('@@@@@@lsc@@@@@@@@@@ : '+lsc);

for(SampleChild1__c sc : lsc) {

country = sc.Country__c;
system.debug('@@@@@@country@@@@@@@@@@ : '+country);
}

If(country == 'IN') {
SampleMasterObject__c sm = new SampleMasterObject__c(Id=smoId, Region__c = 'APAC');

//sm.Id = smoId;
//sm.Region__c = 'APAC';
system.debug('@@@@@@sm.Region__c@@@@@@@@@@ : '+sm.Region__c);
update sm;
}




}
Full Error Statement

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger updateRegion caused an unexpected exception, contact your administrator: updateRegion: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0b90000009eu9JAAQ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updateRegion: maximum trigger depth exceeded SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J] SampleMasterObject trigger event AfterUpdate for [a0b90000009eu9J]: []: Trigger.updateRegion: line 31, column 1
Information:


  • September 30, 2014
  • Like
  • 0
Hi,
I am inserting a record in another object B, once an insert trigger is executed in my source object A.
however i want to display error message /notify if any of the fields of object B failed to get populated with values from object A.
The user should be notified that the insertion in object B failed ,because a field X couldn't be populated due to some reason.