• kittu9
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 72
    Questions
  • 45
    Replies

res = http.send(req);
       pdf=res.getBody();

 

Getting Result every thing fine. But displaying that text in vf page got problem. The text displaying like below in the vf page. How to display result in proper format??????

 

<?xml version='1.0' ?> <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'> <env:Body>
<env:Fault> <faultcode>env:Client</faultcode> <faultstring>Internal Error</faultstring> </env:Fault>
</env:Body> </env:Envelope>

 

 

  • November 13, 2013
  • Like
  • 0



public class ActTrigger {

public List<Contact> listContactObj = new List<Contact>(); // List to store the Contacts
public List<Opportunity> listOpportunityObj = new List<Opportunity>();//List to store Opportunities
public List<Contract> listContractObj = new List<Contract>();//List to store Contracts
public List<task> listTaskObj = new List<task>();// List to store Tasks
public List<Event> listEventObj = new List<Event>();// List to store Events
public Set<String> ownerIds = new Set<String>();
public Map<String,Account> managerAccMap = new Map<String,Account>();
public Account[] oldMap = Trigger.old;
public Integer iCount =0;
public String sOwnerId = '';


public ActTrigger (){
}

public void AccRltdObjOwnChangeMethod (Set<Id> accountIds, Map<Id, String> newOwnerIdsMap){
      
       
      if (!accountIds.isEmpty()) {
      //SOQL to get Contact,Contacts, Open Activities and Opportunities for all updated Accounts         
      for (Account act : [SELECT Id, (SELECT Id, OwnerId FROM Contacts), (SELECT Id, OwnerId FROM Contracts),(SELECT Id, OwnerId FROM Opportunities),(SELECT Id, OwnerId,Status__c FROM events where isrecurrence = false and RecurrenceActivityId = null),(SELECT Id, OwnerId,Status FROM tasks where isrecurrence = false  and RecurrenceActivityId = null) FROM Account WHERE Id in :accountIds]) {
            
           //Updating Contact Owner with the Accounts New Ownerrelated to the Account
           for (Contact c : act.Contacts ) {
                c.OwnerId=newOwnerIdsMap.get(act.id);
                listContactObj.add(c);
           }
           
           //Updating Contract Owner with the Accounts New Owner related to the Account
           for (Contract c : act.Contracts) {
               c.OwnerId=newOwnerIdsMap.get(act.id);
               listContractObj.add(c);
                  
           }
           //Updating Opportunity Owner with the Accounts New Owner related to the Account
           for (Opportunity o : act.Opportunities) { //for all opportunities
               o.OwnerId =newOwnerIdsMap.get(act.id);
               listOpportunityObj.add(o);
           }
            
           //Updating Open Tasks Owner with the Accounts New Owner related to the Account  
           for (task t : act.tasks) {
               if(t.status=='Open' || t.status == 'Scheduled'){
               t.OwnerId =newOwnerIdsMap.get(act.id);
               listTaskObj.add(t);     
               }    
           }  
           //Updating Open Events Owner with the Accounts New Owner related to the Account
           for (Event e : act.events) {
               
               if(e.status__c=='Pending' || e.status__c == 'Scheduled'){
               e.OwnerId =newOwnerIdsMap.get(act.id);
               listEventObj.add(e);     
               }    
           }                    

       System.debug('$$$$$Events List'+listEventObj);
       }
        
       try {
       update listContactObj;
       update listContractObj;
       update listOpportunityObj;
       update listTaskObj;
       update listEventObj;
       }
 
       catch(Exception e) { //catch errors
       }
   }
}

public void AccRltdObjOwnChangeMethodBENDACH(Set<Id> accountIdsBENDACH, Map<Id, String> newOwnerIdsMapBENDACH){
      
       
      if (!accountIdsBENDACH.isEmpty()) {
      //SOQL to get Contact,Contacts for all updated Accounts         
      for (Account act : [SELECT Id, (SELECT Id, OwnerId FROM Contacts), (SELECT Id, OwnerId FROM Contracts),(SELECT Id, OwnerId FROM Opportunities),(SELECT Id, OwnerId,Status__c FROM events where isrecurrence = false and RecurrenceActivityId = null),(SELECT Id, OwnerId,Status FROM tasks where isrecurrence = false  and RecurrenceActivityId = null) FROM Account WHERE Id in :accountIdsBENDACH]) {
            
           //CR-20 Updating Contact Owner with the Accounts New Ownerrelated to the Account on 28-05-2013
           for (Contact c : act.Contacts ) {
                c.OwnerId=newOwnerIdsMapBENDACH.get(act.id);
                listContactObj.add(c);
           }
           
           //CR-18 Updating Contract Owner with the Accounts New Owner related to the Account on 28-05-2013
           for (Contract c : act.Contracts) {
               c.OwnerId=newOwnerIdsMapBENDACH.get(act.id);
               listContractObj.add(c);
           }                   
       }        
       try {
        update listContactObj;
        update listContractObj;
       }  
       catch(Exception e) { //catch errors
       }
   }
}


Public Void AccUpdateDateOfAssignment(Map<ID,Boolean> AccounUpdateMap,List<account> NewAccountList){
try{
List<Account> accountUpdateList = New List<Account>();//list of accounts whose date of assignment is to be changed
Set<ID> accOwnerNotchangedSet = New Set<ID>();//Account whose owners have not been changed
Map<ID,Date> OwnercreatedDate = New Map<ID,Date>();//this is used to track the latest owner change date
List<Date> CreatedDates = New List<Date>();
Set<ID> AccupdateDoASet = New Set<ID>();
Map<ID,Date> AccupdateNewCustomerMap = New Map<ID,Date>();
   for(Account accountList:[Select New_Customer__c,id,Date_Of_Assignment__c,Last_Successful_Call_Date__c from account where id IN:AccounUpdateMap.keySet()]){
         if(AccounUpdateMap.get(accountList.id)== True){
            AccupdateDoASet.add(accountList.id);
         }
    
     else
       accOwnerNotchangedSet.add(accountList.id);
       
  }
  /*Iterate through owner change history to find the last date of assignment*/
141:  for(account acclIst: [select id,Last_Successful_Call_Date__c,New_Customer__c, (select CreatedDate,OldValue, NewValue,field,AccountId from Histories) FROM account where id IN:accOwnerNotchangedSet]){
            
      for(AccountHistory accHis:acclIst.Histories){
         if(accHis.field == 'owner')
         CreatedDates.add(Date.valueof(accHis.CreatedDate));
      }
      If(CreatedDates.size()>0){
         CreatedDates.sort();
         OwnercreatedDate.put(acclIst.id,CreatedDates[(CreatedDates.size()-1)]);
         acclIst.Date_Of_Assignment__c= Date.valueof(CreatedDates[(CreatedDates.size()-1)]);    
         AccupdateNewCustomerMap.put(acclIst.id,Date.valueof(CreatedDates[(CreatedDates.size()-1)]));  
      }     
     }
      /*Update the date of assignemtn in account*/
      for(account ac:NewAccountList){
          if(AccupdateDoASet.contains(ac.id)){
            ac.Date_Of_Assignment__c= Date.Today();       
         }
         else if(AccupdateNewCustomerMap.containsKey(ac.id) ){
              //ac.Date_Of_Assignment__c = Date.valueof(CreatedDates[(CreatedDates.size()-1)]);    
              ac.Date_Of_Assignment__c = AccupdateNewCustomerMap.get(ac.id);
         }
        Date LastSuccessDate ;
        Date DateOfAssgn;
        DateTime doA = ac.Date_Of_Assignment__c;
        if(doA!=null)
        DateOfAssgn = date.newinstance(doA.year(), doA.month(), doA.day());
        
        DateTime Lsd = ac.Last_Successful_Call_Date__c;
        if(Lsd!=null)
        LastSuccessDate = date.newinstance(Lsd .year(), Lsd .month(), Lsd .day());
          
        If(ac.Date_Of_Assignment__c != Null){
           if(LastSuccessDate >= DateOfAssgn  )
             ac.New_Customer__c=False;
          }
         
      }
 }
  catch(Exception e) { //catch errors
  }
}
public void AccRepMangUpdateMethod (List<Account> AccIDList){

For(Account Acct : AccIDList){


if(Acct.Lead_Owner_ID__c!=null){
                Acct.owner_link__c =  Acct.Lead_Owner_ID__c;
                Acct.OwnerId = Acct.Lead_Owner_ID__c;
                ownerIds.add(Acct.Lead_Owner_ID__c);
                if(Acct.Lead_Owner_ID__c.length()>15)
                    sOwnerId = Acct.Lead_Owner_ID__c.substring(1,15);
                else
                    sOwnerId = Acct.Lead_Owner_ID__c;
                managerAccMap.put(sOwnerId+':'+Acct.Id,Acct);   
                }
                  
          else{
                Acct.owner_link__c = Acct.ownerId;
                ownerIds.add(Acct.ownerId);
                system.debug('**Acct.ownerId**'+Acct.ownerId);
                if(String.ValueOf(Acct.ownerId).length()>15)
                    sOwnerId = String.ValueOf(Acct.ownerId).substring(1,15);
                else
                    sOwnerId = Acct.ownerId;
                managerAccMap.put(sOwnerId+':'+Acct.Id,Acct);                
            }
      }
      if(ownerIds.size() > 0){
        Map<String,String> managerMap = new Map<String,String>();
        //system.Debug('@@@@@@@@@@@@ownerIds' + ownerIds);
        for (User u: [Select id,ManagerId from User where id in : ownerIds]){
            //if(u.managerId != null)
            if(String.ValueOf(u.id).length()>15)
                managerMap.put(String.ValueOf(u.id).substring(1,15),u.ManagerId);           
            else
                managerMap.put(u.id,u.ManagerId);
        }
        //system.Debug('@@@@@@@@@@@@managerMap' + managerMap);
        
        for(String accId: managerAccMap.keySet()){
            //system.Debug('@@@@@@@@@@@@accid' + accid);
            String[] sTemp = accid.split(':');
            //system.Debug('@@@@@@@@@@@@sTemp ' + sTemp );
            if(managerMap.containsKey(sTemp[0]) && managerMap.get(sTemp[0]) !=Null){
                (managerAccMap.get(accId)).Rep_manager__c = managerMap.get(sTemp[0]);
            }
            //system.Debug('@@@@@@@@@@@@(managerAccMap.get(accId)).Rep_manager__c ' + (managerAccMap.get(accId)).Rep_manager__c);
            //system.Debug('@@@@@@@@@@@@managerMap.get(sTemp[0] ' + managerMap.get(sTemp[0]));
        }
        //system.Debug('@@@@@@@@@@@@managerAccMap ' + managerAccMap);
        
    }         
                      
 }
 
public void AccRepMangUpdtMethod (List<Account> AccIDList){
For(Account Acct : AccIDList){

         acct.owner_link__c = acct.ownerId;
            ownerIds.add(acct.ownerId);
            if(String.ValueOf(acct.ownerId).length()>15)
                sOwnerId = String.ValueOf(acct.ownerId).substring(1,15);
            else
                sOwnerId = acct.ownerId;

            managerAccMap.put(sOwnerId+':'+acct.Id,acct);
            
}
if(ownerIds.size() > 0){
        Map<String,String> managerMap = new Map<String,String>();
        //system.Debug('@@@@@@@@@@@@ownerIds' + ownerIds);
        for (User u: [Select id,ManagerId from User where id in : ownerIds]){
            //if(u.managerId != null)
            if(String.ValueOf(u.id).length()>15)
                managerMap.put(String.ValueOf(u.id).substring(1,15),u.ManagerId);           
            else
                managerMap.put(u.id,u.ManagerId);
        }
        //system.Debug('@@@@@@@@@@@@managerMap' + managerMap);
        
        for(String accId: managerAccMap.keySet()){
            //system.Debug('@@@@@@@@@@@@accid' + accid);
            String[] sTemp = accid.split(':');
            //system.Debug('@@@@@@@@@@@@sTemp ' + sTemp );
            if(managerMap.containsKey(sTemp[0]) && managerMap.get(sTemp[0]) !=Null){
                (managerAccMap.get(accId)).Rep_manager__c = managerMap.get(sTemp[0]);
            }
            //system.Debug('@@@@@@@@@@@@(managerAccMap.get(accId)).Rep_manager__c ' + (managerAccMap.get(accId)).Rep_manager__c);
            //system.Debug('@@@@@@@@@@@@managerMap.get(sTemp[0] ' + managerMap.get(sTemp[0]));
        }
        //system.Debug('@@@@@@@@@@@@managerAccMap ' + managerAccMap);
        
    }       

}
 
public void CallPlannerMethod (List<Account> AccIDList){

For(Account Acct : AccIDList){

     if(acct.CallFrequencyOverride__c != 0 && acct.CallFrequencyOverride__c !=null){        
                    Integer DaystoBeAdded = Integer.valueOf(365/acct.CallFrequencyOverride__c);           
                           
                    for(integer i =0;i<7;i++){
                        
                        if(math.mod(DaystoBeAdded,7)==0){    
                        break;
                        }
                        DaystoBeAdded++;
                        }
                        if(acct.Last_Successful_Call_Date__c!=Null)
                        acct.Next_Call_Date__c = acct.Last_Successful_Call_Date__c  + DaystoBeAdded ;
                    }
                
        
                    
          else if (acct.Suggested_Call_Frequency__c != 0 && acct.Suggested_Call_Frequency__c !=null){
              Integer DaystoBeAdded = Integer.valueOf(365/acct.Suggested_Call_Frequency__c);
    
                for(integer i =0;i<7;i++){
                    
                    if(math.mod(DaystoBeAdded,7)==0){    
                    break;
                    }
                    DaystoBeAdded++;
                    }
                    
                    if(acct.Last_Successful_Call_Date__c!=Null)
                    acct.Next_Call_Date__c = acct.Last_Successful_Call_Date__c  + DaystoBeAdded ;
                   }
     }      
}   
     
}

  • November 12, 2013
  • Like
  • 0

how can we show more than 1000 records in visualforce page?

  • October 30, 2013
  • Like
  • 0

trigger EmailSend on Task(after insert, after update) {

try {
 Profile_allowed_to_runSendEmailToGroup__c getallprofiles=Profile_allowed_to_runSendEmailToGroup__c.getinstance('Profile Set 1');
        
        set<string>profileset=new set<string>();
        if(getallprofiles.get('Allowed_Profile__c')!=null)
        {
            string getprofilename=string.valueof(getallprofiles.get('Allowed_Profile__c'));
            list<string>profilelst=getprofilename.split(';');
            profileset.addAll(profilelst);
        }
        string profilename=[SELECT Id, Name FROM Profile WHERE Id=:userinfo.getProfileId() LIMIT 1].name;
        list < string > groupname = new list < string > ();
        List < String > mailAddrs = new List < String > ();
        String fullFileURL = URL.getSalesforceBaseUrl().toExternalForm();
        if(profileset.contains(profilename)==true)
        {
            List < id > Accoundid = new list < id > ();
            for (task t1: trigger.new) {
                if (t1.whatid != null && t1.what.type == 'Account') {
                    Accoundid.add(t1.whatid);
                }
                if (t1.Status == 'Completed') {
                    if (t1.Activity_Type__c == 'DPR')
                        groupname.add('SET DPR');
                    else if (t1.Activity_Type__c == 'GME')
                        groupname.add('SET GME');
                    else if (t1.Activity_Type__c == 'GM Changes')
                        groupname.add('SET GM CHANGES');
                    else if (t1.Activity_Type__c == 'Ownership Changes')
                        groupname.add('SET OWNERSHIP CHANGES');
                    else
                        groupname.add('SET ALL OTHERS');
                }
            }
            map < id, account > AccountMap = new map < id, account > ([select id, name from account where id In: Accoundid]);
            list < id > grpmemberid = new list < id > ();
            for (groupmember gm1: [select userOrGroupId from groupMember where group.name in : groupname]) {
                grpmemberid.add(gm1.userOrGroupId);
            }
            for (user u1: [select id, email from user where id IN: grpmemberid]) {
                mailAddrs.add(u1.email);
            }
            if (mailAddrs.size() > 0) {
                List < Messaging.SingleEmailMessage > allemail = new List < Messaging.SingleEmailMessage > ();
                for (task t1: trigger.new) {
                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                    mail.setToAddresses(mailAddrs);
                    string accountName;
                    if (t1.whatid != null && t1.what.type == 'Account') {
                        if (AccountMap.containskey(t1.whatid))
                            accountName = AccountMap.get(t1.whatid).name;
                        else
                            accountName = '';
                    }
                    mail.setSubject(t1.Activity_Type__c + ' : ' + accountName + ' Task Information');
                    mail.setPlainTextBody('A new Contact Report has been completed ' + '\n' + fullFileURL + '/' + t1.Id);
                    allemail.add(mail);
                }
                if (allemail.size() > 0) {
                    Messaging.sendEmail(allemail, false);
                }
            }
        }
  } catch (exception e) {
        system.debug('###' + e.getmessage());
    }
}

tThe above code is working fine. In custom setting have 3 records Profile Set 1,Profile Set 2,Profile Set 3 it is working fine for "Profile Set 1"

 

not working for remaining other. whr i have to change in code. pls help me on this.

  • October 18, 2013
  • Like
  • 0

 

trigger Trigger1 on Task (after insert,after update)
{
List<String> mlist = new List<String>();
List<String> mailAddrs = new List<String>();
String fURL = URL.getSalesforceBaseUrl().toExternalForm() ;


for(Task t : Trigger.new)

{
Account act = [select Name from Account where Id =: t.AccountId];
if(t.Status == 'Completed')
{
if( t.Activity_Type__c == 'Resolved')
{

Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET A'];

for (GroupMember gm : g.groupMembers)
{
mlist.add(gm.userOrGroupId);
}

User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr)
{
mailAddrs.add(u.email);

}
}
else if ( t.Activity_Type__c == 'Completed')

{
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET B'];
for (GroupMember gm : g.groupMembers)

{
mlist.add(gm.userOrGroupId);
}

User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr)
{
mailAddrs.add(u.email);
}
}

else if ( t.Activity_Type__c == 'In Progress')

{
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET C'];
for (GroupMember gm : g.groupMembers)

{
mlist.add(gm.userOrGroupId);

}
User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr)
{
mailAddrs.add(u.email);
}
}

else if ( t.Activity_Type__c == 'On Hold')

{
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET D'];
for (GroupMember gm : g.groupMembers)

{
mlist.add(gm.userOrGroupId);

}
User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr)
{
mailAddrs.add(u.email);
}
}

else
{
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET E'];

for (GroupMember gm : g.groupMembers) {
mlist.add(gm.userOrGroupId); }

User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr) { mailAddrs.add(u.email); }

}

if(mailAddrs != null || mailAddrs.size() > 0)
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setToAddresses(mailAddrs);

mail.setSubject(t.Activity_Type__c+' : '+act.Name+' Task Information');

mail.setPlainTextBody(' Contact Report has been completed '+'\n'+fURL+'/'+t.Id);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}

}
}

 

The above trigger is working fine. Can any one help to avoid Governor limits for this trigger. by using collections can do it. but am not able fix it please help me on this.

  • October 15, 2013
  • Like
  • 0

global with sharing class PopulateBatch implements Database.Batchable<sObject>{

global String Query;

public List<Corporate_Account_List_Assignment__c> calist { set; get; }


//given a AccountId and List<AccountTeamMember >, it returns the record having AccountId=AccoundId
public List<AccountTeamMember> findAccountTeamMember(Id accountId, Map<Id,List<AccountTeamMember>> acc_tmListMap, String teamMemberRole){
if(acc_tmListMap== null || acc_tmListMap.size() == 0 || accountId==null ){
return null;
}

integer count = 0;
List<AccountTeamMember> atmList = acc_tmListMap.get(accountId);
List<AccountTeamMember> atmRetList = new List<AccountTeamMember>();

if(atmList != null){
for(AccountTeamMember am: atmList){
if(am.TeamMemberRole == teamMemberRole){
atmRetList.add(am);
count++;
}
}
}
if(count > 0){
return atmRetList;
}else{
return null;
}
}
public Account findAccount(Id account_name,List<Account> accList ){
if(accList == null || accList.size() == 0 || account_name==null ){
return null;
}
for(Account am: accList){
if(am.Id == account_name){
return am;
}
}
return null;
}

global Populate_Corp_List_Assignments_Batch(String q){
Query=q;
}

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

return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC, List<Corporate_Account_List_Assignment__c> scope){


//calist = [SELECT Account_Name__c,Corporate_Partnership_Director_1__c,Corporate_Partnership_Director_2__c,Corporate_Partnership_Director_3__c,Corporate_Partnership_Director_4__c,Corporate_Partnership_Director_5__c,Marketing_Solutions_1__c, Marketing_Solutions_2__c, Marketing_Solutions_3__c, Media_Services_1__c, Media_Services_2__c, Media_Services_3__c, Digital_Manager_1__c,Digital_Manager_2__c,Digital_Manager_3__c,Digital_Manager_4__c,Digital_Manager_5__c, Id,Name,Ultimate_Parent_Name__c FROM Corporate_Account_List_Assignment__c];
//calist = [SELECT Account_Name__c,Corporate_Partnership_Director_1__c,Corporate_Partnership_Director_2__c,Corporate_Partnership_Director_3__c,Corporate_Partnership_Director_4__c,Corporate_Partnership_Director_5__c,Marketing_Solutions_1__c, Marketing_Solutions_2__c, Marketing_Solutions_3__c, Media_Services_1__c, Media_Services_2__c, Media_Services_3__c,Digital_Manager_1__c,Digital_Manager_2__c,Digital_Manager_3__c,Digital_Manager_4__c,Digital_Manager_5__c, Id,Name,Ultimate_Parent_Name__c FROM Corporate_Account_List_Assignment__c];
//prepare a map of ids and account_name__c
Map<Id,Id> ca_acc_map = new Map<Id,Id>();

for(Corporate_Account_List_Assignment__c ca : scope){

ca_acc_map.put(ca.Id,ca.Account_Name__c);

}


Map<Id,Account> ac2 = new Map<Id,Account>([SELECT Name,ParentId,Id FROM Account where Id in :ca_acc_map.values()]);
List<AccountTeamMember> atmcpd2 =[ SELECT Id,TeamMemberRole,UserId, IsDeleted,AccountId FROM AccountTeamMember WHERE AccountId in :ac2.keyset() AND Isdeleted = FALSE ];

Map<Id,List<AccountTeamMember>> acc_tmListMap = new Map<Id,List<AccountTeamMember>>();
for(AccountTeamMember atm: atmcpd2){
List<AccountTeamMember> atmlist;
if(acc_tmListMap.get(atm.AccountId) == null ){
atmlist = new List<AccountTeamMember>();

}else{
atmlist = acc_tmListMap.get(atm.AccountId);


}

atmList.add(atm);
acc_tmListMap.put(atm.AccountId,atmList);

}

for (Corporate_Account_List_Assignment__c ca : scope)
{
ca.Corporate_Partnership_Director_1__c = null;
ca.Corporate_Partnership_Director_2__c = null;
ca.Corporate_Partnership_Director_3__c = null;
ca.Corporate_Partnership_Director_4__c = null;
ca.Corporate_Partnership_Director_5__c = null;

ca.Digital_Manager_1__c = null;
ca.Digital_Manager_2__c = null;
ca.Digital_Manager_3__c = null;
ca.Digital_Manager_4__c = null;
ca.Digital_Manager_5__c = null;

ca.Marketing_Solutions_1__c = null;
ca.Marketing_Solutions_2__c = null;
ca.Marketing_Solutions_3__c = null;

ca.Media_Services_1__c = null;
ca.Media_Services_2__c = null;
ca.Media_Services_3__c = null;
System.debug('******ID********'+ca.Id);


//find atmcpd
Account accX = ac2.get(ca.Account_Name__c);
List<AccountTeamMember> atmcpd = findAccountTeamMember(accX.Id,acc_tmListMap,'Corporate Partnership Director' );
List<AccountTeamMember> atmMS = findAccountTeamMember(accX.Id,acc_tmListMap,'IMS');
List<AccountTeamMember> atmMDS = findAccountTeamMember(accX.Id,acc_tmListMap,'Media Services');
List<AccountTeamMember> atmDM = findAccountTeamMember(accX.Id,acc_tmListMap,'Digital Manager');


if(atmcpd!= null && atmcpd.size() > 0 )
{
if(atmcpd.size() > 0)
ca.Corporate_Partnership_Director_1__c = atmcpd.get(0).UserId;

if(atmcpd.size()>1)
ca.Corporate_Partnership_Director_2__c = atmcpd.get(1).UserId;

if(atmcpd.size()>2)
ca.Corporate_Partnership_Director_3__c = atmcpd.get(2).UserId;

if(atmcpd.size()>3)
ca.Corporate_Partnership_Director_4__c = atmcpd.get(3).UserId;

if(atmcpd.size()>4)
ca.Corporate_Partnership_Director_5__c = atmcpd.get(4).UserId;
}

if(atmms != null && atmms.size() > 0)
{
if(atmms.size() > 0)
ca.Marketing_Solutions_1__c = atmms.get(0).UserId;

if(atmms.size() > 1)
ca.Marketing_Solutions_2__c = atmms.get(1).UserId;

if(atmms.size() > 2)
ca.Marketing_Solutions_3__c = atmms.get(2).UserId;

}


if(atmmds != null && atmmds.size() > 0)
{
if(atmmds.size() > 0)
ca.Media_Services_1__c = atmmds.get(0).UserId;

if(atmmds.size() > 1)
ca.Media_Services_2__c = atmmds.get(1).UserId;

if(atmmds.size() > 2)
ca.Media_Services_3__c = atmmds.get(2).UserId;

}
if(atmdm != null && atmdm.size() > 0)
{
if(atmdm.size() > 0)
ca.Digital_Manager_1__c = atmdm.get(0).UserId;

if(atmdm.size() > 1)
ca.Digital_Manager_2__c = atmdm.get(1).UserId;

if(atmdm.size() > 2)
ca.Digital_Manager_3__c = atmdm.get(2).UserId;

if(atmdm.size() > 3)
ca.Digital_Manager_4__c = atmdm.get(3).UserId;

if(atmdm.size() > 4)
ca.Digital_Manager_5__c = atmdm.get(4).UserId;
}
}
update scope;

}

global void finish(Database.BatchableContext BC)
{

}
}

 

-------------------------

 

static testMethod void myUnitTest1()
{

Account a = new Account();
a.Name = 'Test';
a.Status__c = 'Prospect';
insert a;

Corporate_Account_List_Assignment__c caList = new Corporate_Account_List_Assignment__c();
caList.Account_Name__c = a.Id;
insert caList;


string query = 'SELECT Account_Name__c,Corporate_Partnership_Director_1__c,Corporate_Partnership_Director_2__c,Corporate_Partnership_Director_3__c,Corporate_Partnership_Director_4__c,Corporate_Partnership_Director_5__c,Marketing_Solutions_1__c, Marketing_Solutions_2__c, Marketing_Solutions_3__c, Media_Services_1__c, Media_Services_2__c, Media_Services_3__c,Digital_Manager_1__c,Digital_Manager_2__c,Digital_Manager_3__c,Digital_Manager_4__c,Digital_Manager_5__c, Id,Name,Ultimate_Parent_Name__c FROM Corporate_Account_List_Assignment__c';

Test.StartTest();


PopulateBatch   pcab = new  PopulateBatch (query);


ID batchprocessid = Database.executeBatch(pcab);


Test.StopTest();
}

 

Code coverage 44% can any one help me out to get 75%. thanks in advance.

  • October 09, 2013
  • Like
  • 0

public class UpdateFieldOnOpportunity implements Schedulable { public List Opp {set; get;} Public List<Insertion__c> Ins { set; get; } public Integer j = 0; public void updateFields() { Opp= [SELECT Id,Name,Account_Name__c, Formula_Video__c, Insertion__c FROM Opportunity WHERE Formula_Video__c > 0 ]; System.debug('*********Opportunities with Formula Video above Zero**********'+ Opp.size()); Ins = [SELECT Account__c,Id,Name,Formula_Video_Flag__c FROM Insertion__c ]; for(Insertion__c i : Ins) { i.Formula_Video_Flag__c = 'FALSE'; } update Ins; for (Insertion__c i : Ins) { System.debug('*******Insertion*********'+i); for(Opportunity o : opp) { if(I.id == o.Insertion__c) I.Formula_Video_Flag__c = 'TRUE'; else I.Formula_Video_Flag__c = 'FALSE'; j++; } System.debug('*******Update*********'); } update Ins; } }

  • October 02, 2013
  • Like
  • 0

public class UpdateFieldOnOpportunity implements Schedulable { public List Opp {set; get;} Public List<Insertion__c> Ins { set; get; } public Integer j = 0; public void updateFields() { Opp= [SELECT Id,Name,Account_Name__c, Formula_Video__c, Insertion__c FROM Opportunity WHERE Formula_Video__c > 0 ]; System.debug('*********Opportunities with Formula Video above Zero**********'+ Opp.size()); Ins = [SELECT Account__c,Id,Name,Formula_Video_Flag__c FROM Insertion__c ]; for(Insertion__c i : Ins) { i.Formula_Video_Flag__c = 'FALSE'; } update Ins; for (Insertion__c i : Ins) { System.debug('*******Insertion*********'+i); for(Opportunity o : opp) { if(I.id == o.Insertion__c) I.Formula_Video_Flag__c = 'TRUE'; else I.Formula_Video_Flag__c = 'FALSE'; j++; } System.debug('*******Update*********'); } update Ins; } }

  • October 02, 2013
  • Like
  • 0

Hi,

 

 I need to migrate the data from one sand box to another sandbox. When am migrating the records of one particular object. In that object for some records have the records in Open Activities & Activity History. Want to migrate those records also. How to do that please give the steps for that.

 

 

  • August 22, 2013
  • Like
  • 0

<apex:page standardController="Template__c" extensions="WidgetController">
<script>
function displayFields()
{
var wtype = document.getElementById('{!$Component.frm1.pblock.pbsection.type}').value;

if( wtype == 'Post Category')
{
alert(wtype);

document.getElementById('{!$Component.frm1.pblock.pbsection.title}').visible = false ;

}
}
</script>
<apex:form id="frm1">
<apex:pageBlock id="pblock">
<apex:pageBlockButtons >

<apex:commandButton value="Save"/>
<apex:commandButton value="Cancel"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Information" collapsible="false" columns="1" id="pbsection">
<apex:inputField value="{!tmptWidget.Type__c}" id="type" onchange="displayFields();"/>
<apex:inputField value="{!tmptWidget.Page__c}" id="template"/>
<apex:inputField value="{!tmptWidget.Title__c}" id="title"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Here Type__c is picklist based on pick list selected value want to visible one field in vf page and remaining other field want to hide how we can do it through java script. Please give inputs for this. I did like above but not working. pls let me know wht mistake i done in above code

  • August 13, 2013
  • Like
  • 0

public class HSRData  
{
public Boolean b {set; get; }
  public List<Hot_Sheet__c> HSR1 { set; get; }
   public List<Hot_Sheet__c> hst { set; get; }
  
  public Set<String> hotset { set;get;}
  
public  List<Hot_Sheet__c> lst {set;get;}
public  List<Hot_Sheet__c> lst1 {set;get;}
public  List<Hot_Sheet__c> lst2 {set;get;}

  public List<User> usrls { set; get; } 
  public Hot_Sheet__c HSRobj1; 
  public Hot_Sheet__c HSRobj2;
  public Id recid { set; get; }
  public string msg { set; get; }
  public string msg1 { set;get;}
  public string val { set; get; } 
  
   public Id accid { set; get; }
     public Hot_Sheet__c getHSRObj1()
    {
     if (HSRobj1 == null)
     {
      HSRobj1 = new Hot_Sheet__c();
      return HSRobj1;
     }
     else
       return HSRobj1;
    }
    
   public Hot_Sheet__c getHSRObj2()
    {
     if (HSRobj2 == null)
     {
      HSRobj2 = new Hot_Sheet__c();
      return HSRobj2;
     }
     else
       return HSRobj2;
    }
    
     public HSRData(ApexPages.StandardController controller) {
      b = true;
        usrls = [SELECT CompanyName,ContactId,Country,Id FROM User ];  
        hotset= new Set<String>();
    
    lst = [SELECT  Account__c, Wins__c, Losses__c, Concerns__c, RFP_Propoals_Sent_This_Week__c, Request_Proposal__c, Estimate_IO_This_Week__c, Owner_Office__c, Name, Id, CreatedDate__c FROM Hot_Sheet__c where CreatedDate__c = THIS_WEEK] ;
                  
               grouped=new map<String,List<Hot_Sheet__c>> ();
        
        for (Integer i = 0; i< lst.size(); i++)
        {
           hotset.add(lst[i].Owner_Office__c); // contains distict accounts
        }
        System.debug('**************'+hotset); 
        lst1 = [SELECT  Name, Account__c,Wins__c,CreatedById,Owner_Office__c,Losses__c  from Hot_Sheet__c where Owner_Office__c IN : hotset  and CreatedDate__c = THIS_WEEK];             
        
        List<Hot_Sheet__c> newLst1=new List<Hot_Sheet__c> ();    
        
       for(String s : hotset)
         {             

 

       for(Hot_Sheet__c  l :lst1){
                 if(l.Owner_Office__c==s)
                     newLst1.add(l);
              }
           grouped.put(s,lst1);                                                      
         }               
  }
public map<String,List<Hot_Sheet__c>> grouped{set;get;}
  public void displayRecords()
  {           
         
        lst = [SELECT  Account__c, Wins__c, Losses__c, Concerns__c, RFP_Propoals_Sent_This_Week__c, Request_Proposal__c, Estimate_IO_This_Week__c, Owner_Office__c, Name, Id, CreatedDate__c  FROM Hot_Sheet__c where CreatedDate__c = THIS_WEEK] ;
                  
               grouped=new map<String,List<Hot_Sheet__c>> ();
        
        for (Integer i = 0; i< lst.size(); i++)
        {
           hotset.add(lst[i].Owner_Office__c); // contains distict accounts        
        }
        
        
        lst1 = [SELECT  Name, Account__c,Wins__c,CreatedById,Owner_Office__c,Losses__c,Concerns__c,RFP_Propoals_Sent_This_Week__c  from Hot_Sheet__c where Owner_Office__c IN : hotset];     
                     List<Hot_Sheet__c> newLst1=new List<Hot_Sheet__c> ();
                
       for(String s : hotset)
         {                    
           for(Hot_Sheet__c  l :lst1){
                       if(l.Owner_Office__c==s)
                       newLst1.add(l);
                         }
                       grouped.put(s,newlst1);
                                                 
         }               
  }   
 
  public void getData() 
  
  {   
      msg = ''; msg1='';  b = true;
  
      hotset= new Set<String>();  
  
      if( HSRobj1.Date__c == null || HSRobj2.Date__c == null)  
  
          {   
              msg1 = 'Please Select Valid From and To Dates';   
              lst1 = lst = null; 
              grouped = null;b=false;
          }   
      
      
     if ( HSRobj1.Date__c != null && HSRobj2.Date__c != null)   
     
         {            
             Datetime dt = HSRobj1.Date__c;       

             Date dates = dt.date();       

             Datetime dt1 = HSRobj2.Date__c;       

             Date dates1 = dt1.date();       
             
             if ( (Date.valueOf(String.valueOf(dates)) > Date.valueOf(String.valueOf(dates1)) ) || ( ( Date.valueOf(String.valueOf(dates)) > Date.valueOf(System.today())) ) || ( ( Date.valueOf(String.valueOf(dates)) > Date.valueOf(System.today()-1)) && ( Date.valueOf(String.valueOf(dates1)) > Date.valueOf(System.today()))) )       
             
             {                 

             msg1 = 'Please Select Valid From and To Dates..............';        
                    
             lst1 = lst =  null;                      
             grouped = null;b = false;
             }      
         
         
            else       
         
             {              
         
             System.debug('I am in else block');       
                         
             Date d1 =  system.today().addDays(+1);                                
             
             
             if ( system.today() ==  Date.valueOf(String.valueOf(dates1))+1 )             
             {          
             
                     System.debug('************100**************');  
                 
                  hotset= new Set<String>();
         
                  lst = [SELECT  Account__c, Wins__c, Losses__c, Concerns__c, RFP_Propoals_Sent_This_Week__c, Request_Proposal__c, Estimate_IO_This_Week__c, Owner_Office__c, Name, Id, CreatedDate__c  FROM Hot_Sheet__c ] ;
                  
                   grouped=new map<String,List<Hot_Sheet__c>> ();
        
                    for (Integer i = 0; i< lst.size(); i++)
                    {
                       hotset.add(lst[i].Owner_Office__c);                     
                    }
                     System.debug('**************'+hotset); 
                 
                     lst1 = [SELECT  Name, Account__c,Wins__c,CreatedById,Owner_Office__c,Losses__c,Concerns__c,RFP_Propoals_Sent_This_Week__c  from Hot_Sheet__c where Owner_Office__c IN : hotset];     
                     List<Hot_Sheet__c> newLst1=new List<Hot_Sheet__c> ();
                
                   for(String s : hotset)
                    {        
                     for(Hot_Sheet__c  l :lst1){
                       if(l.Owner_Office__c==s)
                       newLst1.add(l);
                         }
                       grouped.put(s,newlst1); 
                    }         
             }
             
              } 
          
           }
 } 
    
}

 

-------------------------------------------------------

@isTest
public class TestClassOfHSRData
{
public static testMethod void main()
{
map<String,List<Hot_Sheet__c>> m = new map<String,List<Hot_Sheet__c>> ();

Set<String> hotset = new Set<String>();

List<Hot_Sheet__c> hst = new List<Hot_Sheet__c>(); List<Hot_Sheet__c> newLst1=new List<Hot_Sheet__c> ();

List<Hot_Sheet__c> ls = [select Name from Hot_Sheet__c ];

for (Integer i = 0; i< lst.size(); i++)
{
hotset.add(lst[i].Owner_Office__c); // contains distict accounts
}

for(Hot_Sheet__c h : ls)
{
hst.add(h);
}


Hot_Sheet__c hsr = new Hot_Sheet__c();

ApexPages.StandardController hsrController= new ApexPages.standardController(hsr);

HSRData h = new HSRData(hsrController);

h.getHSRObj1();

Hot_Sheet__c h1 = h.getHSRObj1();

h.getHSRObj2();

h.displayRecords();


h.getData() ;
}
}

 

Covering only 59% can any help me on this. 

  • August 01, 2013
  • Like
  • 0

global with sharing class Populate_Corp_List_Assignments_Batch implements Database.Batchable<sObject>{

   global String Query;
   
    public List<Corporate_Account_List_Assignment__c> calist { set; get; }
 
    
    //given a AccountId and List<AccountTeamMember >, it returns the record having AccountId=AccoundId
    public List<AccountTeamMember> findAccountTeamMember(Id accountId, Map<Id,List<AccountTeamMember>> acc_tmListMap, String teamMemberRole){
        if(acc_tmListMap== null || acc_tmListMap.size() == 0 || accountId==null ){
            return null;
       }
       
       integer count = 0;
       List<AccountTeamMember> atmList = acc_tmListMap.get(accountId);
       List<AccountTeamMember> atmRetList = new List<AccountTeamMember>();

       if(atmList  != null){
        for(AccountTeamMember am: atmList){
            if(am.TeamMemberRole == teamMemberRole){
                atmRetList.add(am);
                count++;
            }
        }
        }
        if(count > 0){
            return atmRetList;
        }else{
        return null;
        }
    }
     public Account findAccount(Id account_name,List<Account> accList ){
        if(accList == null || accList.size() == 0 || account_name==null ){
            return null;
        }
        for(Account am: accList){
            if(am.Id == account_name){
                return am;
            }
        }
        return null;
    }
    

    global Populate_Corp_List_Assignments_Batch(String q){
       Query=q;
    }

    global Database.QueryLocator start(Database.BatchableContext BC){    
     
        return Database.getQueryLocator(query);
    }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
   
  
     //calist = [SELECT Account_Name__c,Corporate_Partnership_Director_1__c,Corporate_Partnership_Director_2__c,Corporate_Partnership_Director_3__c,Corporate_Partnership_Director_4__c,Corporate_Partnership_Director_5__c,Marketing_Solutions_1__c, Marketing_Solutions_2__c, Marketing_Solutions_3__c, Media_Services_1__c, Media_Services_2__c, Media_Services_3__c, Digital_Manager_1__c,Digital_Manager_2__c,Digital_Manager_3__c,Digital_Manager_4__c,Digital_Manager_5__c, Id,Name,Ultimate_Parent_Name__c FROM Corporate_Account_List_Assignment__c];     
     calist = [SELECT Account_Name__c,Corporate_Partnership_Director_1__c,Corporate_Partnership_Director_2__c,Corporate_Partnership_Director_3__c,Corporate_Partnership_Director_4__c,Corporate_Partnership_Director_5__c,Marketing_Solutions_1__c, Marketing_Solutions_2__c, Marketing_Solutions_3__c, Media_Services_1__c, Media_Services_2__c, Media_Services_3__c,Digital_Manager_1__c,Digital_Manager_2__c,Digital_Manager_3__c,Digital_Manager_4__c,Digital_Manager_5__c, Id,Name,Ultimate_Parent_Name__c FROM Corporate_Account_List_Assignment__c];     
         //prepare a map of ids and account_name__c
         Map<Id,Id> ca_acc_map = new Map<Id,Id>();
        
        for(Corporate_Account_List_Assignment__c ca : calist){
            
            ca_acc_map.put(ca.Id,ca.Account_Name__c);
            
         }
         
         
          Map<Id,Account> ac2 = new Map<Id,Account>([SELECT Name,ParentId,Id FROM Account where Id in :ca_acc_map.values()]);
           List<AccountTeamMember> atmcpd2 =[ SELECT Id,TeamMemberRole,UserId, IsDeleted,AccountId FROM AccountTeamMember WHERE AccountId in :ac2.keyset()  AND Isdeleted = FALSE  ];
      
      Map<Id,List<AccountTeamMember>> acc_tmListMap = new Map<Id,List<AccountTeamMember>>();
           for(AccountTeamMember atm: atmcpd2){
               List<AccountTeamMember> atmlist;
                if(acc_tmListMap.get(atm.AccountId) == null ){
                    atmlist = new List<AccountTeamMember>();
                   
                }else{
                     atmlist = acc_tmListMap.get(atm.AccountId);
                    
                
                }
                
                 atmList.add(atm);
                    acc_tmListMap.put(atm.AccountId,atmList);
           
           }
          
     for (Corporate_Account_List_Assignment__c ca : calist)
     {
     ca.Corporate_Partnership_Director_1__c = null;
     ca.Corporate_Partnership_Director_2__c = null;
     ca.Corporate_Partnership_Director_3__c = null;
     ca.Corporate_Partnership_Director_4__c = null; 
     ca.Corporate_Partnership_Director_5__c = null;
     
     ca.Digital_Manager_1__c = null;
     ca.Digital_Manager_2__c = null;
     ca.Digital_Manager_3__c = null; 
     ca.Digital_Manager_4__c = null;
     ca.Digital_Manager_5__c = null;
     
     ca.Marketing_Solutions_1__c = null;
     ca.Marketing_Solutions_2__c = null;
     ca.Marketing_Solutions_3__c = null;
     
     ca.Media_Services_1__c = null;
     ca.Media_Services_2__c = null; 
     ca.Media_Services_3__c = null;
      System.debug('******ID********'+ca.Id);
     
      
      //find atmcpd
      Account accX = ac2.get(ca.Account_Name__c);
      List<AccountTeamMember> atmcpd = findAccountTeamMember(accX.Id,acc_tmListMap,'Corporate Partnership Director' );
     List<AccountTeamMember> atmMS = findAccountTeamMember(accX.Id,acc_tmListMap,'IMS');
      List<AccountTeamMember> atmMDS = findAccountTeamMember(accX.Id,acc_tmListMap,'Media Services');
       List<AccountTeamMember> atmDM = findAccountTeamMember(accX.Id,acc_tmListMap,'Digital Manager');
         
      
        if(atmcpd!= null && atmcpd.size() > 0 )
        {       
         if(atmcpd.size() > 0)
         ca.Corporate_Partnership_Director_1__c = atmcpd.get(0).UserId;
         
          if(atmcpd.size()>1)
           ca.Corporate_Partnership_Director_2__c = atmcpd.get(1).UserId;
         
           if(atmcpd.size()>2)
           ca.Corporate_Partnership_Director_3__c = atmcpd.get(2).UserId;         
           
           if(atmcpd.size()>3)
           ca.Corporate_Partnership_Director_4__c = atmcpd.get(3).UserId;
           
          if(atmcpd.size()>4)
           ca.Corporate_Partnership_Director_5__c = atmcpd.get(4).UserId;
        }
        
        if(atmms != null && atmms.size() > 0)
        {
          if(atmms.size() > 0)
          ca.Marketing_Solutions_1__c  = atmms.get(0).UserId;
          
          if(atmms.size() > 1)
          ca.Marketing_Solutions_2__c = atmms.get(1).UserId;
          
          if(atmms.size() > 2)
          ca.Marketing_Solutions_3__c = atmms.get(2).UserId;

        }
      
      
        if(atmmds != null && atmmds.size() > 0)
        {
          if(atmmds.size() > 0)
          ca.Media_Services_1__c = atmmds.get(0).UserId;
          
          if(atmmds.size() > 1)
          ca.Media_Services_2__c = atmmds.get(1).UserId;
          
          if(atmmds.size() > 2) 
          ca.Media_Services_3__c = atmmds.get(2).UserId;
          
        }
        if(atmdm != null && atmdm.size() > 0)
        {
         if(atmdm.size() > 0)
         ca.Digital_Manager_1__c = atmdm.get(0).UserId;
         
         if(atmdm.size() > 1)
          ca.Digital_Manager_2__c = atmdm.get(1).UserId;
          
         if(atmdm.size() > 2)
          ca.Digital_Manager_3__c  = atmdm.get(2).UserId;
          
         if(atmdm.size() > 3)
          ca.Digital_Manager_4__c  = atmdm.get(3).UserId;
          
          if(atmdm.size() > 4)
          ca.Digital_Manager_5__c  = atmdm.get(4).UserId;
        }
      }               
      update calist;

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

Please help me on this

global class PopulateCorporateFields implements Schedulable
{

    public List<Corporate_Account_List_Assignment__c> calist { set; get; }
 
    
    //given a AccountId and List<AccountTeamMember >, it returns the record having AccountId=AccoundId
    public List<AccountTeamMember> findAccountTeamMember(Id accountId, Map<Id,List<AccountTeamMember>> acc_tmListMap, String teamMemberRole){
        if(acc_tmListMap== null || acc_tmListMap.size() == 0 || accountId==null ){
            return null;
       }
       
       integer count = 0;
       List<AccountTeamMember> atmList = acc_tmListMap.get(accountId);
       List<AccountTeamMember> atmRetList = new List<AccountTeamMember>();

       if(atmList  != null){
        for(AccountTeamMember am: atmList){
            if(am.TeamMemberRole == teamMemberRole){
                atmRetList.add(am);
                count++;
            }
        }
        }
        if(count > 0){
            return atmRetList;
        }else{
        return null;
        }
    }
    
    
     //given a Account_Name__c from Corporate_Account_List_Assignment__c object, find the corresponding Account record
     public Account findAccount(Id account_name,List<Account> accList ){
        if(accList == null || accList.size() == 0 || account_name==null ){
            return null;
        }
        for(Account am: accList){
            if(am.Id == account_name){
                return am;
            }
        }
        return null;
    }
    
    
   global void execute(SchedulableContext ctx) 
    {
     calist = [SELECT Account_Name__c,Corporate_Partnership_Director_1__c,Corporate_Partnership_Director_2__c,Corporate_Partnership_Director_3__c,Corporate_Partnership_Director_4__c,Corporate_Partnership_Director_5__c,Marketing_Solutions_1__c, Marketing_Solutions_2__c, Marketing_Solutions_3__c, Media_Services_1__c, Media_Services_2__c, Media_Services_3__c,Digital_Manager_1__c,Digital_Manager_2__c,Digital_Manager_3__c,Digital_Manager_4__c,Digital_Manager_5__c, Id,Name,Ultimate_Parent_Name__c FROM Corporate_Account_List_Assignment__c];     
         //prepare a map of ids and account_name__c
         Map<Id,Id> ca_acc_map = new Map<Id,Id>();
        
        for(Corporate_Account_List_Assignment__c ca : calist){
            
            ca_acc_map.put(ca.Id,ca.Account_Name__c);
            
         }
         
         
          Map<Id,Account> ac2 = new Map<Id,Account>([SELECT Name,ParentId,Id FROM Account where Id in :ca_acc_map.values()]);
           List<AccountTeamMember> atmcpd2 =[ SELECT Id,TeamMemberRole,UserId, IsDeleted,AccountId FROM AccountTeamMember WHERE AccountId in :ac2.keyset()  AND Isdeleted = FALSE  ];
      
      Map<Id,List<AccountTeamMember>> acc_tmListMap = new Map<Id,List<AccountTeamMember>>();
           for(AccountTeamMember atm: atmcpd2){
               List<AccountTeamMember> atmlist;
                if(acc_tmListMap.get(atm.AccountId) == null ){
                    atmlist = new List<AccountTeamMember>();
                   
                }else{
                     atmlist = acc_tmListMap.get(atm.AccountId);
                    
                
                }
                
                 atmList.add(atm);
                    acc_tmListMap.put(atm.AccountId,atmList);
           
           }
          
     for (Corporate_Account_List_Assignment__c ca : calist)
     {
     ca.Corporate_Partnership_Director_1__c = null;
     ca.Corporate_Partnership_Director_2__c = null;
     ca.Corporate_Partnership_Director_3__c = null;
     ca.Corporate_Partnership_Director_4__c = null; 
     ca.Corporate_Partnership_Director_5__c = null;
     
     ca.Digital_Manager_1__c = null;
     ca.Digital_Manager_2__c = null;
     ca.Digital_Manager_3__c = null; 
     ca.Digital_Manager_4__c = null;
     ca.Digital_Manager_5__c = null;
     
     ca.Marketing_Solutions_1__c = null;
     ca.Marketing_Solutions_2__c = null;
     ca.Marketing_Solutions_3__c = null;
     
     ca.Media_Services_1__c = null;
     ca.Media_Services_2__c = null; 
     ca.Media_Services_3__c = null;
      System.debug('******ID********'+ca.Id);
     
      
      //find atmcpd
      Account accX = ac2.get(ca.Account_Name__c);
      List<AccountTeamMember> atmcpd = findAccountTeamMember(accX.Id,acc_tmListMap,'Corporate Partnership Director' );
     List<AccountTeamMember> atmMS = findAccountTeamMember(accX.Id,acc_tmListMap,'IMS');
      List<AccountTeamMember> atmMDS = findAccountTeamMember(accX.Id,acc_tmListMap,'Media Services');
       List<AccountTeamMember> atmDM = findAccountTeamMember(accX.Id,acc_tmListMap,'Digital Manager');
         
      
        if(atmcpd!= null && atmcpd.size() > 0 )
        {       
         if(atmcpd.size() > 0)
         ca.Corporate_Partnership_Director_1__c = atmcpd.get(0).UserId;
         
          if(atmcpd.size()>1)
           ca.Corporate_Partnership_Director_2__c = atmcpd.get(1).UserId;
         
           if(atmcpd.size()>2)
           ca.Corporate_Partnership_Director_3__c = atmcpd.get(2).UserId;         
           
           if(atmcpd.size()>3)
           ca.Corporate_Partnership_Director_4__c = atmcpd.get(3).UserId;
           
          if(atmcpd.size()>4)
           ca.Corporate_Partnership_Director_5__c = atmcpd.get(4).UserId;
        }
        
        if(atmms != null && atmms.size() > 0)
        {
          if(atmms.size() > 0)
          ca.Marketing_Solutions_1__c  = atmms.get(0).UserId;
          
          if(atmms.size() > 1)
          ca.Marketing_Solutions_2__c = atmms.get(1).UserId;
          
          if(atmms.size() > 2)
          ca.Marketing_Solutions_3__c = atmms.get(2).UserId;

        }
      
      
        if(atmmds != null && atmmds.size() > 0)
        {
          if(atmmds.size() > 0)
          ca.Media_Services_1__c = atmmds.get(0).UserId;
          
          if(atmmds.size() > 1)
          ca.Media_Services_2__c = atmmds.get(1).UserId;
          
          if(atmmds.size() > 2) 
          ca.Media_Services_3__c = atmmds.get(2).UserId;
          
        }
        if(atmdm != null && atmdm.size() > 0)
        {
         if(atmdm.size() > 0)
         ca.Digital_Manager_1__c = atmdm.get(0).UserId;
         
         if(atmdm.size() > 1)
          ca.Digital_Manager_2__c = atmdm.get(1).UserId;
          
         if(atmdm.size() > 2)
          ca.Digital_Manager_3__c  = atmdm.get(2).UserId;
          
         if(atmdm.size() > 3)
          ca.Digital_Manager_4__c  = atmdm.get(3).UserId;
          
          if(atmdm.size() > 4)
          ca.Digital_Manager_5__c  = atmdm.get(4).UserId;
        }
      }               
      update calist;
    }

}

public class PopulateCorporateFields {

    public List<Corporate_Account_List_Assignment__c> calist { set; get; }
 
    public PopulateCorporateFields(ApexPages.StandardController controller) {

    }
    
    public void updateFields()
    {
     calist = [SELECT Account_Name__c,Corporate_Partnership_Director_1__c,Corporate_Partnership_Director_2__c,Corporate_Partnership_Director_3__c,Corporate_Partnership_Director_4__c,Corporate_Partnership_Director_5__c,Marketing_Solutions_1__c, Marketing_Solutions_2__c, Marketing_Solutions_3__c, Media_Services_1__c, Media_Services_2__c, Media_Services_3__c,Digital_Manager_1__c,Digital_Manager_2__c,Digital_Manager_3__c,Digital_Manager_4__c,Digital_Manager_5__c, Id,Name,Ultimate_Parent_Name__c FROM Corporate_Account_List_Assignment__c];     
         
     for (Corporate_Account_List_Assignment__c ca : calist)
     {
     ca.Corporate_Partnership_Director_1__c = null;
     ca.Corporate_Partnership_Director_2__c = null;
     ca.Corporate_Partnership_Director_3__c = null;
     ca.Corporate_Partnership_Director_4__c = null; 
     ca.Corporate_Partnership_Director_5__c = null;
     
     ca.Digital_Manager_1__c = null;
     ca.Digital_Manager_2__c = null;
     ca.Digital_Manager_3__c = null; 
     ca.Digital_Manager_4__c = null;
     ca.Digital_Manager_5__c = null;
     
     ca.Marketing_Solutions_1__c = null;
     ca.Marketing_Solutions_2__c = null;
     ca.Marketing_Solutions_3__c = null;
     
     ca.Media_Services_1__c = null;
     ca.Media_Services_2__c = null; 
     ca.Media_Services_3__c = null;
      System.debug('******ID********'+ca.Id);
      Account ac = [SELECT Name,ParentId,Id FROM Account where Id =: ca.Account_Name__c];
      
      List<AccountTeamMember> atmcpd =[ SELECT Id,TeamMemberRole,UserId, IsDeleted FROM AccountTeamMember WHERE AccountId =: ac.Id AND TeamMemberRole = 'Corporate Partnership Director'  ];
      
      List<AccountTeamMember> atmMS =[ SELECT Id,TeamMemberRole,UserId, IsDeleted FROM AccountTeamMember WHERE AccountId =: ac.Id AND TeamMemberRole = 'IMS' AND Isdeleted = FALSE  ];       
      
      List<AccountTeamMember> atmMDS =[ SELECT Id,TeamMemberRole,UserId, IsDeleted FROM AccountTeamMember WHERE AccountId =: ac.Id AND TeamMemberRole = 'Media Services' AND Isdeleted = FALSE  ];
      
     List<AccountTeamMember> atmDM =[ SELECT Id,TeamMemberRole,UserId, IsDeleted FROM AccountTeamMember WHERE AccountId =: ac.Id AND TeamMemberRole = 'Digital Manager' AND Isdeleted = FALSE  ];
      
        if(atmcpd!= null || atmcpd.size() > 0 )
        {
        // User u = [select Id,Name from user where Id=: atm.get(0).UserId];
        //System.debug('******Size*******'+atmcpd.size()+'**********'+atmcpd.get(0).UserId);
         if(atmcpd.size() > 0)
         ca.Corporate_Partnership_Director_1__c = atmcpd.get(0).UserId;
         
          if(atmcpd.size()>1)
           ca.Corporate_Partnership_Director_2__c = atmcpd.get(1).UserId;
         
           if(atmcpd.size()>2)
           ca.Corporate_Partnership_Director_3__c = atmcpd.get(2).UserId;         
           
           if(atmcpd.size()>3)
           ca.Corporate_Partnership_Director_4__c = atmcpd.get(3).UserId;
           
          if(atmcpd.size()>4)
           ca.Corporate_Partnership_Director_5__c = atmcpd.get(4).UserId;
        }
        
        if(atmms != null || atmms.size() > 0)
        {
          if(atmms.size() > 0)
          ca.Marketing_Solutions_1__c  = atmms.get(0).UserId;
          
          if(atmms.size() > 1)
          ca.Marketing_Solutions_2__c = atmms.get(1).UserId;
          
          if(atmms.size() > 2)
          ca.Marketing_Solutions_3__c = atmms.get(2).UserId;

        }
      
      
        if(atmmds != null || atmmds.size() > 0)
        {
          if(atmmds.size() > 0)
          ca.Media_Services_1__c = atmmds.get(0).UserId;
          
          if(atmmds.size() > 1)
          ca.Media_Services_2__c = atmmds.get(1).UserId;
          
          if(atmmds.size() > 2) 
          ca.Media_Services_3__c = atmmds.get(2).UserId;
          
        }
        if(atmdm != null || atmdm.size() > 0)
        {
         if(atmdm.size() > 0)
         ca.Digital_Manager_1__c = atmdm.get(0).UserId;
         
         if(atmdm.size() > 1)
          ca.Digital_Manager_2__c = atmdm.get(1).UserId;
          
         if(atmdm.size() > 2)
          ca.Digital_Manager_3__c  = atmdm.get(2).UserId;
          
         if(atmdm.size() > 3)
          ca.Digital_Manager_4__c  = atmdm.get(3).UserId;
          
          if(atmdm.size() > 4)
          ca.Digital_Manager_5__c  = atmdm.get(4).UserId;
        }
      }               
      update calist;
    }

}

Getting too many soql queries error getting. Pleas help me on this how to optimize it.

public class PopulateCorporateFields {

    public List<Corporate_Account_List_Assignment__c> calist { set; get; }
 
    public PopulateCorporateFields(ApexPages.StandardController controller) {

    }
    
    public void updateFields()
    {
     calist = [SELECT Account_Name__c,Corporate_Partnership_Director_1__c,Corporate_Partnership_Director_2__c,Corporate_Partnership_Director_3__c,Corporate_Partnership_Director_4__c,Corporate_Partnership_Director_5__c,Marketing_Solutions_1__c, Marketing_Solutions_2__c, Marketing_Solutions_3__c, Media_Services_1__c, Media_Services_2__c, Media_Services_3__c,Digital_Manager_1__c,Digital_Manager_2__c,Digital_Manager_3__c,Digital_Manager_4__c,Digital_Manager_5__c, Id,Name,Ultimate_Parent_Name__c FROM Corporate_Account_List_Assignment__c];     
         
     for (Corporate_Account_List_Assignment__c ca : calist)
     {
     ca.Corporate_Partnership_Director_1__c = null;
     ca.Corporate_Partnership_Director_2__c = null;
     ca.Corporate_Partnership_Director_3__c = null;
     ca.Corporate_Partnership_Director_4__c = null; 
     ca.Corporate_Partnership_Director_5__c = null;
     
     ca.Digital_Manager_1__c = null;
     ca.Digital_Manager_2__c = null;
     ca.Digital_Manager_3__c = null; 
     ca.Digital_Manager_4__c = null;
     ca.Digital_Manager_5__c = null;
     
     ca.Marketing_Solutions_1__c = null;
     ca.Marketing_Solutions_2__c = null;
     ca.Marketing_Solutions_3__c = null;
     
     ca.Media_Services_1__c = null;
     ca.Media_Services_2__c = null; 
     ca.Media_Services_3__c = null;
      System.debug('******ID********'+ca.Id);
      Account ac = [SELECT Name,ParentId,Id FROM Account where Id =: ca.Account_Name__c];
      
      List<AccountTeamMember> atmcpd =[ SELECT Id,TeamMemberRole,UserId, IsDeleted FROM AccountTeamMember WHERE AccountId =: ac.Id AND TeamMemberRole = 'Corporate Partnership Director'  ];
      
      List<AccountTeamMember> atmMS =[ SELECT Id,TeamMemberRole,UserId, IsDeleted FROM AccountTeamMember WHERE AccountId =: ac.Id AND TeamMemberRole = 'IMS' AND Isdeleted = FALSE  ];       
      
      List<AccountTeamMember> atmMDS =[ SELECT Id,TeamMemberRole,UserId, IsDeleted FROM AccountTeamMember WHERE AccountId =: ac.Id AND TeamMemberRole = 'Media Services' AND Isdeleted = FALSE  ];
      
     List<AccountTeamMember> atmDM =[ SELECT Id,TeamMemberRole,UserId, IsDeleted FROM AccountTeamMember WHERE AccountId =: ac.Id AND TeamMemberRole = 'Digital Manager' AND Isdeleted = FALSE  ];
      
        if(atmcpd!= null || atmcpd.size() > 0 )
        {
        // User u = [select Id,Name from user where Id=: atm.get(0).UserId];
        //System.debug('******Size*******'+atmcpd.size()+'**********'+atmcpd.get(0).UserId);
         if(atmcpd.size() > 0)
         ca.Corporate_Partnership_Director_1__c = atmcpd.get(0).UserId;
         
          if(atmcpd.size()>1)
           ca.Corporate_Partnership_Director_2__c = atmcpd.get(1).UserId;
         
           if(atmcpd.size()>2)
           ca.Corporate_Partnership_Director_3__c = atmcpd.get(2).UserId;         
           
           if(atmcpd.size()>3)
           ca.Corporate_Partnership_Director_4__c = atmcpd.get(3).UserId;
           
          if(atmcpd.size()>4)
           ca.Corporate_Partnership_Director_5__c = atmcpd.get(4).UserId;
        }
        
        if(atmms != null || atmms.size() > 0)
        {
          if(atmms.size() > 0)
          ca.Marketing_Solutions_1__c  = atmms.get(0).UserId;
          
          if(atmms.size() > 1)
          ca.Marketing_Solutions_2__c = atmms.get(1).UserId;
          
          if(atmms.size() > 2)
          ca.Marketing_Solutions_3__c = atmms.get(2).UserId;

        }
      
      
        if(atmmds != null || atmmds.size() > 0)
        {
          if(atmmds.size() > 0)
          ca.Media_Services_1__c = atmmds.get(0).UserId;
          
          if(atmmds.size() > 1)
          ca.Media_Services_2__c = atmmds.get(1).UserId;
          
          if(atmmds.size() > 2) 
          ca.Media_Services_3__c = atmmds.get(2).UserId;
          
        }
        if(atmdm != null || atmdm.size() > 0)
        {
         if(atmdm.size() > 0)
         ca.Digital_Manager_1__c = atmdm.get(0).UserId;
         
         if(atmdm.size() > 1)
          ca.Digital_Manager_2__c = atmdm.get(1).UserId;
          
         if(atmdm.size() > 2)
          ca.Digital_Manager_3__c  = atmdm.get(2).UserId;
          
         if(atmdm.size() > 3)
          ca.Digital_Manager_4__c  = atmdm.get(3).UserId;
          
          if(atmdm.size() > 4)
          ca.Digital_Manager_5__c  = atmdm.get(4).UserId;
        }
      }               
      update calist;
    }

}
Getting Too many SOQL queries. Please help me how to optimize this code.

Hi,

 

 According to requirement we overrided the view page. Now in that page want to display related list to display the task associated with that record. How to display those related list with task pls let me know how to do it. thanks

Hi,

 

 If task status is "completed" want to check the corresponding object record type value.  Eg: "Employee" have to check the field value like Emp type is "Contract" or "Permanant" 

 

How it is possible in work flow? can any one help me on this

HI,

 

 I would like to change the entire home page color to gray. Is it possible how can we acheive this fucntionality?

 

 

Criteria: "Contact Record Type  equals 'Expat' and Status equals 'Submitted' " only these records want to share to one user. I created 3 records those satisfied the criteria but still these contact records are not displaying to the user.  Created this sharing rule if satisfied sharing these records to one role i.e "CMP" role. when the users belongs to that "CMP" role logged in they are not able to see the records.

 

is there any other things will override sharing settings or any other reason for that not displaying records to user.

 

Please give the ideas on this.

Hi Team,

 
  Please help how to schedule a apex class to run for every 2 weeks.
 
 

There are seven fields for Salesforce’s cron syntax, unlike *nix’s 5 fields.

  • Seconds [0-59]
  • Minutes [0-59]
  • Hours [0-23]
  • Day of month [1-31]
  • Month [1-12 or JAN-DEC]
  • Day of week [1-7 or SUN-SAT]
  • Year [1970-2099]

I seen above two but am not getting how to schedule it for 2 weeks please help me on that. thanks in advance

 

 

 

how can we show more than 1000 records in visualforce page?

  • October 30, 2013
  • Like
  • 0

trigger EmailSend on Task(after insert, after update) {

try {
 Profile_allowed_to_runSendEmailToGroup__c getallprofiles=Profile_allowed_to_runSendEmailToGroup__c.getinstance('Profile Set 1');
        
        set<string>profileset=new set<string>();
        if(getallprofiles.get('Allowed_Profile__c')!=null)
        {
            string getprofilename=string.valueof(getallprofiles.get('Allowed_Profile__c'));
            list<string>profilelst=getprofilename.split(';');
            profileset.addAll(profilelst);
        }
        string profilename=[SELECT Id, Name FROM Profile WHERE Id=:userinfo.getProfileId() LIMIT 1].name;
        list < string > groupname = new list < string > ();
        List < String > mailAddrs = new List < String > ();
        String fullFileURL = URL.getSalesforceBaseUrl().toExternalForm();
        if(profileset.contains(profilename)==true)
        {
            List < id > Accoundid = new list < id > ();
            for (task t1: trigger.new) {
                if (t1.whatid != null && t1.what.type == 'Account') {
                    Accoundid.add(t1.whatid);
                }
                if (t1.Status == 'Completed') {
                    if (t1.Activity_Type__c == 'DPR')
                        groupname.add('SET DPR');
                    else if (t1.Activity_Type__c == 'GME')
                        groupname.add('SET GME');
                    else if (t1.Activity_Type__c == 'GM Changes')
                        groupname.add('SET GM CHANGES');
                    else if (t1.Activity_Type__c == 'Ownership Changes')
                        groupname.add('SET OWNERSHIP CHANGES');
                    else
                        groupname.add('SET ALL OTHERS');
                }
            }
            map < id, account > AccountMap = new map < id, account > ([select id, name from account where id In: Accoundid]);
            list < id > grpmemberid = new list < id > ();
            for (groupmember gm1: [select userOrGroupId from groupMember where group.name in : groupname]) {
                grpmemberid.add(gm1.userOrGroupId);
            }
            for (user u1: [select id, email from user where id IN: grpmemberid]) {
                mailAddrs.add(u1.email);
            }
            if (mailAddrs.size() > 0) {
                List < Messaging.SingleEmailMessage > allemail = new List < Messaging.SingleEmailMessage > ();
                for (task t1: trigger.new) {
                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                    mail.setToAddresses(mailAddrs);
                    string accountName;
                    if (t1.whatid != null && t1.what.type == 'Account') {
                        if (AccountMap.containskey(t1.whatid))
                            accountName = AccountMap.get(t1.whatid).name;
                        else
                            accountName = '';
                    }
                    mail.setSubject(t1.Activity_Type__c + ' : ' + accountName + ' Task Information');
                    mail.setPlainTextBody('A new Contact Report has been completed ' + '\n' + fullFileURL + '/' + t1.Id);
                    allemail.add(mail);
                }
                if (allemail.size() > 0) {
                    Messaging.sendEmail(allemail, false);
                }
            }
        }
  } catch (exception e) {
        system.debug('###' + e.getmessage());
    }
}

tThe above code is working fine. In custom setting have 3 records Profile Set 1,Profile Set 2,Profile Set 3 it is working fine for "Profile Set 1"

 

not working for remaining other. whr i have to change in code. pls help me on this.

  • October 18, 2013
  • Like
  • 0

 

trigger Trigger1 on Task (after insert,after update)
{
List<String> mlist = new List<String>();
List<String> mailAddrs = new List<String>();
String fURL = URL.getSalesforceBaseUrl().toExternalForm() ;


for(Task t : Trigger.new)

{
Account act = [select Name from Account where Id =: t.AccountId];
if(t.Status == 'Completed')
{
if( t.Activity_Type__c == 'Resolved')
{

Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET A'];

for (GroupMember gm : g.groupMembers)
{
mlist.add(gm.userOrGroupId);
}

User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr)
{
mailAddrs.add(u.email);

}
}
else if ( t.Activity_Type__c == 'Completed')

{
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET B'];
for (GroupMember gm : g.groupMembers)

{
mlist.add(gm.userOrGroupId);
}

User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr)
{
mailAddrs.add(u.email);
}
}

else if ( t.Activity_Type__c == 'In Progress')

{
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET C'];
for (GroupMember gm : g.groupMembers)

{
mlist.add(gm.userOrGroupId);

}
User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr)
{
mailAddrs.add(u.email);
}
}

else if ( t.Activity_Type__c == 'On Hold')

{
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET D'];
for (GroupMember gm : g.groupMembers)

{
mlist.add(gm.userOrGroupId);

}
User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr)
{
mailAddrs.add(u.email);
}
}

else
{
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SET E'];

for (GroupMember gm : g.groupMembers) {
mlist.add(gm.userOrGroupId); }

User[] usr = [SELECT email FROM user WHERE id IN :mlist];
for(User u : usr) { mailAddrs.add(u.email); }

}

if(mailAddrs != null || mailAddrs.size() > 0)
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setToAddresses(mailAddrs);

mail.setSubject(t.Activity_Type__c+' : '+act.Name+' Task Information');

mail.setPlainTextBody(' Contact Report has been completed '+'\n'+fURL+'/'+t.Id);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}

}
}

 

The above trigger is working fine. Can any one help to avoid Governor limits for this trigger. by using collections can do it. but am not able fix it please help me on this.

  • October 15, 2013
  • Like
  • 0

public class UpdateFieldOnOpportunity implements Schedulable { public List Opp {set; get;} Public List<Insertion__c> Ins { set; get; } public Integer j = 0; public void updateFields() { Opp= [SELECT Id,Name,Account_Name__c, Formula_Video__c, Insertion__c FROM Opportunity WHERE Formula_Video__c > 0 ]; System.debug('*********Opportunities with Formula Video above Zero**********'+ Opp.size()); Ins = [SELECT Account__c,Id,Name,Formula_Video_Flag__c FROM Insertion__c ]; for(Insertion__c i : Ins) { i.Formula_Video_Flag__c = 'FALSE'; } update Ins; for (Insertion__c i : Ins) { System.debug('*******Insertion*********'+i); for(Opportunity o : opp) { if(I.id == o.Insertion__c) I.Formula_Video_Flag__c = 'TRUE'; else I.Formula_Video_Flag__c = 'FALSE'; j++; } System.debug('*******Update*********'); } update Ins; } }

  • October 02, 2013
  • Like
  • 0

public class PopulateCorporateFields {

    public List<Corporate_Account_List_Assignment__c> calist { set; get; }
 
    public PopulateCorporateFields(ApexPages.StandardController controller) {

    }
    
    public void updateFields()
    {
     calist = [SELECT Account_Name__c,Corporate_Partnership_Director_1__c,Corporate_Partnership_Director_2__c,Corporate_Partnership_Director_3__c,Corporate_Partnership_Director_4__c,Corporate_Partnership_Director_5__c,Marketing_Solutions_1__c, Marketing_Solutions_2__c, Marketing_Solutions_3__c, Media_Services_1__c, Media_Services_2__c, Media_Services_3__c,Digital_Manager_1__c,Digital_Manager_2__c,Digital_Manager_3__c,Digital_Manager_4__c,Digital_Manager_5__c, Id,Name,Ultimate_Parent_Name__c FROM Corporate_Account_List_Assignment__c];     
         
     for (Corporate_Account_List_Assignment__c ca : calist)
     {
     ca.Corporate_Partnership_Director_1__c = null;
     ca.Corporate_Partnership_Director_2__c = null;
     ca.Corporate_Partnership_Director_3__c = null;
     ca.Corporate_Partnership_Director_4__c = null; 
     ca.Corporate_Partnership_Director_5__c = null;
     
     ca.Digital_Manager_1__c = null;
     ca.Digital_Manager_2__c = null;
     ca.Digital_Manager_3__c = null; 
     ca.Digital_Manager_4__c = null;
     ca.Digital_Manager_5__c = null;
     
     ca.Marketing_Solutions_1__c = null;
     ca.Marketing_Solutions_2__c = null;
     ca.Marketing_Solutions_3__c = null;
     
     ca.Media_Services_1__c = null;
     ca.Media_Services_2__c = null; 
     ca.Media_Services_3__c = null;
      System.debug('******ID********'+ca.Id);
      Account ac = [SELECT Name,ParentId,Id FROM Account where Id =: ca.Account_Name__c];
      
      List<AccountTeamMember> atmcpd =[ SELECT Id,TeamMemberRole,UserId, IsDeleted FROM AccountTeamMember WHERE AccountId =: ac.Id AND TeamMemberRole = 'Corporate Partnership Director'  ];
      
      List<AccountTeamMember> atmMS =[ SELECT Id,TeamMemberRole,UserId, IsDeleted FROM AccountTeamMember WHERE AccountId =: ac.Id AND TeamMemberRole = 'IMS' AND Isdeleted = FALSE  ];       
      
      List<AccountTeamMember> atmMDS =[ SELECT Id,TeamMemberRole,UserId, IsDeleted FROM AccountTeamMember WHERE AccountId =: ac.Id AND TeamMemberRole = 'Media Services' AND Isdeleted = FALSE  ];
      
     List<AccountTeamMember> atmDM =[ SELECT Id,TeamMemberRole,UserId, IsDeleted FROM AccountTeamMember WHERE AccountId =: ac.Id AND TeamMemberRole = 'Digital Manager' AND Isdeleted = FALSE  ];
      
        if(atmcpd!= null || atmcpd.size() > 0 )
        {
        // User u = [select Id,Name from user where Id=: atm.get(0).UserId];
        //System.debug('******Size*******'+atmcpd.size()+'**********'+atmcpd.get(0).UserId);
         if(atmcpd.size() > 0)
         ca.Corporate_Partnership_Director_1__c = atmcpd.get(0).UserId;
         
          if(atmcpd.size()>1)
           ca.Corporate_Partnership_Director_2__c = atmcpd.get(1).UserId;
         
           if(atmcpd.size()>2)
           ca.Corporate_Partnership_Director_3__c = atmcpd.get(2).UserId;         
           
           if(atmcpd.size()>3)
           ca.Corporate_Partnership_Director_4__c = atmcpd.get(3).UserId;
           
          if(atmcpd.size()>4)
           ca.Corporate_Partnership_Director_5__c = atmcpd.get(4).UserId;
        }
        
        if(atmms != null || atmms.size() > 0)
        {
          if(atmms.size() > 0)
          ca.Marketing_Solutions_1__c  = atmms.get(0).UserId;
          
          if(atmms.size() > 1)
          ca.Marketing_Solutions_2__c = atmms.get(1).UserId;
          
          if(atmms.size() > 2)
          ca.Marketing_Solutions_3__c = atmms.get(2).UserId;

        }
      
      
        if(atmmds != null || atmmds.size() > 0)
        {
          if(atmmds.size() > 0)
          ca.Media_Services_1__c = atmmds.get(0).UserId;
          
          if(atmmds.size() > 1)
          ca.Media_Services_2__c = atmmds.get(1).UserId;
          
          if(atmmds.size() > 2) 
          ca.Media_Services_3__c = atmmds.get(2).UserId;
          
        }
        if(atmdm != null || atmdm.size() > 0)
        {
         if(atmdm.size() > 0)
         ca.Digital_Manager_1__c = atmdm.get(0).UserId;
         
         if(atmdm.size() > 1)
          ca.Digital_Manager_2__c = atmdm.get(1).UserId;
          
         if(atmdm.size() > 2)
          ca.Digital_Manager_3__c  = atmdm.get(2).UserId;
          
         if(atmdm.size() > 3)
          ca.Digital_Manager_4__c  = atmdm.get(3).UserId;
          
          if(atmdm.size() > 4)
          ca.Digital_Manager_5__c  = atmdm.get(4).UserId;
        }
      }               
      update calist;
    }

}

Getting too many soql queries error getting. Pleas help me on this how to optimize it.

Hi Team,

 
  Please help how to schedule a apex class to run for every 2 weeks.
 
 

There are seven fields for Salesforce’s cron syntax, unlike *nix’s 5 fields.

  • Seconds [0-59]
  • Minutes [0-59]
  • Hours [0-23]
  • Day of month [1-31]
  • Month [1-12 or JAN-DEC]
  • Day of week [1-7 or SUN-SAT]
  • Year [1970-2099]

I seen above two but am not getting how to schedule it for 2 weeks please help me on that. thanks in advance

 

 

 

Pls provide me the steps to do this

The req is i have pick list name is "Rank" have values like 100,200,300 and i want to keep these values as unique. And i have one more field "Role". If Role is CPD and rank is already used by any other record have to display error message for that i written trigger. That is working fine for insert event. Not working for update can any one help me on this.

 

The following is the trigger: 

 

trigger CheckRankValues on Account_Team_Commission__c (before insert)
{
  public List<Account_Team_Commission__c> c;
 for(Account_Team_Commission__c ct :Trigger.new)
 {
  if(Trigger.isBefore && Trigger.isInsert)
  {
      c = [select Id,Name,Rank__c,Team_member_role__c  from Account_Team_Commission__c];
      
      if(c != null && c.size() > 0)
      {
        for ( Integer i = 0 ; i< c.size() ; i++)
        {
          if ( (ct.Rank__c == c.get(i).Rank__c) && (ct.Team_member_role__c == 'Corporate Partnership Directors'))
           ct.addError('Rank  Must be Unique value : '+ct.Rank__c);
        }
      }
  }
  if(Trigger.isBefore && Trigger.isUpdate)
  {
     c = [select Id,Name,Rank__c,Team_member_role__c  from Account_Team_Commission__c];
      
      if(c != null && c.size() > 0)
      {
        for ( Integer i = 0 ; i< c.size() ; i++) //Account accts = Trigger.oldMap.get(acc.Id);
        {
          Account_Team_Commission__c atc = Trigger.oldMap.get(c.get(i).Id);
          if ( (atc.Rank__c == c.get(i).Rank__c) &&(atc.Team_member_role__c == 'Corporate Partnership Directors'))
           ct.addError('Rank Must be Unique value : '+ct.Rank__c);
        }
      }
  }
 }
}

 

Scenario:

------------

       Name    Role   Rank

Eg: ABC      CPD    1     (Correct)

       DEF      CPD   2     (Correct)

       GHI       CPD  1  (Incorrect ) with same role and rank already used so wont allow this type

For this i written above trigger,working for insert event not working for Update. 

 

I have created one  custom section. In that added two custom links now am able to see those section with links in home as a "System Administrator"

 

Now i want to display that section with two links to only for one user. How to display that particular section only to one user?

 

 

One way is creating one new layout adding this section to that layout and assigning to that profile. But if we do like this , If i created 5 users with same this profile 5 users are able to see. But my requirement is only to display for one user. 

 

Is there any otherway how can i achieve this. Please help me out on this. thanks in advance

Usage of "Veiw State" in the visual force page

How to execute a trigger only one time instead of executing for all records.

Hi All,

 

 I need some help. In my custom object i have one formula field it is displaying user name based on value in the pick list value. Based on the picklist value the user value is displaying in one field for that created formula field. 

 

I created one look up field(User) in my object now i want to populate that field value based on the user name retrived in the formula field so now i want to update this look up field value based on the formula field for this in after insert have to do this update but salesforce does not allows to update the current record in the after insert event. So can any one help how to acheive this functionality.

 

Is there any other way to do this. Please help me on this

 

Thanks in advance.

Hi All,

Can any one explain me about the usage of Salesforce to Salesforce feature & what are the applications advantges etc.

How this feature all the organizations will use.

Please provide some information on this.

Thanks in advance

  • April 26, 2013
  • Like
  • 0