• Jay Parikh 36
  • NEWBIE
  • 49 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 21
    Replies
Hi i have one apex class which has future method and every time i am calling it from apex trigger it is throwing this error : System.AsyncException: Future method cannot be called from a future or batch
Apex class :
Public class AccountProcessor {
    @future
    Public static void countContacts (set <ID> ActId){
    Double NumOfcontact ;
    set <id> actToUpdate = new set <id> ();
    list <account> act = [select id ,Number_of_Contacts__c  from account where id in : ActId];
    for (Account acLst : act){
    actToUpdate.add(acLst.id);
    }
    List <contact> ct = [select id , AccountId from contact where  AccountId in : actToUpdate ];
    if(ct.size() == 0 ){
    NumOfcontact = 0;
    }
    else if (ct.size() > 0){
    NumOfcontact = (ct.size());
    }
    Account act2 ;
    List <account> ActLatUpdate = new list <account>();
    for (Account actfinal : act ){
         act2 = new account ();
         act2.id = actfinal.id;
         act2.Number_of_Contacts__c =  NumOfcontact;
         ActLatUpdate.add(act2);
    }
    if(ActLatUpdate != null){
       Update ActLatUpdate;
    }
    }
}



Apex trigger :
trigger Toupdatecontact on account (after insert , after update){

   AccountProcessor.countContacts(Trigger.newMap.keyset());
   
}
I have one checkbox field on account object and I want to create workflow rule where every time that checkbox values go from True to False then it will update one field which is date data type with on which date that checkbox goes from true to false and I do not want to update that date field when record is created it only fired when checkbox goes from true to false
I want to create validation rule when Opportunity is closed won and the user who is trying to update sub-stage and role of that user is xyz it will throw an error?
Hi -- We have created a Visualforce page and where we are sending Email Conformation to a customer,
But it is only working for Gmail Domain but it is not working for all other domain like Yahoo. AOL.
Here is a trigger :
trigger ContactroleonOpp on Opportunity (after insert) {
  list <OpportunityContactRole > i = new list <OpportunityContactRole >();
  
  for(Opportunity  newopp : trigger.new){
    if (newopp.id != null ){
      i.add(new OpportunityContactRole (
       OpportunityId = newopp.id,
       //accountname = newopp.AccountId,
       ContactId = newopp.AccountId,
       Role = 'Other', 
       IsPrimary = true));
    
    
    }
  }
  
  insert i ;
  }

Error msg:Review all error messages below to correct your data.
Apex trigger ContactroleonOpp caused an unexpected exception, contact your administrator: ContactroleonOpp: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Contact ID: id value of incorrect type: 
Hi i have Lead Source object and acount object which are look up relation and on Lead source object i have email address field which take email address from lead source find accountid which is related with account and take that accountids and update the field on lead source called account ids i have written apex trigger but now i am not sure how i will assign query result to that field here is a my code :
trigger leadsourcewithaccountidsupdate on Lead_Sources__c (after update ) {
set <id> accountids = new set <id>();
set <string> emailname = new set <string>();
    
    for (Lead_Sources__c ls : trigger.new){
        if(ls.Email_at_last_edit__c	 != null){
            emailname.add(ls.Email_at_last_edit__c);
            system.debug('------debug1'+emailname);
        }
        
    }
    if (emailname.size()>0){
      Account[] updates = [select id   from account where PersonEmail in : emailname ];  
      system.debug('------debug2'+updates);
      
   }
}

 
trigger calcyforsas on Location_Cal__c (after insert , after update ) { 
    set<id> tst = new set <id>();
    
    if(trigger.isinsert || trigger.isupdate){
        for(Location_Cal__c ls : trigger.new ) {
            if(ls.testeTop_X_Designation__c != null){
               tst.add(ls.testeTop_X_Designation__c);
               system.debug('-----55'+tst);
            }
        } 
        for (testeTop_X_Designation__c ty :[select id ,Hello__c from testeTop_X_Designation__c where id in : tst  ]){
            system.debug('------88'+ty.Hello__c);
            string fx = ty.Hello__c;
            system.debug('-----55'+fx);
            Location_Cal__c cj = new Location_Cal__c();
            cj.Id = ls.id;
            cj.sas__c = fx;
            update cj;
            }
         
       }
}

 
Hi -- I have one xyz custom object and which is related with account object now i have req where on account object there will be 3 or 4 xyz object records and i want to create a new fields which is called first record and latest record checkbox which is based on created date of xyz records how will i achieve ??
for example :: on account there will be xyz object has a , b , c records based on creation date it will checked a record first records box true and same with the latest one ?????
Hi all---
I have reqierement where there are two object : account is parents and product is child 
now i want to update two fields on account 1. early purchased 2. latest purchased 
Early purchased will update based upon the product which is bought first one and latest purchased will update on same account where product bought latest one 

how i will achieve this trigger?
I have created VF PAGE and controller class and in debug log i am getting this error <apex:inputText> element value must resolve to a String type! what should i do???
ONE TEXT FEILD AND FIELD NAME CALLED   PROFILE HAS VALEUES OF  John - 78, Jorden - 71, Detra - 67, Fees - 65
1. NEW FORMULA FIELD output >>> John
2. NEW FORMULA FIELD output >>>78
3. NEW FORMULA FIELD output >>>Jorden
4. NEW FORMULA FIELD output >>>71
5. NEW FORMULA FIELD output >>>Detra
6. NEW FORMULA FIELD output >>> 67
7. NEW FORMULA FIELD output >>> Fees
7. NEW FORMULA FIELD output >>> 65
I have one text fields 

input ::::Feeler - 62, Exciter - 58, Bottom-Liner - 58, Detailer - 54


and in a new field i only want to see output as :::Feeler - 62    how can i achieve using formula field?? 
I have schedule job which have to run every 20 min but when i am putting as a schedule job (from anno window )it only runs one time andafter that it is not working every 20 min it is only working when you submit once here is the code :


String str = system.now().addMinutes(20).format('ss mm HH dd MM ? yyyy'); 
System.schedule('WebcartPullProductsScheduled', str , new WebcartPullProductsScheduled());  

 
I have one visual flow based upon that it will updates opportunity fields and i have two roles call and reciver for call roles it is working fine but for receiver roles it is not working what should i do????

i have two object oppertunity and account 
there r two fields stagename and cource 
if stagename is closedwon and cource is english
it will show logo on account object how to i write formula or what is the solution?
Hello guys

I am having one scenario, while creating contact, I will be checking the email id of contact and if duplicate email id found for specific account it relates then I have a Checkbox__c field on account and it should be unchecked.
by default Vheckbox__c will be checked.
While creating contact for a particular account,if email is already found on that particular account then checkbox should be unchecked
Lets Say I have account A1 and have Checkbox__c field checked by default.
Now I will add contacts for the account A1. I am adding first contact C1 with email xyz@gmail.com and I will add another contact C2 with same email id xyz@gmail.com, since two contacts have same email id then Checkbox__c should get unchecked and I will update contact C2 with email abc@gmail.com and now two contacs have different email ids the Checkbox__c should get checked.

If I get any help then it will be really helpful.
Hi -- We have created a Visualforce page and where we are sending Email Conformation to a customer,
But it is only working for Gmail Domain but it is not working for all other domain like Yahoo. AOL.
I want to create a field that has the last time the account was touched that was not done by a system admin.
By touch, I mean Newest date out of the following: Task Created date, Event created to date, task modified date, event modified date.
This trigger was built for us but doesn’t exclude the System admin as well as doesn’t give us the last day if they created an activity just gives us a modified date.  Not really sure how to fix it/ adjust it. Any help is appreciated. I have never used Apex before.
 
trigger UpdateLastActivityDate4318 on Task (after insert, after update, after delete, after undelete)
{
    Set<Id> accountIds = new Set<id>();
    if(Trigger.isDelete)
    {
        //always get the old for deleted activities
        for(Task t : Trigger.old)
        {
            accountIds.add(t.AccountId);
        }
    }
    else   
    {
        for(Task t : Trigger.new)
        {           
            accountIds.add(t.AccountId);
        }                  
       
    }
   
  List<Account> accounts =           
            [
                SELECT
                  Id,
                    (
                        SELECT
                          Subject,
                            LastModifiedDate
                        FROM Tasks
                        ORDER BY isClosed ASC, LastModifiedDate DESC
                        LIMIT 1
                    ),
                  Last_Activity_Date__c
                FROM Account
                WHERE Id in :accountIds
            ];
   
   
   
    for (Account a : accounts)
    {
   
        system.debug(a);
       
       
        if(a.Tasks.size() > 0)
        {
            system.debug(a.Tasks[0]);
            a.Last_Activity_Date__c = a.Tasks[0].LastModifiedDate;
        }
        else
        {
            a.Last_Activity_Date__c = null;
        }
    }
   
    update accounts;
}
 
}
 
 
 
When I attempt to save my Apex Class I receive the error "Error: Compile Error: Unexpected token 'class timecardEndDateAudit implements Database.Batchable'. at line 3 column 8"
I can't seem to figure out what I'm missing here. 

gobal class timecardEndDateAudit implements Database.Batchable<sObject>,Database.Stateful{

global Database.QueryLocator start(Database.BatchableContext bc){

String query = 'SELECT jstcl__Placement__r.Name , Account_Executive__c , jstcl__Placement__r.Timecard_End_Date_Audit__c FROM jstcl__TG_Timesheet__c WHERE jstcl__Week_Ending__c >= LAST_N_DAYS:14'

return Database.getQueryLocator(query);
global void execute(Database.BatchableContext bc,List<Placement>scope){

for (Placement Placements :scope){
Placements.Timecard_End_Date_Audit__c ='1';
}
update scope;
}
global void finish(Database.BatchableContext bc){}
}
Here is a trigger :
trigger ContactroleonOpp on Opportunity (after insert) {
  list <OpportunityContactRole > i = new list <OpportunityContactRole >();
  
  for(Opportunity  newopp : trigger.new){
    if (newopp.id != null ){
      i.add(new OpportunityContactRole (
       OpportunityId = newopp.id,
       //accountname = newopp.AccountId,
       ContactId = newopp.AccountId,
       Role = 'Other', 
       IsPrimary = true));
    
    
    }
  }
  
  insert i ;
  }

Error msg:Review all error messages below to correct your data.
Apex trigger ContactroleonOpp caused an unexpected exception, contact your administrator: ContactroleonOpp: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Contact ID: id value of incorrect type: 
trigger calcyforsas on Location_Cal__c (after insert , after update ) { 
    set<id> tst = new set <id>();
    
    if(trigger.isinsert || trigger.isupdate){
        for(Location_Cal__c ls : trigger.new ) {
            if(ls.testeTop_X_Designation__c != null){
               tst.add(ls.testeTop_X_Designation__c);
               system.debug('-----55'+tst);
            }
        } 
        for (testeTop_X_Designation__c ty :[select id ,Hello__c from testeTop_X_Designation__c where id in : tst  ]){
            system.debug('------88'+ty.Hello__c);
            string fx = ty.Hello__c;
            system.debug('-----55'+fx);
            Location_Cal__c cj = new Location_Cal__c();
            cj.Id = ls.id;
            cj.sas__c = fx;
            update cj;
            }
         
       }
}

 
Hi -- I have one xyz custom object and which is related with account object now i have req where on account object there will be 3 or 4 xyz object records and i want to create a new fields which is called first record and latest record checkbox which is based on created date of xyz records how will i achieve ??
for example :: on account there will be xyz object has a , b , c records based on creation date it will checked a record first records box true and same with the latest one ?????
Hi all---
I have reqierement where there are two object : account is parents and product is child 
now i want to update two fields on account 1. early purchased 2. latest purchased 
Early purchased will update based upon the product which is bought first one and latest purchased will update on same account where product bought latest one 

how i will achieve this trigger?
Hello Developers!

I have a situation here in which trigger is not firing.
Master object: Volunteer_Project__c and Detail object: Participation__c
I want to count number of unique email addresses (Total_Associated_Volunteers__c) of Participation__c on Volunteer_Project__c.

Approach: Whenever there is a record entry in child for one particular master, I am compering that newly inserting record's email address to all of the child records of that master. If similar email found then Unique_Roll_Up__c on that detail record is 0 otherwise 1. At the end, I am putting rollup summary on Unique_Roll_Up__c at the Master object.

Trigger:
 
Trigger UniqueRollUp On Participation__c(Before Insert, Before Update){

    List<Participation__c> Partici = New List<Participation__c>();
    Set<String> UniqueEmailSet = New Set<String>();
    Set<ID> ProjIds = New Set<ID>();
    
    If(Trigger.IsInsert || Trigger.IsUpdate)
    {
        For(Participation__c P: Trigger.New)
        {    
            ProjIds.add(P.Volunteer_Project_Name__c);    
        }
    }
    
    Partici = [Select Volunteer_Email__c FROM Participation__c WHERE Volunteer_Project_Name__c = :ProjIds];
    
    For(Participation__c Pa: Trigger.New){
        If(Pa.Volunteer_Email__c != null){
            
            for(Integer I = 0; I<Partici.size(); I++){
                if(Pa.Volunteer_Email__c == Partici[0].Volunteer_Email__c){
                    Pa.Unique_Roll_Up__c = 0;
                }
            }
        }
        else{
            Pa.Unique_Roll_Up__c = 1;
        }
    }
}

Thank You!
ONE TEXT FEILD AND FIELD NAME CALLED   PROFILE HAS VALEUES OF  John - 78, Jorden - 71, Detra - 67, Fees - 65
1. NEW FORMULA FIELD output >>> John
2. NEW FORMULA FIELD output >>>78
3. NEW FORMULA FIELD output >>>Jorden
4. NEW FORMULA FIELD output >>>71
5. NEW FORMULA FIELD output >>>Detra
6. NEW FORMULA FIELD output >>> 67
7. NEW FORMULA FIELD output >>> Fees
7. NEW FORMULA FIELD output >>> 65
I have one text fields 

input ::::Feeler - 62, Exciter - 58, Bottom-Liner - 58, Detailer - 54


and in a new field i only want to see output as :::Feeler - 62    how can i achieve using formula field?? 

Hello all,

 

Can you please let me know the steps to make sure that I run the batch apex every 30 minutes all day and everyday...In the UI i can schedule everyday but here i want to execute my batch class everyday and on each and every single day i have to run this Batch Apex every 30 minutes?Please let me know the sequence of actions that i need to take...

 

Here is my schedulable class

 

 

global class ProcessAccs implements Schedulable{
   
    global void execute(SchedulableContext sc) {
        //  Instantiate batch class 
        BatchProcessAccs B = new BatchProcessAccs();
        database.executebatch(B,200);
    }
    
}