• Niraj Kumar 9
  • NEWBIE
  • 85 Points
  • Member since 2015
  • Mr.
  • Adsat


  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 35
    Questions
  • 41
    Replies
I have a simple test class which has sufficient code coverage for Trigger in Partiel Sandbox.
I have 0 % Test coverage in Production.

I have executed the lines individually in Anonymous mode , the code executes properly without any issues.

While deploying i am using : Use specific test and not the default one to test only on test class and the trigger responsible
@isTest(SeeAllData=true) 
private class TestClassTest {
    
    Static testmethod void mytest1 () {
        
        Candidat__c c = new Candidat__c(name='z1', FirstName__c='t1', Email__c = 'test1@test.sf');
        insert c; 

        task e = new task (subject='zz1',whatid=c.id);      
        insert e;
    }

}

Any reason for my usecase ?
  • June 15, 2016
  • Like
  • 0
Hi all,
 
I am preparing for ADM, FOrce.com and App certification and need study material. 

Thanks
Niraj Kumar
 
Please help anyone.Its urgent.
Need to write a trigger on task object to count all tasks related to account, contact and opportunity.

Account task =2, Opportunity task(related to this Account )=1, Contact task(related to this Account)=3
In Account count field Shows =6.



 
Hi,

Can U please modify this trigger to call Future class. May be this solution work.
Trigger TaskTrigger on Task(after insert, after delete, after undelete) {
    Set<Id> accountIds = new Set<Id>();
    for(Task tsk : trigger.isDelete ? trigger.old : trigger.new) {
        accountIds.add(tsk.AccountId);
    }
    AggregateResult[] groupedResults = [SELECT Count(Id), AccountId FROM Task group by AccountId having AccountId in: accountIds];
    Map<Id,Integer> taksCountMap = new Map<Id,Integer>();
    for (AggregateResult ar : groupedResults)  {
        taksCountMap.put((Id)ar.get('AccountId'),Integer.valueOf(ar.get('expr0')));
    }
    
    List<Account> accUpdLst = new List<Account>();
    //Updating the count field
    for(Task tsk: trigger.new) {   
        if(taksCountMap.containsKey(tsk.AccountId))
            accUpdLst.add(new Account(Id = tsk.AccountId,count__c = taksCountMap.get(tsk.AccountId)));
    }
    
    if(accUpdLst.size() > 0) {
        update accUpdLst;
    }
}

 
Hi Guys,
I need to be modify the trigger and apex class so that it will work for Account Count= Account+Contact+Opportunity(task and event).Only for Account , Rests are ok.
trigger UpdateAccountContactopportunityCounttask on task (after insert, after delete) {
      
   
     Set <Id> AccountIDs = new Set <Id> ();
     Set <Id> ContactIDs = new Set <Id> ();
     Set <Id> OpportunityIDs = new Set <Id> ();
   
  
  if(trigger.isinsert){
      for(Task tsk1: Trigger.new){
      
    
      
          if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == Account.getSObjectType()){
              AccountIDs .add(tsk1.WhatId);
              
          }
          if(tsk1.WhoId <> NULL && tsk1.WhoId.getSobjectType() == Contact.getSObjectType()){
              ContactIDs.add(tsk1.WhoId);
          }
         if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == opportunity.getSObjectType()){
              OpportunityIDs.add(tsk1.WhatId);
          } 
      }
      
  }
  if(Trigger.isDelete ){
      for(Task tsk1: Trigger.old){
         if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == Account.getSObjectType()){
              AccountIDs .add(tsk1.WhatId);
          }
        if(tsk1.WhoId <> NULL && tsk1.WhoId.getSobjectType() == Contact.getSObjectType()){
              ContactIDs.add(tsk1.WhoId);
          } 
          if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == opportunity.getSObjectType()){
              OpportunityIDs.add(tsk1.WhatId);
          } 
      }  
  }
  if(AccountIDs.size()>0)
      ActivityTriggerHandler.UpdateActivityAccount(AccountIDs);
  
  // Recompute the Activities for Account
  
    if(ContactIDs.size()>0)
      ActivityTriggerHandler.UpdateActivityContact(ContactIDs);
  
  // Recompute the Activities for Contact
  
   if(OpportunityIDs.size()>0)
      ActivityTriggerHandler.UpdateActivityOpportunity(OpportunityIDs);
  
  // Recompute the Activities for opportunity
  
}
trigger UpdateAccountContactOpportunityCountevent on event (after insert, after delete) {

  Set <Id> ContactIDs = new Set <Id> ();
   Set <Id> AccountIDs = new Set <Id> ();
    Set <Id> opportunityIDs = new Set <Id> ();
  
  if(Trigger.isInsert ){
      for(Event ev1: Trigger.new){
          if(ev1.WhoId <> NULL && ev1.WhoId.getSobjectType() == Contact.getSObjectType()){
              ContactIDs.add(ev1.WhoId);
          }
          if(ev1.WhatId <> NULL && ev1.WhatId.getSobjectType() == Account.getSObjectType()){
              AccountIDs .add(ev1.WhatId);
          }
        if(ev1.WhatId <> NULL && ev1.WhatId.getSobjectType() == Opportunity.getSObjectType()){
              opportunityIDs .add(ev1.WhatId);
          }  
      }
  }
  if(Trigger.isDelete ){
      for(Event ev1: Trigger.old){
          if(ev1.WhoId <> NULL && ev1.WhoId.getSobjectType() == Contact.getSObjectType()){
              ContactIDs.add(ev1.WhoId);
          }
          if(ev1.WhatId <> NULL && ev1.WhatId.getSobjectType() == Account.getSObjectType()){
              AccountIDs .add(ev1.WhatId);
          }
          if(ev1.WhatId <> NULL && ev1.WhatId.getSobjectType() == Opportunity.getSObjectType()){
              opportunityIDs .add(ev1.WhatId);
          }
      }  
  }
  if(ContactIDs.size()>0)
      ActivityTriggerHandler.UpdateActivityContact(ContactIDs);
  
  // Recompute the Activities for Contact
  
  if(AccountIDs.size()>0)
     
      ActivityTriggerHandler.UpdateActivityAccount(AccountIDs);
  // Recompute the Activities for Account
  
   if(opportunityIDs.size()>0)
      
      ActivityTriggerHandler.UpdateActivityOpportunity(opportunityIDs);
  // Recompute the Activities for opportunity
  
}
Apex classes::::
 
Public class ActivityTriggerHandler{




@future
       
         public static void UpdateActivityAccount(set<Id> AccountIDs ){
            MAP <Id,integer> AccountCntMap = new MAP <Id, integer>();
                      
           
            integer count;
             for(ID id1: AccountIDs ){
                AccountCntMap .put(id1, 0);  
             }
             for(Task tsk1: [select id from task where Id IN : AccountIDs]){
                 count = AccountCntMap .get(tsk1.WhatId) + 1;
                 AccountCntMap .put(tsk1.WhatId, count);
             }
             for(Event ev1: [select WhatId, Id from Event where Id IN :AccountIDs]){
                 count = AccountCntMap .get(ev1.WhatId) + 1;
                 AccountCntMap .put(ev1.WhatId, count);
             }
             LIST <Account> AccUpd = new LIST <Account>();
             for(Account Acc1: [SELECT Id, Count_of_Activity__c FROM Account WHERE Id IN :AccountIDs ]){
                count = AccountCntMap .get(Acc1.Id);
                Acc1.Count_of_Activity__c = count;
                 AccUpd .add(Acc1);
             }
             Database.update(AccUpd );
         }
          
 
        
          @future
         public static void UpdateActivityContact(set<Id> ContactIDs){
            MAP <Id,integer> ContactCntMap = new MAP <Id, integer>(); 
            integer count;
             for(ID id1: ContactIDs){
                ContactCntMap.put(id1, 0);  
             }
             for(Task tsk1: [select WhoId, Id from Task where WhoId IN :ContactIDs]){
                 count = ContactCntMap.get(tsk1.WhoId) + 1;
                 ContactCntMap.put(tsk1.WhoId, count);
             }
             for(Event ev1: [select WhoId, Id from Event where WhoId IN :ContactIDs]){
                 count = ContactCntMap.get(ev1.WhoId) + 1;
                 ContactCntMap.put(ev1.WhoId, count);
             }
             LIST <Contact> ContUpd = new LIST <Contact>();
             for(Contact cont1: [SELECT Id, Count_of_Activity__c FROM Contact WHERE Id IN :ContactIDs]){
                count = ContactCntMap.get(cont1.Id);
                cont1.Count_of_Activity__c = count;
                 ContUpd.add(cont1);
             }
             Database.update(ContUpd);
           }
   
         
         @future
       
         public static void UpdateActivityOpportunity(set<Id> opportunityIDs ){
            MAP <Id,integer> OpportunityCntMap = new MAP <Id, integer>(); 
            integer count;
             for(ID id1: opportunityIDs ){
                OpportunityCntMap .put(id1, 0);  
             }
             for(Task tsk1: [select WhatId, Id from Task where WhatId IN :opportunityIDs ]){
                 count = OpportunityCntMap.get(tsk1.WhatId) + 1;
                 OpportunityCntMap.put(tsk1.WhatId, count);
             }
             for(Event ev1: [select WhatId, Id from Event where WhatId IN :opportunityIDs ]){
                 count = OpportunityCntMap.get(ev1.WhatId) + 1;
                 OpportunityCntMap.put(ev1.WhatId, count);
             }
             LIST <Opportunity> OppUpd = new LIST <Opportunity>();
             for(opportunity Opp1: [SELECT Id, Count_of_Activity__c FROM Opportunity WHERE Id IN :opportunityIDs ]){
                count = OpportunityCntMap.get(Opp1.Id);
                Opp1.Count_of_Activity__c = count;
                 OppUpd.add(Opp1);
             }
             Database.update(OppUpd);
         }  
      
       }
Thanks in advance.

Regards,
Niraj Kumar.



 
Hi Guys,

I need a trigger to count all task associated with Account, Contact and opportunity .Update the Account count field in Account .
Eg- Account have 2 task and related Contact and opportunity related to this Account have one one task respectively.
In Account count field Show 5 instead of 2.

Thanks in Advance
Hi Guys,

I need a soql query to get all task related to Account, Contact, opportunity.

Thanks.
Hi Guys,

I need a trigger to count the task of Account, Contact, opportunity and update in the Account count field with sum of Account task, Contact task, Opportunity task.

EX - Create a Account, create 2 task on Account, create a contact related to this account and create 1 task, create a opportunity related to this account  create 2 task. In Account Count Field it shoud be 5 taks.
Hi guys,

I want to retrieve all task associated with account and related to contact, opportunity
Hi,

Below is my trigger, its not counting the closed  Activity.
Need your help.
 
trigger AccountCounttask on task (after insert, after delete) {

  Set <Id> AccountIDs = new Set <Id> ();
  
  if(Trigger.isInsert ){
      for(Task tsk1: Trigger.new){
          if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == Account.getSObjectType()){
              AccountIDs .add(tsk1.WhatId);
          }
      }
  }
  if(Trigger.isDelete ){
      for(Task tsk1: Trigger.old){
         if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == Account.getSObjectType()){
              AccountIDs .add(tsk1.WhatId);
          }
      }  
  }
  if(AccountIDs.size()>0)
      ActivityTriggerHandler.UpdateActivityAccount(AccountIDs);
  
  // Recompute the Activities for Account
}
 
@future
       
         public static void UpdateActivityAccount(set<Id> AccountIDs ){
            MAP <Id,integer> AccountCntMap = new MAP <Id, integer>(); 
            integer count;
             for(ID id1: AccountIDs ){
                AccountCntMap .put(id1, 0);  
             }
             for(Task tsk1: [select WhatId, Id from Task where WhatId IN :AccountIDs ]){
                 count = AccountCntMap .get(tsk1.WhatId) + 1;
                 AccountCntMap .put(tsk1.WhatId, count);
             }
             for(Event ev1: [select WhatId, Id from Event where WhatId IN :AccountIDs ]){
                 count = AccountCntMap .get(ev1.WhatId) + 1;
                 AccountCntMap .put(ev1.WhatId, count);
             }
             LIST <Account> AccUpd = new LIST <Account>();
             for(Account Acc1: [SELECT Id, Count_of_Activity__c FROM Account WHERE Id IN :AccountIDs ]){
                count = AccountCntMap .get(Acc1.Id);
                Acc1.Count_of_Activity__c = count;
                 AccUpd .add(Acc1);
             }
             Database.update(AccUpd );
         }

 
Hi,
Hhere is the task trigger and class for counting count of activity.Old task of existing Account is not counting .

Here is code.
 
trigger AccountCounttask on task (after insert, after delete) {

  Set <Id> AccountIDs = new Set <Id> ();
  
  if(Trigger.isInsert ){
      for(Task tsk1: Trigger.new){
          if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == Account.getSObjectType()){
              AccountIDs .add(tsk1.WhatId);
          }
      }
  }
  if(Trigger.isDelete ){
      for(Task tsk1: Trigger.old){
         if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == Account.getSObjectType()){
              AccountIDs .add(tsk1.WhatId);
          }
      }  
  }
  if(AccountIDs.size()>0)
      ActivityTriggerHandler.UpdateActivityAccount(AccountIDs);
  
  // Recompute the Activities for Account
}
@future
       
         public static void UpdateActivityAccount(set<Id> AccountIDs ){
            MAP <Id,integer> AccountCntMap = new MAP <Id, integer>(); 
            integer count;
             for(ID id1: AccountIDs ){
                AccountCntMap .put(id1, 0);  
             }
             for(Task tsk1: [select WhatId, Id from Task where WhatId IN :AccountIDs ]){
                 count = AccountCntMap .get(tsk1.WhatId) + 1;
                 AccountCntMap .put(tsk1.WhatId, count);
             }
             for(Event ev1: [select WhatId, Id from Event where WhatId IN :AccountIDs ]){
                 count = AccountCntMap .get(ev1.WhatId) + 1;
                 AccountCntMap .put(ev1.WhatId, count);
             }
             LIST <Account> AccUpd = new LIST <Account>();
             for(Account Acc1: [SELECT Id, Count_of_Activity__c FROM Account WHERE Id IN :AccountIDs ]){
                count = AccountCntMap .get(Acc1.Id);
                Acc1.Count_of_Activity__c = count;
                 AccUpd .add(Acc1);
             }
             Database.update(AccUpd );
         }

Thanks in Advance.

 
Hi,

I want to make changes that if  opportunity owner role is 'sales specialist' then no change in opportunity owner and for other role
trigger tocUpdateOpportunitySalesTeamForAccountOwnerChange on Account (before update) 
{
    ID[] acc=new ID[]{};
    ID[] OwnerIds=new ID[]{};
    ID[] oldOwnerIds=new ID[]{};
    ID[] oppIds=new ID[]{};
    
    // List<Opportunity> oppToUpdate = new List<Opportunity>();
    
    List <String> OppOldOwnrLst = new List<String>();
    
    for (Integer i = 0; i < Trigger.new.size(); i++) 
    {           
         String id = Trigger.new[i].Id;
         if(Trigger.new[i].trZuoraID__c==null)
         {
            if (Trigger.new[i].OwnerId != Trigger.old[i].OwnerId) 
            {
                acc.add(Trigger.new[i].Id);
                OwnerIds.add(Trigger.new[i].OwnerId);
                oldOwnerIds.add(Trigger.old[i].OwnerId);                                 
            }
         }
    }
    
    System.Debug('acc'+acc+'acc.size'+acc.size());
    System.Debug('OwnerIds'+OwnerIds+'OwnerIds.size'+OwnerIds.size());
    System.Debug('oldOwnerIds'+oldOwnerIds+'oldOwnerIds.size'+oldOwnerIds.size());
  
    if(acc.size()>0)
    {
          
        for(Opportunity opp1:[Select Id,OwnerId, StageName, AccountId from Opportunity Where AccountId IN:acc])
        {
                     System.Debug('opp1.OwnerId'+opp1.OwnerId);
             
             if(opp1.StageName != ('6. Order Placed') && opp1.StageName != ('7. Order Complete') && opp1.StageName != ('8. Closed / No Order'))
            {
                oppIds.add(opp1.Id);
                OppOldOwnrLst.add(opp1.id+';'+opp1.OwnerId);                       
               
            }
        }
   
            //ProcessDataAccount Class Method Called
                
            //ProcessDataAccount.AssignData(acc,OwnerIds,oppIds,oldOwnerIds,OppOldOwnrLst);
    }   
}

opportunity owner= Account owner.

Here is my code
Hi guys,

I am getting error :::Apex trigger UpdateActivityCountonAccountContactOptytask caused an unexpected exception, contact your administrator: UpdateActivityCountonAccountContactOptytask: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.UpdateActivityCountonAccountContactOptytask: line 135, column 1
trigger UpdateActivityCountonAccountContactOptytask on task (after insert, after delete, after update) {

 
  map<id,integer> mopportunityCount = new map<id,integer>();
  map<id,integer> maccountCount = new map<id,integer>();
  map<id,integer> mcontactCount = new map<id,integer>();
  
  Integer OptyCount = 0;
 Integer AccountCount = 0;
 Integer ContactCount = 0;


  if (trigger.isinsert  || trigger.isUpdate ){

  for(task t :trigger.new) {
  
  if(t.whatId != null) {
  
    if(string.valueOf(t.WhatId).left(3) == '001') {
         
         
         if(maccountCount .containsKey(t.WhatId)) {
           AccountCount = maccountCount.get(t.WhatId);
            }
         
         AccountCount = AccountCount + 1;
         maccountCount.put(t.WhatId,AccountCount );
      }
    
      if(string.valueOf(t.WhatId).left(3) == '006') {
         
         
         if(mopportunityCount.containsKey(t.WhatId)) {
           OptyCount = mopportunityCount.get(t.WhatId);
            }
         
         OptyCount = OptyCount + 1;
      
         mopportunityCount.put(t.whatid,OptyCount);
      }
    }

    if(t.whoId != null) {
      if(string.valueOf(t.WhoId).left(3) == '003') {
         
         
         if(mcontactCount.containsKey(t.WhoId)) {
           ContactCount  = mcontactCount.get(t.WhoId);
            }
         
         ContactCount  = ContactCount  + 1;
      
         mcontactCount.put(t.whoid,ContactCount );
      }
    }
  }
 }
 
  if (trigger.isdelete){
   for(task t :trigger.old) {

    if(t.whatId != null) {
  
    if(string.valueOf(t.WhatId).left(3) == '001') {
         
         
         if(maccountCount .containsKey(t.WhatId)) {
           AccountCount = maccountCount.get(t.WhatId);
            }
         
         AccountCount = AccountCount - 1;
         maccountCount.put(t.WhatId,AccountCount );
      }
    
      if(string.valueOf(t.WhatId).left(3) == '006') {
         
         
         if(mopportunityCount.containsKey(t.WhatId)) {
           OptyCount = mopportunityCount.get(t.WhatId);
            }
         
         OptyCount = OptyCount - 1;
      
         mopportunityCount.put(t.whatid,OptyCount);
      }
    }
  
    if(t.whoId != null) {
      if(string.valueOf(t.WhoId).left(3) == '003') {
         
         
         if(mcontactCount.containsKey(t.WhoId)) {
           ContactCount  = mcontactCount.get(t.WhoId);
            }
         
         ContactCount  = ContactCount  - 1;
      
         mcontactCount.put(t.whoid,ContactCount );
      }
    }
  }
}

  if(mcontactCount.keyset().size()>0) {
    list<contact> contactToUpdate = new list<contact>([SELECT id,Count_of_Activity__c FROM contact WHERE Id IN :mcontactCount.keyset()]);

    if(contactToUpdate.Size() > 0)
    for(contact c :contactToUpdate) {

    if(c.Count_of_Activity__c != null)    
    c.Count_of_Activity__c = c.Count_of_Activity__c + mcontactCount.get(c.id);
    }
   
    if(contactToUpdate.size()>0) {
      update contactToUpdate;
    }
   } 
 

  if(mopportunityCount.keyset().size()>0) {
    list<opportunity> opportunityToUpdate = new list<opportunity>([SELECT id,Count_of_Activity__c FROM opportunity WHERE Id IN :mopportunityCount.keyset()]);
     for(opportunity o :opportunityToUpdate ) {
     o.Count_of_Activity__c = o.Count_of_Activity__c + mopportunityCount.get(o.id);
    }
   if(opportunityToUpdate.size()>0) {
      update opportunityToUpdate;
    }
   } 
   if(maccountCount.keyset().size()>0) {
    list<account> accountToUpdate = new list<account>([SELECT id,Count_of_Activity__c FROM account WHERE Id IN :maccountCount.keyset()]);

    for(account a :accountToUpdate ) {

        
    a.Count_of_Activity__c = a.Count_of_Activity__c + maccountCount.get(a.id);
    }
   
    if(accountToUpdate.size()>=0) {
      update accountToUpdate;
    }
   } 
  }

 
Hi Guys,

can u please let me know, Custom Lookup is working fine in salesforce1 too.
I am facing issues .
Hi Guys,
Lookup is not working fine in salesfeorce1 but working fine in Salesforce.
Here is the code::

<apex:selectList value="{!selectedUser}" size="1" id="UsrSelLst">
                   <apex:selectOptions value="{!SelectedUserList}"  id="UsrSelOpt" />
                   </apex:selectList>

Lookup is open in new windows but after selection of user nothing happen.
 
Hi Guys,
Apex Select list is not working in salesforce1 while working fine in salesforce.
 <apex:selectList value="{!selectedUser}" size="1" id="UsrSelLst">
 
Hi,

My requiement is :::The requirement is to be able to create reports based on Contacts or account or Opportunities and see a “Summary” field for Total  # of Activities associated with either Contacts, Accounts or Opportunities.
Note that we do not want to see a line for each activity, we want to see one line for the each contact or opp or account with the activity summary count.

I know the navigation but  am not sure about the Object Relationships(Its include all three and activities) .

 
Hi,
VF page user lookup not updating field after selection of user in Salesforce1 but working fine in salesforce.

here is the code VF
<apex:outputlabel style="font-weight:bold;margin-top:10px">OR Search and select for a Sales Order Specialist or Queue</apex:outputlabel><br/>
<apex:outputPanel id="lookupQU"> 
            <apex:outputLabel id="Ol" style="text-align:left;font-weight : bold" value="Owner ">&nbsp;</apex:outputLabel>     

         
                <apex:selectList value="{!QueueUser}" size="1" id="SelLst"> 
                <apex:selectOptions value="{!Items}" id="SelOptId"/>   
                </apex:selectList>
                               &nbsp;
                <apex:outputpanel rendered="{!showLookup}">
                  <apex:inputText id="txtHd2" value="{!custAA.Owner.Name}"/> 
                 
                 <a href="#"  id="lookupPickTechMask1"  title="User or Queue LookUp (New Window)" onclick="openQULookUp('{!accountId}');">
                            <img src="/s.gif" alt="TechMask Lookup (New Window)"  class="lookupIcon" onblur="this.className = 

'lookupIcon';"    onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 

'lookupIcon';"    onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" title="User or Queue LookUp 

(New  Window)"/>
                  </a>             
                </apex:outputpanel>
                <apex:outputpanel rendered="{!NOT(showLookup)}" id="OutList">
                <apex:inputHidden id="HdUsrSelId" value="{!ReturnValId}"/>
                 <apex:selectList value="{!selectedUser}" size="1" id="UsrSelLst">
                   <apex:selectOptions value="{!SelectedUserList}"  id="UsrSelOpt" />
                   </apex:selectList>
                   <a href="#"  id="lookupPickTechMask1"  title="User or Queue LookUp (New Window)" onclick="openQULookUp

('{!accountId}');">
                            <img src="/" alt="TechMask Lookup (New Window)"  class="lookupIcon" onblur="this.className = 

'lookupIcon';"    onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 

'lookupIcon';"    onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" title="User or Queue LookUp 

(New  Window)"/>
                  </a>
                  <apex:pagemessages />
                </apex:outputpanel>
                <apex:inputHidden id="txtHdId" value="{!usqe}"/>
            </apex:outputPanel>
       
       
      
     </apex:pageBlockSection>
      </apex:pageBlock>      <br />
and
 
function openQULookUp(id)
        {
            var txtval;
            var txtval1;
            txtval=document.getElementById('pg:frm:Pb:pbs:SelLst').value
            txtval1= '';
            if(document.getElementById('pg:frm:Pb:pbs:txtHd2') != null) 
               txtval1=document.getElementById('pg:frm:Pb:pbs:txtHd2').value;
            else {
               var p = document.getElementById('pg:frm:Pb:pbs:UsrSelLst').selectedIndex ;
               txtval1 = document.getElementById('pg:frm:Pb:pbs:UsrSelLst').options[p].text
             }
             
             if(txtval == 'User')
             { 
             var newWindow = window.open( '/apex/UsrLookup?UsrId='+txtval1+'&selected=user&accId='+id, '_new', 'resizable=yes,scrollbars=yes,status=yes,toolbar=false,height=600,width=800,top=100,left=100');
             newWindow.creator=self;
             }
             else if (txtval == 'Queue')
             {
             var newWindow = window.open( '/apex/QueLookup?QueId='+txtval1+'&selected=Queue&accId='+id, '_new', 'resizable=yes,scrollbars=yes,status=yes,toolbar=false,height=600,width=800,top=100,left=100');
             newWindow.creator=self;
             }

And controller is :::
 
public pageReference OwnerUpdate()
    {
      showLookup = true ;
      System.debug('Owner' + UID + 'UsQeId' + UsQeId + 'Con' + Con + 'ContId' + ContId);
      String cont = conFunAcc.Contact_Id__c;  
      String recTy;

    
      String UerId;
      PageReference pageRef ;      
     if(rt != '')
      {
      RecordType recType = [select Name,id from RecordType where RecordType.SobjectType = 'Siebel_Quote__c' and Name =:rt];
      recTy = recType.id;   
       System.debug('name' + recType.name + 'Id' + recType.id); 
      }
    
      if(UID != '' && QueueUser == 'User')
      {
        System.debug('****************test11111***'+selectedUser)   ;
        if( selectedUser == '' || selectedUser == null ) {
        System.debug('****************test***'+selectedUser)    ;
        string str = '%'+UID+'%';
        list<User> uer = [select id, name,tfcrmTeamRole__c from User where tfcrmTeamRole__c = 'Sales Order Specialist' and IsActive = true and ((NOT Profile.Name like 'Account Gateway%') OR (NOT Profile.Name like 'My Thomson Reuters%')) and name Like : str ];
        if(uer.size() > 1)
        {
          for(User ur : uer){
            showLookup = false ;
            SelectedUserList.add(new selectoption (ur.id,ur.Name));
            UerId = uer[0].Id;
            selectedUser = uer[0].Id;
            System.debug('***************user selected from dropdown **' + UerId)   ;
         }

            System.debug('****************uer.size() > 1***')   ;
            ApexPages.Message errMsg= new ApexPages.Message(ApexPages.severity.ERROR, 'Multiple Sales Order Specialists found. Select from the drop-down or click icon to refine search.');  
            ApexPages.addMessage(errMsg);
          return null;
        }else if(uer.size() == 0 ){
            System.debug('***************uer.size() == 0**')    ;
            ApexPages.Message errMsg= new ApexPages.Message(ApexPages.severity.ERROR, 'No matching Sales Order Specialists found.');  
            ApexPages.addMessage(errMsg);
            return null;
            }

        else if(uer.size() == 1 ){
           System.debug('***************er.size() == 1**')  ;
           UerId = uer[0].Id;
           System.debug('***************user selected if list size is 1**' + UerId) ;
             }

        
        }
            else 
            {


            system.debug('**** In the inner else selectedUser *****' + selectedUser);
               UerId = selectedUser;
               system.debug('**** In the inner else section *****' + UerId);
            }

      }
      else
      {
        system.debug('**** In the outer else UsQeId *****' + UsQeId);
          UerId = UsQeId;
          system.debug('**** In the Outer else section *****' + UerId);
      }
      
      if(UID != '' && QueueUser == 'Queue')
      {
      if( selectedUser == '' || selectedUser == null ) 
        {

        System.debug('****************test***'+selectedUser)    ;
        string str = '%'+UID+'%';
        list<QueueSobject> Qu = [Select Queue.Name, QueueId From QueueSobject where SobjectType ='Siebel_Quote__C' and Queue.Name Like : str ];
        if(Qu.size() > 1){
          for(QueueSobject Qe : Qu){
            showLookup = false ;
            SelectedUserList .add(new selectoption (Qe.QueueId,Qe.Queue.Name));
            UerId = Qu[0].QueueId;
            selectedUser = Qu[0].QueueId;
          }

            System.debug('****************Qu.size() > 1***')    ;
            ApexPages.Message errMsg= new ApexPages.Message(ApexPages.severity.ERROR,'Multiple Queues found. Select from the drop-down or click icon to refine search.');  
            ApexPages.addMessage(errMsg);

          return null;
        }else if( Qu.size() == 0){
            System.debug('***************Qu.size() == 0**') ;
          ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'No matching Queue found.'));
           return null;
        }else if(Qu.size() == 1 ){
           System.debug('***************er.size() == 1**')  ;
           UerId = Qu[0].QueueId;
        }
        }else 
           UerId = selectedUser;
      }
     /* else{
        system.debug('Else you came here');
          UerId = UsQeId;
      }*/
      
      system.debug('  CONTACT ID   '+cntid);
      if((OppId == null || OppId == '') && (CntId == null || CntId == '') && ( AccId == null ||AccId == '') )
      {
        pageRef = new PageReference('/a1m/e?retURL=%2F'+'a1m'+'&00N40000002R00z=' + UerId+'&RecordType=' + recTy+'&nooverride=1');
      }
      
      
      if((OppId == null || OppId == '') && (CntId != null && CntId != '') && ( AccId != null && AccId != '') )
      {
        pageRef = new PageReference('/a1m/e?CF00N40000002R00n='+ nomUtil.urlEncode(contactName) +'&CF00N40000002R00n_lkid='+CntId+'&retURL=%2F'+CntId+'&00N40000002R00z=' + UerId+'&RecordType=' + recTy+'&CF00N40000002R00m='+ nomUtil.urlEncode(accN[0].Name) +'&CF00N40000002R00m_lkid='+AccId+'&CF00N40000001nb0p='+Con + '&CF00N40000001nb0p_lkid='+ ContId+'&nooverride=1');
      }
      
      if((OppId == null || OppId == '') && (CntId != null && CntId != '') && ( AccId != null && AccId != '') && (recTy=='0124000000015SgAAI' || recTy=='0124000000016lkAAA'))
      {
        pageRef = new PageReference('/apex/customeradminactivity?CF00N40000002R00n='+ nomUtil.urlEncode(contactName) +'&CF00N40000002R00n_lkid='+CntId+'&retURL=/'+CntId+'&saveURL=/apex/displaypli&00N40000002R00z=' + UerId+'&RecordType=' + recTy+'&CF00N40000002R00m='+ nomUtil.urlEncode(accN[0].Name) +'&CF00N40000002R00m_lkid='+AccId+'&CF00N40000001nb0p='+Con + '&CF00N40000001nb0p_lkid='+ ContId+'&nooverride=1');
      }
      
      if((OppId == null || OppId == '') && (CntId == null || CntId == '') && ( AccId != null && AccId != ''))
      {
      pageRef = new PageReference('/a1m/e?CF00N40000002R00m='+ nomUtil.urlEncode(accN[0].Name) +'&CF00N40000002R00m_lkid='+AccId+'&retURL=%2F'+AccId+'&00N40000002R00z=' + UerId+'&RecordType=' + recTy+'&CF00N40000001nb0p='+Con+'&CF00N40000001nb0p_lkid=' + ContId+'&nooverride=1');
      }
      
      if((OppId == null || OppId == '') && (CntId == null || CntId == '') && ( AccId != null && AccId != '') && (recTy=='0124000000015SgAAI' || recTy=='0124000000016lkAAA'))
      {
      pageRef = new PageReference('/apex/customeradminactivity?CF00N40000002R00m='+ nomUtil.urlEncode(accN[0].Name) +'&CF00N40000002R00m_lkid='+AccId+'&retURL=/'+AccId+'&saveURL=/apex/displaypli&00N40000002R00z=' + UerId+'&RecordType=' + recTy+'&CF00N40000001nb0p='+Con+'&CF00N40000001nb0p_lkid=' + ContId+'&nooverride=1');
      }
      
      if( OppId != null && OppId != '' && (recTy=='0124000000015SgAAI' || recTy=='0124000000016lkAAA'))
      {      
        //system.debug('Entered display PLI loop : Rectype ID:'+recTy);
        pageRef = new PageReference('/apex/customeradminactivity?CF00N40000001nb0s='+ nomUtil.urlEncode(Optm[0].Name) +'&CF00N40000001nb0s_lkid='+OppId+'&retURL=/'+OppId+'&saveURL=/apex/displaypli&CF00N40000002R00m='+ nomUtil.urlEncode(accN[0].Name) +'&CF00N40000002R00m_lkid='+AccId+'&00N40000002R00z=' + UerId+'&RecordType=' + recTy+'&CF00N40000001nb0p='+Con+'&CF00N40000001nb0p_lkid=' + ContId+'&nooverride=1');
      }
      
    /*  if((OppId == null || OppId == '') && (CntId != null && CntId != '') && ( AccId != null && AccId != '') && (recTy=='0124000000015dZAAQ' || recTy=='0124000000016lkAAA'))
      {
        pageRef = new PageReference('/apex/customeradminactivity?CF00N40000002R00n='+ nomUtil.urlEncode(contactName) +'&CF00N40000002R00n_lkid='+CntId+'&retURL=/'+CntId+'&saveURL=/apex/displaypli&00N40000002R00z=' + UerId+'&RecordType=' + recTy+'&CF00N40000002R00m='+ nomUtil.urlEncode(accN[0].Name) +'&CF00N40000002R00m_lkid='+AccId+'&CF00N40000001nb0p='+Con + '&CF00N40000001nb0p_lkid='+ ContId+'&nooverride=1');
      }
      
      if((OppId == null || OppId == '') && (CntId == null || CntId == '') && ( AccId != null && AccId != '') && (recTy=='0124000000015dZAAQ' || recTy=='0124000000016lkAAA'))
      {
      pageRef = new PageReference('/apex/customeradminactivity?CF00N40000002R00m='+ nomUtil.urlEncode(accN[0].Name) +'&CF00N40000002R00m_lkid='+AccId+'&retURL=/'+AccId+'&saveURL=/apex/displaypli&00N40000002R00z=' + UerId+'&RecordType=' + recTy+'&CF00N40000001nb0p='+Con+'&CF00N40000001nb0p_lkid=' + ContId+'&nooverride=1');
      }
      
      if( OppId != null && OppId != '' && (recTy=='0124000000015dZAAQ' || recTy=='0124000000016lkAAA'))
      {      
        //system.debug('Entered display PLI loop : Rectype ID:'+recTy);
        pageRef = new PageReference('/apex/customeradminactivity?CF00N40000001nb0s='+ nomUtil.urlEncode(Optm[0].Name) +'&CF00N40000001nb0s_lkid='+OppId+'&retURL=/'+OppId+'&saveURL=/apex/displaypli&CF00N40000002R00m='+ nomUtil.urlEncode(accN[0].Name) +'&CF00N40000002R00m_lkid='+AccId+'&00N40000002R00z=' + UerId+'&RecordType=' + recTy+'&CF00N40000001nb0p='+Con+'&CF00N40000001nb0p_lkid=' + ContId+'&nooverride=1');
      }*/
      
      else if(OppId != null && OppId != '')
      {
        //system.debug('Exitloop : Rectype ID:'+recTy);
        pageRef = new PageReference('/a1m/e?CF00N40000001nb0s='+ nomUtil.urlEncode(Optm[0].Name) +'&CF00N40000001nb0s_lkid='+OppId+'&retURL=%2F'+OppId+'&CF00N40000002R00m='+ nomUtil.urlEncode(accN[0].Name) +'&CF00N40000002R00m_lkid='+AccId+'&00N40000002R00z=' + UerId+'&RecordType=' + recTy+'&CF00N40000001nb0p='+Con+'&CF00N40000001nb0p_lkid=' + ContId+'&nooverride=1');
      }
      
     // system.debug('test******************8888'+)

      system.debug('****** List value ownupd *********' + SelectedUserList);      
      pageRef.setRedirect(true);
      system.debug('  PAGE REF   '+pageRef);
      return pageRef;

Thanks in Advance.

Best regards,
Niraj Kumar

 
Hi,

Vf page working fine in salesforce but not updating user field in salesforce1 after selection of user.

Here is my code.
 
<apex:page id="pg" standardController="Siebel_Quote__c" extensions="RequestSiebelQuote" tabStyle="Siebel_Quote__c" action="{!CheckForSOS}" standardStylesheets="true">
<script>
    function test(){
    
     // alert('You are here');
        UsQe = document.getElementById('pg:frm:Pb:pbs:UsrSelLst').value;
        UsQeId = document.getElementById('pg:frm:Pb:pbs:UsrSelLst').value;
        UsQeId = document.getElementById('pg:frm:Pb:pbs:HdUsrSelId').value;
        var retvalId = UsQeId;
       // alert('test+'+retvalId);
         ReturnValueUpdateAction(retvalId);
    
    }
    
    
    function getCheckedValue() { 
    //alert('Inside JS');
     var rt = document.getElementById('pg:frm:Pblk:SelLstRT').value;
      var UsQe= '' ;
        if(document.getElementById('pg:frm:Pb:pbs:UsrSelLst') != null) 
      { 
    //   alert('text'+ document.getElementById('pg:frm:Pb:pbs:UsrSelLst').text);
    //   alert('value'+ document.getElementById('pg:frm:Pb:pbs:UsrSelLst').value);     

        UsQe = document.getElementById('pg:frm:Pb:pbs:UsrSelLst').value;
        UsQeId = document.getElementById('pg:frm:Pb:pbs:UsrSelLst').value;
      
       
        
        ownerUpdateAction(own,UsQeId,rt,main,contId);
      }

       var statustxt = document.getElementById('pg:frm:Pb:pbs:txtHd2').value;
      if(statustxt != '')
      { 
         UsQe=document.getElementById('pg:frm:Pb:pbs:txtHd2').value;
      }
       var UsQeId;
       var ch = false;
       var LUch = false;
      // var rt = document.getElementById('pg:frm:Pblk:SelLstRT').value;
       var radio = document.getElementsByName('sos');
       var LUradio = document.getElementsByName('LUsos');
       for(var j=0; j < radio.length; j++)
       {
       if(radio[j].checked)
       ch = true;
       }  
       
       for(var s=0; s < LUradio.length; s++)
       {
       if(LUradio[s].checked)
       LUch = true;
       }
        
        var own;
        var main;
        var contId;
        if(rt == '')
       {
       alert("Please select a Customer Admin Activity type and then proceed.");
        return false;
       }
       if(UsQe == '' && ch == false && LUch == false)
       {
       alert("Please select either User/Queue or select a member from Account Owner's Default Sales team as Owner or select a member from running user's Default Sales team as Owner");
       }
       else if(UsQe != '' && ch == true && LUch == true)
       {
       alert("Please select only a User/Queue or a member from the Account Owner's Default Sales Team or a member from the running user's Default Sales Team - Delete the User/Queue value if you want to select a Default Sales Team member"); 
       
       var radList = document.getElementsByName('sos');
        for (var r = 0; r < radList.length; r++) 
        {
        if(radList[r].checked) 
        radList[r].checked = false;
        }
        var LUradList = document.getElementsByName('LUsos');
        for (var m = 0; m < LUradList.length; m++) 
        {
        if(LUradList[m].checked) 
        LUradList[m].checked = false;
        }
        
       }
       
       else if(UsQe != '' && ch == true)
       {
       alert("Please select only a User/Queue or a member from the Account Owner's Default Sales Team - Delete the User/Queue value if you want to select a Default Sales Team member"); 
       
       var radList = document.getElementsByName('sos');
        for (var r = 0; r < radList.length; r++) 
        {
        if(radList[r].checked) 
        radList[r].checked = false;
        }
       }
        
       else if(UsQe != '' && LUch == true)
       {
       alert("Please select only a User/Queue or a member from the Running User's Default Sales Team - Delete the User/Queue value if you want to select a Default Sales Team member"); 
       
       var LUradList = document.getElementsByName('LUsos');
        for (var m = 0; m < LUradList.length; m++) 
        {
        if(LUradList[m].checked) 
        LUradList[m].checked = false;
        }
       }
       
       else if(ch == true && LUch == true)
       {
       alert("Please select either a member from the Account Owner's Default Sales Team or a member from the running user's Default Sales Team"); 
       
       var radList = document.getElementsByName('sos');
        for (var r = 0; r < radList.length; r++) 
        {
        if(radList[r].checked) 
        radList[r].checked = false;
        }
        var LUradList = document.getElementsByName('LUsos');
        for (var m = 0; m < LUradList.length; m++) 
        {
        if(LUradList[m].checked) 
        LUradList[m].checked = false;
        }
       }
        
       else if(UsQe != '' && ch == false && LUch == false)
        {
         if({!msc})
         {
            main=document.getElementById('txtUsrFrm').value;
            contId =document.getElementById('contId').value;
         }
          own=document.getElementById('pg:frm:Pb:pbs:txtHd2').value;
          UsQeId=document.getElementById('pg:frm:Pb:pbs:txtHdId').value;
          ownerUpdateAction(own,UsQeId,rt,main,contId);
        }
       
       else  if({!show} && ch == true){
        var arr = new Array();
        arr = document.getElementsByName('sos');
        if({!msc}){
         main=document.getElementById('txtUsrFrm').value;
         contId =document.getElementById('contId').value;
       }
       if(ch == true)
       {
        for(var i = 0; i < arr.length;i++)
           {
            var obj = document.getElementsByName('sos').item(i);
            if(obj.checked){
                 UsQeId=obj.value;
                 ch=true;
             }
           }
       }
           ownerUpdateAction(own,UsQeId,rt,main,contId);
       } 
       
       else  if({!showLU} && LUch == true){ 
        var arr1 = new Array();
        arr1 = document.getElementsByName('LUsos');
        
        if({!msc}){
         main=document.getElementById('txtUsrFrm').value;
         contId =document.getElementById('contId').value;
       }
       if(LUch == true)
       {    
           for(var a = 0; a < arr1.length;a++)
              {
            var obj1 = document.getElementsByName('LUsos').item(a);
            if(obj1.checked){
                 UsQeId=obj1.value;
                 ch1=true;
             }
           }
       }
           
           ownerUpdateAction(own,UsQeId,rt,main,contId);
       }
       
     }
     function openLookUp(id)
        {
             var newWindow = window.open( '/apex/Lookup_RQ?accId='+id , '_new', 'resizable=yes,scrollbars=yes,status=yes,toolbar=false,height=600,width=800,top=100,left=100');
             newWindow.creator=self;
        }
        
        function openQULookUp(id)
        {
            var txtval;
            var txtval1;
            txtval=document.getElementById('pg:frm:Pb:pbs:SelLst').value
            txtval1= '';
            if(document.getElementById('pg:frm:Pb:pbs:txtHd2') != null) 
               txtval1=document.getElementById('pg:frm:Pb:pbs:txtHd2').value;
            else {
               var p = document.getElementById('pg:frm:Pb:pbs:UsrSelLst').selectedIndex ;
               txtval1 = document.getElementById('pg:frm:Pb:pbs:UsrSelLst').options[p].text
             }
             
             if(txtval == 'User')
             { 
             var newWindow = window.open( '/apex/UsrLookup?UsrId='+txtval1+'&selected=user&accId='+id, '_new', 'resizable=yes,scrollbars=yes,status=yes,toolbar=false,height=600,width=800,top=100,left=100');
             newWindow.creator=self;
             }
             else if (txtval == 'Queue')
             {
             var newWindow = window.open( '/apex/QueLookup?QueId='+txtval1+'&selected=Queue&accId='+id, '_new', 'resizable=yes,scrollbars=yes,status=yes,toolbar=false,height=600,width=800,top=100,left=100');
             newWindow.creator=self;
             }
             
        }
  </script>
<apex:form id="frm">
 <apex:pagemessages />
  
  
  
   <apex:actionFunction name="ReturnValueUpdateAction" action="{!ReturnValueUpdate}"   rerender="pg:frm:Pb:pbs:OutList">
         <apex:param name="ReturnValId" assignTo="{!ReturnValId}" value="" id="RvId"/>
        
    </apex:actionFunction>     
  
  <apex:actionFunction name="ownerUpdateAction" action="{!OwnerUpdate}" rerender="frm">
         <apex:param name="UID" assignTo="{!UID}" value="" id="t"/>
         <apex:param name="UsQeId" assignTo="{!UsQeId}" value="" id="UQ"/>
         <apex:param name="rt" assignTo="{!rt}" value="" id="RT"/>
         <apex:param name="Con" assignTo="{!Con}" value="" id="l"/>
         <apex:param name="ContId" assignTo="{!ContId}" value="" id="s"/>
  </apex:actionFunction>
  
    
      
    <apex:pageBlock id="Pblk" title="Select 'Customer Admin Activity' type">  
     <apex:outputLabel id="OLb" style="vertical-align:text-top;font-weight : bold" value="Customer Admin Activity Type">
     <img src="/s.gif" alt="Help" class="helpOrb" title="{!helptext}"/></apex:outputLabel> 
       
         <apex:selectList value="{!RecordType}" size="1" id="SelLstRT">
          
         <apex:selectOptions value="{!RTValues}" id="SelOptIdRT"/>
         </apex:selectList>
     
    </apex:pageBlock> 
        
    <apex:pageBlock id="Pb" title="Select 'Customer Admin Activity Record' Owner">
        <apex:pageBlockSection id="pbs" title="Please assign this to a Sales Order Specialist from yours or the Account Owner Sales Team or Queue" >  
           
        
         

<!-- Your SOS-->
<apex:outputlabel style="font-weight:bold;margin-top:10px">Select from your Sales Order Specialist Team Members</apex:outputlabel><br/>
      <apex:pageBlockTable style="margin-bottom:20px" value="{!LoggedUTM}" var="o" >
              <apex:column headerValue="Name">
                  <apex:OutputText value="{!o.User.Name}"/>
              </apex:column>  
             <apex:column headerValue="Role">
                   <apex:OutputText value="{!o.User.tfcrmTeamRole__c}"/>
             </apex:column> 
             <apex:column headerValue="Select a Member">
                  <input type="radio" name='LUsos' value="{!o.User.Id}"/>               
             </apex:column>             
       </apex:pageBlockTable>
<br/>

<!-- AM SOS-->

          <apex:outputlabel style="font-weight:bold;margin-top:10px">OR Select from the Account Owner Sales Order Specialist Team Members</apex:outputlabel><br/>
       <apex:pageBlockTable style="margin-bottom:20px" value="{!utm}" var="o" >
              <apex:column headerValue="Name">
                  <apex:OutputText value="{!o.User.Name}"/>
              </apex:column>  
             <apex:column headerValue="Role">
                   <apex:OutputText value="{!o.User.tfcrmTeamRole__c}"/>
             </apex:column> 
             <apex:column headerValue="Select a Member">
                  <input type="radio" name='sos' value="{!o.User.Id}"/>               
             </apex:column>             
       </apex:pageBlockTable>  

<br/>
<!--U/Q lookup-->

<apex:outputlabel style="font-weight:bold;margin-top:10px">OR Search and select for a Sales Order Specialist or Queue</apex:outputlabel><br/>
<apex:outputPanel id="lookupQU"> 
            <apex:outputLabel id="Ol" style="text-align:left;font-weight : bold" value="Owner ">&nbsp;</apex:outputLabel>     

         
                <apex:selectList value="{!QueueUser}" size="1" id="SelLst"> 
                <apex:selectOptions value="{!Items}" id="SelOptId"/>   
                </apex:selectList>
                               &nbsp;
                <apex:outputpanel rendered="{!showLookup}">
                  <apex:inputText id="txtHd2" value="{!custAA.Owner.Name}"/> 
                 
                 <a href="#"  id="lookupPickTechMask1"  title="User or Queue LookUp (New Window)" onclick="openQULookUp('{!accountId}');">
                            <img src="/s.gif" alt="TechMask Lookup (New Window)"  class="lookupIcon" onblur="this.className = 

'lookupIcon';"    onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 

'lookupIcon';"    onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" title="User or Queue LookUp 

(New  Window)"/>
                  </a>             
                </apex:outputpanel>
                <apex:outputpanel rendered="{!NOT(showLookup)}" id="OutList">
                <apex:inputHidden id="HdUsrSelId" value="{!ReturnValId}"/>
                 <apex:selectList value="{!selectedUser}" size="1" id="UsrSelLst">
                   <apex:selectOptions value="{!SelectedUserList}"  id="UsrSelOpt" />
                   </apex:selectList>
                   <a href="#"  id="lookupPickTechMask1"  title="User or Queue LookUp (New Window)" onclick="openQULookUp

('{!accountId}');">
                            <img src="/" alt="TechMask Lookup (New Window)"  class="lookupIcon" onblur="this.className = 

'lookupIcon';"    onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 

'lookupIcon';"    onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" title="User or Queue LookUp 

(New  Window)"/>
                  </a>
                  <apex:pagemessages />
                </apex:outputpanel>
                <apex:inputHidden id="txtHdId" value="{!usqe}"/>
            </apex:outputPanel>
       
       
      
     </apex:pageBlockSection>
      </apex:pageBlock>      <br />  
    

        
     <apex:pageBlock title="Select a Main Sales Contact from the Account Hierarchy" rendered="{!(msc)}" helpTitle="Help for this Page" helpUrl="help">
         <apex:pageBlockSection columns="2">
            <apex:outputField value="{!conFunAcc.Account_Id__c}"/> 
             
             <apex:pageblockSectionItem >
                 <apex:outputlabel style="vertical-align:text-top;font-weight : bold">Main Sales Contact</apex:outputlabel>
                 <apex:outputPanel id="lookup">
                 <input type="text" id="txtUsrFrm"/>
                 <input type="hidden" id="contId"/>                
                     <apex:inputHidden id="txtHd" value="{!val}"/>
                     <a href="#"  id="lookupPickTechMask"  title="Main Sales Contact Lookup (New Window)" onclick="openLookUp('{!conFunAcc.Account_Id__c}');">
                            <img src="/s.gif" alt="TechMask Lookup (New Window)"  class="lookupIcon" onblur="this.className = 'lookupIcon';"    onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';"    onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" title="Main Sales Contact Lookup (New  Window)"/>
                         </a>
                 </apex:outputPanel> 
             </apex:pageblockSectionItem>
           </apex:pageBlockSection>
         </apex:pageBlock>
         <apex:outputLabel rendered="{!(msc)}" id="Ol" style="text-align:left;font-weight : bold" value="OR"></apex:outputLabel>
         
         
          <apex:outputPanel rendered="{!(!flag)}">
     <a href="/003/e?retURL=%2F003%2Fo&RecordType=0124000000059h2&ent=Contact&con4={!accName}">Create New Contact</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     </apex:outputPanel>
     <apex:outputPanel rendered="{!(flag)}">
<p>     <a href="/{!accountId}">Click here to assign a Main Sales Contact to the Account</a></p>
     </apex:outputPanel>
    <apex:outputPanel >
         <table>
               <tr>
               <td>&nbsp;</td>
               </tr>
               <tr>
               <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="button" onclick="JavaScript:getCheckedValue(); return false;"  value="Next"  id="nxt" /></td></tr>
        </table>
    </apex:outputPanel>
  </apex:form>
  <script>
      allradios = document.forms['pg:frm'].sos;
      if(allradios.length){
          allradios[0].checked = false;
      }else{
          allradios.checked = false;
      }     
      
      LUallradios = document.forms['pg:frm'].LUsos;
      if(LUallradios.length){
          LUallradios[0].checked = false;
      }else{
          LUallradios.checked = false;
      } 
      
  </script>
</apex:page>

 
Hi,

on my VF page ther is a picklist field country, If I want to change the saved Country INDIA to USA, After changing the picklist value it should show the Pop up message on ONCHANGE EVENT.



 
Hi,

Below is my trigger, its not counting the closed  Activity.
Need your help.
 
trigger AccountCounttask on task (after insert, after delete) {

  Set <Id> AccountIDs = new Set <Id> ();
  
  if(Trigger.isInsert ){
      for(Task tsk1: Trigger.new){
          if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == Account.getSObjectType()){
              AccountIDs .add(tsk1.WhatId);
          }
      }
  }
  if(Trigger.isDelete ){
      for(Task tsk1: Trigger.old){
         if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == Account.getSObjectType()){
              AccountIDs .add(tsk1.WhatId);
          }
      }  
  }
  if(AccountIDs.size()>0)
      ActivityTriggerHandler.UpdateActivityAccount(AccountIDs);
  
  // Recompute the Activities for Account
}
 
@future
       
         public static void UpdateActivityAccount(set<Id> AccountIDs ){
            MAP <Id,integer> AccountCntMap = new MAP <Id, integer>(); 
            integer count;
             for(ID id1: AccountIDs ){
                AccountCntMap .put(id1, 0);  
             }
             for(Task tsk1: [select WhatId, Id from Task where WhatId IN :AccountIDs ]){
                 count = AccountCntMap .get(tsk1.WhatId) + 1;
                 AccountCntMap .put(tsk1.WhatId, count);
             }
             for(Event ev1: [select WhatId, Id from Event where WhatId IN :AccountIDs ]){
                 count = AccountCntMap .get(ev1.WhatId) + 1;
                 AccountCntMap .put(ev1.WhatId, count);
             }
             LIST <Account> AccUpd = new LIST <Account>();
             for(Account Acc1: [SELECT Id, Count_of_Activity__c FROM Account WHERE Id IN :AccountIDs ]){
                count = AccountCntMap .get(Acc1.Id);
                Acc1.Count_of_Activity__c = count;
                 AccUpd .add(Acc1);
             }
             Database.update(AccUpd );
         }

 
I have a simple test class which has sufficient code coverage for Trigger in Partiel Sandbox.
I have 0 % Test coverage in Production.

I have executed the lines individually in Anonymous mode , the code executes properly without any issues.

While deploying i am using : Use specific test and not the default one to test only on test class and the trigger responsible
@isTest(SeeAllData=true) 
private class TestClassTest {
    
    Static testmethod void mytest1 () {
        
        Candidat__c c = new Candidat__c(name='z1', FirstName__c='t1', Email__c = 'test1@test.sf');
        insert c; 

        task e = new task (subject='zz1',whatid=c.id);      
        insert e;
    }

}

Any reason for my usecase ?
  • June 15, 2016
  • Like
  • 0
I have set Opporunity as private but still other users are able to see the opportunities which they do not owm.
1. Under Sharing Settings - Opportunity is set to Private
2. Account sharing rules - Opportunity is set to Private
3. Under Roles - Users in this role cannot access opportunities that they do not own that are associated with accounts that they do own is Selected

Cannot figure out what further needs to be done.

PLease suggest
Hi Experts,

I'm new to salesforce coding. I need a trigger for updating case fields based on account number.
For more information please find below image.

User-added image

Regards,
Manu
Hi guys,

I am working with a client who has over 250,000 records that need to be imported in the initial import of their data. Is there a tool that I can use that will allow me to import that volume in the initial import. They don't want to pay for a subription as once the data is on the system then that's it, there won't be anymore mass imports.
Hi,

Could you help instruct how I could get ids for standard fields, instead of their API names. For example, when you inspect the account name field on a html, the id shows as "acc2". The "acc2" is what I want, but is it possible to retrieve them all in one time? 

Thank you very much!
Hi Everyone,

I would like to delete all of my Role, but there are all assign to users  (and i have a lot of users ),
so i'm trying to do an SOQL request through Workbench, but it doesn't works..
 
UPDATE User
SET UserRoleId = "NULL" 
Where UserRoleId ="NOT NULL" ;


I don't know if i need quote or not, some of you have any ideas ?

Thanks you !!


 
Hi All,

I am new to salesforce triggers.  I have two object Doctor__c and Patient__c objects. One custom field Doctor_Code__c on Docor__c object and another custom field on Patient__C object. Patient object has lookup field Doctor__c. If Patient Doctor_Code__c equal to Doctors Doctor_Code__c then Doctor__C field should populate with Doctor Name on Patient Object. For this I have written the Apex class and calling the Apex Class in trigger. But I am not getting any field Update. Below is the Code.

Apex Class:
------------------
public Class UpdateDoctor
{
  public void updatedoctor1 (List<Doctor__C> doctors)
     {
         map<string, Doctor__C> ObjMap = new map<string, Doctor__C>();
         for(Doctor__C obj: doctors)
         {
              if (obj.Doctor_Code__C!= Null)
        {
            ObjMap.put(obj.Doctor_Code__C, obj);
        }
    }
      List<Patient__c> cases = [SELECT Id, Doctor_Code__c, Doctor__c FROM Patient__c WHERE Doctor_Code__c IN :ObjMap.KeySet()];
    List<Patient__c> caseUpdateList = new List<Patient__c>();
     for(Patient__c c: cases)
    {
        Doctor__C  obj = ObjMap.get(c.Doctor_Code__c);
        c.Doctor__C= obj.Id;
         caseUpdateList.add(c);
    }
     }
}

Trigger
----------
trigger UpdateDoctortrigger  on Doctor__c( before insert,before update) {
    list<Doctor__c> doctors = trigger.new;
    UpdateDoctor my = new UpdateDoctor();
    my.updatedoctor1 (doctors);
  }

Please help on this issue.

Thanks in Advance.
Hi Guys,

I need a trigger to count all task associated with Account, Contact and opportunity .Update the Account count field in Account .
Eg- Account have 2 task and related Contact and opportunity related to this Account have one one task respectively.
In Account count field Show 5 instead of 2.

Thanks in Advance
Hi Guys,

I need a soql query to get all task related to Account, Contact, opportunity.

Thanks.
Hi Guys,

I need a trigger to count the task of Account, Contact, opportunity and update in the Account count field with sum of Account task, Contact task, Opportunity task.

EX - Create a Account, create 2 task on Account, create a contact related to this account and create 1 task, create a opportunity related to this account  create 2 task. In Account Count Field it shoud be 5 taks.
Hi,
Hhere is the task trigger and class for counting count of activity.Old task of existing Account is not counting .

Here is code.
 
trigger AccountCounttask on task (after insert, after delete) {

  Set <Id> AccountIDs = new Set <Id> ();
  
  if(Trigger.isInsert ){
      for(Task tsk1: Trigger.new){
          if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == Account.getSObjectType()){
              AccountIDs .add(tsk1.WhatId);
          }
      }
  }
  if(Trigger.isDelete ){
      for(Task tsk1: Trigger.old){
         if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == Account.getSObjectType()){
              AccountIDs .add(tsk1.WhatId);
          }
      }  
  }
  if(AccountIDs.size()>0)
      ActivityTriggerHandler.UpdateActivityAccount(AccountIDs);
  
  // Recompute the Activities for Account
}
@future
       
         public static void UpdateActivityAccount(set<Id> AccountIDs ){
            MAP <Id,integer> AccountCntMap = new MAP <Id, integer>(); 
            integer count;
             for(ID id1: AccountIDs ){
                AccountCntMap .put(id1, 0);  
             }
             for(Task tsk1: [select WhatId, Id from Task where WhatId IN :AccountIDs ]){
                 count = AccountCntMap .get(tsk1.WhatId) + 1;
                 AccountCntMap .put(tsk1.WhatId, count);
             }
             for(Event ev1: [select WhatId, Id from Event where WhatId IN :AccountIDs ]){
                 count = AccountCntMap .get(ev1.WhatId) + 1;
                 AccountCntMap .put(ev1.WhatId, count);
             }
             LIST <Account> AccUpd = new LIST <Account>();
             for(Account Acc1: [SELECT Id, Count_of_Activity__c FROM Account WHERE Id IN :AccountIDs ]){
                count = AccountCntMap .get(Acc1.Id);
                Acc1.Count_of_Activity__c = count;
                 AccUpd .add(Acc1);
             }
             Database.update(AccUpd );
         }

Thanks in Advance.

 
Hi guys,

I am getting error :::Apex trigger UpdateActivityCountonAccountContactOptytask caused an unexpected exception, contact your administrator: UpdateActivityCountonAccountContactOptytask: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.UpdateActivityCountonAccountContactOptytask: line 135, column 1
trigger UpdateActivityCountonAccountContactOptytask on task (after insert, after delete, after update) {

 
  map<id,integer> mopportunityCount = new map<id,integer>();
  map<id,integer> maccountCount = new map<id,integer>();
  map<id,integer> mcontactCount = new map<id,integer>();
  
  Integer OptyCount = 0;
 Integer AccountCount = 0;
 Integer ContactCount = 0;


  if (trigger.isinsert  || trigger.isUpdate ){

  for(task t :trigger.new) {
  
  if(t.whatId != null) {
  
    if(string.valueOf(t.WhatId).left(3) == '001') {
         
         
         if(maccountCount .containsKey(t.WhatId)) {
           AccountCount = maccountCount.get(t.WhatId);
            }
         
         AccountCount = AccountCount + 1;
         maccountCount.put(t.WhatId,AccountCount );
      }
    
      if(string.valueOf(t.WhatId).left(3) == '006') {
         
         
         if(mopportunityCount.containsKey(t.WhatId)) {
           OptyCount = mopportunityCount.get(t.WhatId);
            }
         
         OptyCount = OptyCount + 1;
      
         mopportunityCount.put(t.whatid,OptyCount);
      }
    }

    if(t.whoId != null) {
      if(string.valueOf(t.WhoId).left(3) == '003') {
         
         
         if(mcontactCount.containsKey(t.WhoId)) {
           ContactCount  = mcontactCount.get(t.WhoId);
            }
         
         ContactCount  = ContactCount  + 1;
      
         mcontactCount.put(t.whoid,ContactCount );
      }
    }
  }
 }
 
  if (trigger.isdelete){
   for(task t :trigger.old) {

    if(t.whatId != null) {
  
    if(string.valueOf(t.WhatId).left(3) == '001') {
         
         
         if(maccountCount .containsKey(t.WhatId)) {
           AccountCount = maccountCount.get(t.WhatId);
            }
         
         AccountCount = AccountCount - 1;
         maccountCount.put(t.WhatId,AccountCount );
      }
    
      if(string.valueOf(t.WhatId).left(3) == '006') {
         
         
         if(mopportunityCount.containsKey(t.WhatId)) {
           OptyCount = mopportunityCount.get(t.WhatId);
            }
         
         OptyCount = OptyCount - 1;
      
         mopportunityCount.put(t.whatid,OptyCount);
      }
    }
  
    if(t.whoId != null) {
      if(string.valueOf(t.WhoId).left(3) == '003') {
         
         
         if(mcontactCount.containsKey(t.WhoId)) {
           ContactCount  = mcontactCount.get(t.WhoId);
            }
         
         ContactCount  = ContactCount  - 1;
      
         mcontactCount.put(t.whoid,ContactCount );
      }
    }
  }
}

  if(mcontactCount.keyset().size()>0) {
    list<contact> contactToUpdate = new list<contact>([SELECT id,Count_of_Activity__c FROM contact WHERE Id IN :mcontactCount.keyset()]);

    if(contactToUpdate.Size() > 0)
    for(contact c :contactToUpdate) {

    if(c.Count_of_Activity__c != null)    
    c.Count_of_Activity__c = c.Count_of_Activity__c + mcontactCount.get(c.id);
    }
   
    if(contactToUpdate.size()>0) {
      update contactToUpdate;
    }
   } 
 

  if(mopportunityCount.keyset().size()>0) {
    list<opportunity> opportunityToUpdate = new list<opportunity>([SELECT id,Count_of_Activity__c FROM opportunity WHERE Id IN :mopportunityCount.keyset()]);
     for(opportunity o :opportunityToUpdate ) {
     o.Count_of_Activity__c = o.Count_of_Activity__c + mopportunityCount.get(o.id);
    }
   if(opportunityToUpdate.size()>0) {
      update opportunityToUpdate;
    }
   } 
   if(maccountCount.keyset().size()>0) {
    list<account> accountToUpdate = new list<account>([SELECT id,Count_of_Activity__c FROM account WHERE Id IN :maccountCount.keyset()]);

    for(account a :accountToUpdate ) {

        
    a.Count_of_Activity__c = a.Count_of_Activity__c + maccountCount.get(a.id);
    }
   
    if(accountToUpdate.size()>=0) {
      update accountToUpdate;
    }
   } 
  }