• suresh sanneboina 4
  • NEWBIE
  • 385 Points
  • Member since 2015

  • Chatter
    Feed
  • 13
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 97
    Replies
Hi 
How to assign opportunity record types based on  account record types using apex trigger and not for converting lead just using account and opportunity record types?

Thanks
Dakshendra.R
All,
I was asked to update some code so that instead of always inserting an Opportunity based on the Task insertion criteria, it only inserts an Opportunity if the related Account doesn't already have one. Usually I think this would be solved using Account.Opportunities.Size()==0, but I'm inserting the Opportunity based off a Task creation and finding the Account associated to the Contact using AccountId. And
​ cIdMap.get(tsk.whoId).AccountId.Opportunities.Size()==0
throws an Invalid foreign key relationship: Contact.AccountId error.

Does anyone know how I could solve this?

Here is the full code. The method is on lines 82-118.
public class SalesBlitzProcess {
    //Grab Lst of tasks
    protected final Task[] taskNewList;
    protected final Task[] taskOldList;
    
    public SalesBlitzProcess (Task[] taskOldList, Task[] taskNewList){
        this.taskNewList = taskNewList;
        this.taskOldList = taskOldList;
    }
    
    List<Task> taskList = new List<Task>();
    List<Opportunity> oppList = new List<Opportunity>();
    Task t;
    Opportunity o;
    Contact c;
    Account a;
    
    //Left Message - Create new Tasks if the following Outcomes == 'Left Message' || 'No Answer'
    Set<Contact> cSet = new Set<Contact>();
    public void executeLeftMessage(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 1' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                //Set c.Nurture_Paused__c = True; and c.Send_Day_1_Follow_Up_Email__c = true;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = true;
                    c.Send_Day_1_Follow_Up_Email__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Sales Blitz Call - Day 3';
                t.Status = 'Not Started';
                t.ActivityDate = System.Today().addDays(2);
                taskList.add(t);
                
            } else if (tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 3' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Sales Blitz Call - Day 5';
                t.Status = 'Not Started';
                t.ActivityDate = System.Today().addDays(2);
                taskList.add(t);
                
            } else if (tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 5' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                //c.Send_Day_1_Follow_Up_Email__c = true;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Send_Day_5_Follow_Up_Email__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Sales Blitz Call - Day 8';
                t.Status = 'Not Started';
                t.ActivityDate = System.Today().addDays(3);
                taskList.add(t);
                
            } else if (tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 8' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                //Set c.Nurture_Paused__c = False;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = false;
                    c.Send_Day_1_Follow_Up_Email__c = false;
                    c.Send_Day_5_Follow_Up_Email__c = false;
                    cSet.add(c);
                }
            }
        }
        
        If(!taskList.isEmpty()){
            insert taskList;
        }
        If(!cSet.isEmpty()){
            update new List <Contact>(cSet);
        }
    }
    
    //Continue Process - Create Opportunity if Task has the following outcomes
    Set<Id> ContactIds = new Set<Id>();
    public void executeContinueProcess(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && (tsk.Outcome__c == 'Set First Advisor Briefing'
                || tsk.Outcome__c == 'Set Qualified Meeting'
                || tsk.Outcome__c == 'Set Existing Producer Meeting'
                || tsk.Outcome__c == 'Set Touch Base Meeting'
                || tsk.Outcome__c == 'Proposal Needed'
                || tsk.Outcome__c == 'Verbal Commitment')){
                    String tId = tsk.WhoId;
                    if(String.ValueOf(tsk.WhoId).substring(0,3) == '003'){
                        ContactIds.add(tsk.WhoId);
                    }
                    
                    List<Contact> taskContacts = [Select Id, AccountId, Account.Name, Nurture_Paused__c FROM Contact Where Id in:ContactIds];
                    Map<Id, Contact> cIdMap = new Map<Id, Contact>(taskContacts);
                    //Create Opportunity if Task has the outcome above
                    o = new Opportunity();
                    //system.debug('==========Contact Id ========'+tsk.WhoId);
                    //system.debug('==========Contact record ========'+cIdMap.get(tsk.WhoId));
                    //system.debug('==========account Id ========'+cIdMap.get(tsk.WhoId).AccountId);
                    if(tsk.WhoId != null && cIdMap.get(tsk.WhoId) != null){
                        o.AccountId = cIdMap.get(tsk.WhoId).AccountId;
                    }
                    o.Name = 'New Sales Blitz Opportunity';
                    o.StageName = 'New';
                    o.Opportunity_Potential__c = 0.00;
                    o.CloseDate = Date.today();
                    o.OriginalOpportunitySource__c = 'Sales Blitz';
                    oppList.add(o);
                }
        }
        If(!oppList.isEmpty()){
            insert oppList;
        }
    }
    
    //Not Now - Check Nurture Paused for 3 weeks if Outcome__c == Follow Up Or TBD, then unpause.
    public void executeNotNow(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && (tsk.Outcome__c == 'Follow Up' || tsk.Outcome__c == 'TBD')){
                //Set c.Nurture_Paused__c = True;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Unpause Nurture - 3 Weeks';
                t.Status = 'Not Started';
                t.Outcome__c = 'Unpause Nurture';
                t.ActivityDate = System.Today().addDays(21);
                taskList.add(t);
            }
            //After 3 weeks, unpause nurture
            //Once closed, uncheck checkbox
            else if (tsk.Status =='Completed' && tsk.Subject == 'Unpause Nurture - 3 Weeks' && tsk.Outcome__c == 'Unpause Nurture'){
                //Set c.Nurture_Paused__c = False;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = false;
                    cSet.add(c);
                }
            }
        }
        If(!taskList.isEmpty()){
            insert t;
        }
        if(!cSet.isEmpty()){
            update new List <Contact>(cSet);
        }
    }
    //Hard No - Create reminder task to close in 90 days to unpause nurture
    public void executeHardNo(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && tsk.Outcome__c == 'Not Interested' && tsk.Subject.contains('Sales Blitz')){
                //Set c.Nurture_Paused__c = True;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Unpause Nurture - 3 Months';
                t.Status = 'Not Started';
                t.Outcome__c = 'Unpause Nurture';
                t.ActivityDate = System.Today().addDays(90);
                taskList.add(t);
            }
            //After 3 months, unpause nurture
            //Once closed, uncheck checkbox
            else if (tsk.Status =='Completed' && tsk.Subject == 'Unpause Nurture - 3 Months' && tsk.Outcome__c == 'Unpause Nurture'){
                //Set c.Nurture_Paused__c = False;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = false;
                    cSet.add(c);
                }
            }
        }
        If(!taskList.isEmpty()){
            insert t;
        }
        if(!cSet.isEmpty()){
            update new List <Contact>(cSet);
        }
    }
}

 
Not sure why I 'm getting a null pointer error here in the batch process, any thoughts are appreciated :)

Code
public Database.QueryLocator start(Database.BatchableContext BC)  
{
    String query = 'SELECT Id,  (SELECT ContactId, IsPrimary FROM OpportunityContactRoles ORDER BY IsPrimary DESC) FROM Opportunity WHERE LastModifiedDate = LAST_N_DAYS:365';
    return Database.getQueryLocator(query); 
}

public void execute(Database.BatchableContext BC, List < sObject > s)
{
    List < Opportunity > oppsToUpdate = new List < Opportunity > ();
    for (sObject ssss: s)
    {
        Opportunity o = (Opportunity) ssss;
        List < OpportunityContactRole > opptys = new List < OpportunityContactRole > ();
        opptys = (List < OpportunityContactRole > ) o.getsobjects('OpportunityContactRoles'); //o.getsobjects will return a List<SObject>, in the same line we cast those into List<OpportunityContactRole>

        for (OpportunityContactRole optt: opptys) // HERE IS WHERE THE ERROR IS.  LOOPING THROUGH SUB QUERY LIST
        {
            String contId = '';
            contId = String.ValueOf(optt.ContactId);
            if (!String.IsBlank(contId))
            {
                o.Primary_Contact_Id__c = contId;
                oppsToUpdate.add(o);
                break;
            }
        }
    }

    update oppsToUpdate;

}
In Apex I am trying to count the number of days from first day of the current month excluding Sat and Sun.

            Date firstDayOfMonth = System.today().toStartOfMonth();
             Datetime dt1 = DateTime.newInstance(firstDayOfMonth, Time.newInstance(0, 0, 0, 0));
             String d=dt1.format('EEEE');
            
             if(d != 'Saturday' &&  d != 'Sunday')
              {
                Datetime et1 = DateTime.newInstance(Date.Today(), Time.newInstance(0, 0, 0, 0));
                String e=et1.format('EEEE');
                System.debug('After conversion present day======'+et1);
                 
                Integer noOfDaysFromFirstDyMonth=0; 
                while (dt1<= et1) {
                d=(String)dt1.format('EEEE');
                e=(String)et1.format('EEEE');  
                    if (d!='Saturday' || d!='Sunday')  {  
                    if (e!='Saturday' || e!='Sunday')
                        {
                            noOfDaysFromFirstDyMonth = noOfDaysFromFirstDyMonth + 1;  
                            System.debug('dt1=='+dt1.format('EEE'));
                            System.debug('et1=='+et1.format('EEE'));
                        }
                    }  
                    dt1= dt1.addDays(1);  
                } 
  
When the days are Sat or Sun ,it should not go inside if conditions but its going inside ifs.Where I am wrong please guide me?
 
HI,
i have CSV file in documents, that have to read from BATCH class then create Account..

1. how to read CSV from Documents ?
2. how to return query from start method ?

can any one give me sameple code for this.

Thanks in advance.

 
  • July 08, 2016
  • Like
  • 0
How to get value from one Visual force tab to second Visual force tab???
Retrieving Email template from Json..
Getting an error System.JSONException: Unexpected character ('f' (code 102)):
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Controller////////////////////////////////////////////////////////
public class Calloutcontroller1 {
public List<template1> ConsoleWrapperList3{get;set;}
public List<template1> getperformcallout3(){
ConsoleWrapperList3 = new List<template1>();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
req.setEndpoint('http://webapi.demomail.net/test/bodyTemplate.js'); 
req.setMethod('GET');
res = http.send(req);
if(res.getstatusCode() == 200 && res.getbody() != null){
String replaceIllegal= res.getbody().replaceAll('\n','').replaceAll('\r','').replaceAll('&quote;','').replaceAll('font;','');
ConsoleWrapperList3=(List<template1>)System.JSON.deserialize( res.getbody(),List<template1>.class);
}
return consolewrapperlist3;
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\VF Page\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<apex:page controller="Calloutcontroller1" sidebar="false" docType="html-5.0" >
<apex:form >
<apex:pageBlock id="ThePage">
 <apex:pageBlockSection >
 <apex:pageBlockSectionItem >
 <messaging:htmlEmailBody >
 <html>
 <body>
                <span>Body</span>
                <div>
                    {!performcallout3}
                </div>
                 </body>
                 </html>
                </messaging:htmlEmailBody>
                <!--<apex:outputText value="" style="width:400px ; height:400px"></apex:outputText>-->
            </apex:pageBlockSectionItem>
 </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Wrapper Class//////////////////////////////////////////////

public class template1{
public String Id{get;set;}
public String bodyT{get;set;}
}
 
I'm trying to check if an opportunity has been inactive for a year. If yes, I'll send an email notification.

I'm using process builder to do this. But I'm not sure how to check if Last modified date was before 12 months from today. I'm able to come up with 
this Opportunity.LastModifiedDate < TODAY - DAYS(365)

Let me know what modifications needs to be done
User-added image
I have two custom objects related with lookip. I want to update all Child objects address field according to Parents. I know for that, I have to write a trigger so plz help me.
Hi All,

Please give me idea ..........How to display  morethan 1000 rows in a vf page......

I am getting below error "limit is exceed to display morethan 1000 rows", if i shows morethan 1000 rows...Even i used readonly = true in page component

Adv Thnx
Siv
 
  • January 27, 2016
  • Like
  • 0
Salesforce Expert,
I am new to Salesforce,I have a scenario :

I have a account list that contains few fields like (Name,Biling state,phone and few more) and with that I want a button called Show, whenever i click on show that will give me selected account description and account name. But the output will be in expand/collapse patterm in that list itself.

I wrote wraper class for this using pageblock table but my output is not coming as expected.Can any 1 pls help.

- Ayush
public with sharing class AssertEx 
{
    
    public integer sum()
    {
         integer a =10;
            integer b =20;
         integer c;
         c=a+b;
         system.debug('======'+c);
         //system.assert();
         //system.assertequals();
         //System.assertNotEquals();
         return c;
    }
}
Hi,

when creating a meeting from Contact layout. We are unable to fire trigger. Is there a way to get the info of the meeting and synch to external service when a meeting is created/updated.

 
Hi,

We have created a global web service class and that has a method which accepts parameters
Source Account Id and target account id. The source needs to be merged to target and all the contacts(14000) existing in source should be moved to target. Before moving the contact i need to update contacts and need to merge. We are getting the exception 'Too Many DML Rows
10001'.

I knew that salesforce has a DML limit of 10000 rows in a single transaction. I cannot use asynchronous call since the request to merge the records is called from the External System.

Please help me out if there is any alternative.

 
Does Anyone worked on Salesforce IOT
Hi, m send the some data my website to ssales force using php code but my using web to lead form and the the data/records comes in the Leads, but i want all the data in account, contact and opportunity.

So help me how can i send the data.
trigger Branch on Student_details__c(After update) {
if (Trigger.isAfter) {
for (Student_details__c  a: Trigger.new) {

if(a.Branch__c=='C.S.E')
a.Branch__c= 'Civil';
update a;
}}

}
Hi All,

Hope someone can help me on this.
I have created an custom account lookup because with standard account lookup i am unable to add contact filter.
Now I have to autopopulate account name on the custom account field on quote from the opportunity object or possibliy from Account Object itself. It should autopopulate when i click the new button on quote. 
I tried some trigger but i hope there is some mistakes.Please see below.

trigger updateQuoteAccount on Quote (before insert, before update) {
      List<Quote> OpportunitiesToUpdate = new List<Quote>();
      for(Quote QA : [Select Id, Opportunity.Account.Id From Quote Where Id IN : trigger.newMap.keyset()]) {
            QA.Account_c = QA.Opportunity.Account.Id;
             QuoteToUpdate.add(QA);            
       }   
       if(!QuoteToUpdate.isEmpty())
                update QuoteToUpdate;
 
Hi 
How to assign opportunity record types based on  account record types using apex trigger and not for converting lead just using account and opportunity record types?

Thanks
Dakshendra.R
Hi all

We have a custom object which appears on the account page. The problem however is that this object needs to appear on the opportunity too. Reason being, there is an email alert set up which is triggered off a field that appears on the opportunity page and the object in question needs to be attached to each Opportunity.

Is it possible to have this particular custom object to appear on the Opportunity as well? Can you define master objects once the custom object has been created? 
Hi All

I have a object with the check box as one of the field, when the user enters data into that object and he checks the check box all the existing checkboxes or already checked records need to be unchecked?  How can you achieve this by using out-of-box functionality?
 
My account.amount field value is 1003.34.My code is like account.amount > =1000 , but it throws an error.
Hi All,
Below are Apex Class and Test Class.
Apex Class:
public  class UnvalidatedMum {
      id currentUserid;
      public list<Mum_Information__c> UnvalidatedMumList{get;set;}
    public UnvalidatedMum () {
        currentUserid=UserInfo.getUserId();
        Educator__c edu=[select id from Educator__c where user__c =:currentUserid limit 1];
        UnvalidatedMumList=[SELECT Id, Name, Mobile_No__c,  EduMum__c, 
                            First_Name__c,  Validation_Stage__c, Current_week__c FROM Mum_Information__c
                            where EduMum__c =:edu.id and Validation_Stage__c='Unvalidated' order by CreatedDate desc limit 10000 ];
        
    }
}
Test class:
-----------
@istest
private class UnvalidatedMumExtTest
{
  
    private static testmethod void fetchUnValidatedMum(){
         list<Mum_Information__c> mumList = new list<Mum_Information__c>();
          user u =[select id from user limit 1];
         Educator__c edu = new Educator__c();
        edu.Educator_Phone_No__c='7451245759';
        edu.user__c = u.id;
        insert edu;
       City__c c = new City__c(Name='cityname',Estimated_Target__c=6);
        insert c;
        Message_Table__c  m = new Message_Table__c (Persona__c=1,Week__c=12);
        insert m;
        Hospital__c h = new Hospital__c(name='hospital',Hospital_Type__c='Govt',City_Name__c=c.id);
        insert h;
        Mum_Information__c info = new Mum_Information__c(Mum_Hospital__c=h.id,Whatsapp_Presence__c='yes',Validation_Stage__c='validated',Pregnancy_Type__c='First',Lifestage_Months__c='3rd trimester',Family_Type__c='Joint',Facebook_Presence__c='no',First_Name__c = 'Test',edumum__c=edu.id,edd__c=date.today(),MObile_no__c='7094346807', address__c='hyd',pincode__c=121312,Landline_Number__c=0402303433,otp__c=123,Preferred_language__c='English',Do_you_own_this_phone__c='yes',ConsentID__c = decimal.valueof('12345678912')); 
        insert info;
 UnvalidatedMum un = new UnvalidatedMum();
  }
}

I am getting only 50% code coverage. I am not able to cover the Bold lines in apex class. Anyone please help on this.

Thanks in Advance.


 
I keep getting the feedback that my data is not grouped by status, but cannot figure out how to group it by that.... I grouped it by opened or closed... Can I get some advice on which step I'm missing? 
User-added image

 
All,
I was asked to update some code so that instead of always inserting an Opportunity based on the Task insertion criteria, it only inserts an Opportunity if the related Account doesn't already have one. Usually I think this would be solved using Account.Opportunities.Size()==0, but I'm inserting the Opportunity based off a Task creation and finding the Account associated to the Contact using AccountId. And
​ cIdMap.get(tsk.whoId).AccountId.Opportunities.Size()==0
throws an Invalid foreign key relationship: Contact.AccountId error.

Does anyone know how I could solve this?

Here is the full code. The method is on lines 82-118.
public class SalesBlitzProcess {
    //Grab Lst of tasks
    protected final Task[] taskNewList;
    protected final Task[] taskOldList;
    
    public SalesBlitzProcess (Task[] taskOldList, Task[] taskNewList){
        this.taskNewList = taskNewList;
        this.taskOldList = taskOldList;
    }
    
    List<Task> taskList = new List<Task>();
    List<Opportunity> oppList = new List<Opportunity>();
    Task t;
    Opportunity o;
    Contact c;
    Account a;
    
    //Left Message - Create new Tasks if the following Outcomes == 'Left Message' || 'No Answer'
    Set<Contact> cSet = new Set<Contact>();
    public void executeLeftMessage(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 1' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                //Set c.Nurture_Paused__c = True; and c.Send_Day_1_Follow_Up_Email__c = true;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = true;
                    c.Send_Day_1_Follow_Up_Email__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Sales Blitz Call - Day 3';
                t.Status = 'Not Started';
                t.ActivityDate = System.Today().addDays(2);
                taskList.add(t);
                
            } else if (tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 3' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Sales Blitz Call - Day 5';
                t.Status = 'Not Started';
                t.ActivityDate = System.Today().addDays(2);
                taskList.add(t);
                
            } else if (tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 5' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                //c.Send_Day_1_Follow_Up_Email__c = true;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Send_Day_5_Follow_Up_Email__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Sales Blitz Call - Day 8';
                t.Status = 'Not Started';
                t.ActivityDate = System.Today().addDays(3);
                taskList.add(t);
                
            } else if (tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 8' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                //Set c.Nurture_Paused__c = False;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = false;
                    c.Send_Day_1_Follow_Up_Email__c = false;
                    c.Send_Day_5_Follow_Up_Email__c = false;
                    cSet.add(c);
                }
            }
        }
        
        If(!taskList.isEmpty()){
            insert taskList;
        }
        If(!cSet.isEmpty()){
            update new List <Contact>(cSet);
        }
    }
    
    //Continue Process - Create Opportunity if Task has the following outcomes
    Set<Id> ContactIds = new Set<Id>();
    public void executeContinueProcess(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && (tsk.Outcome__c == 'Set First Advisor Briefing'
                || tsk.Outcome__c == 'Set Qualified Meeting'
                || tsk.Outcome__c == 'Set Existing Producer Meeting'
                || tsk.Outcome__c == 'Set Touch Base Meeting'
                || tsk.Outcome__c == 'Proposal Needed'
                || tsk.Outcome__c == 'Verbal Commitment')){
                    String tId = tsk.WhoId;
                    if(String.ValueOf(tsk.WhoId).substring(0,3) == '003'){
                        ContactIds.add(tsk.WhoId);
                    }
                    
                    List<Contact> taskContacts = [Select Id, AccountId, Account.Name, Nurture_Paused__c FROM Contact Where Id in:ContactIds];
                    Map<Id, Contact> cIdMap = new Map<Id, Contact>(taskContacts);
                    //Create Opportunity if Task has the outcome above
                    o = new Opportunity();
                    //system.debug('==========Contact Id ========'+tsk.WhoId);
                    //system.debug('==========Contact record ========'+cIdMap.get(tsk.WhoId));
                    //system.debug('==========account Id ========'+cIdMap.get(tsk.WhoId).AccountId);
                    if(tsk.WhoId != null && cIdMap.get(tsk.WhoId) != null){
                        o.AccountId = cIdMap.get(tsk.WhoId).AccountId;
                    }
                    o.Name = 'New Sales Blitz Opportunity';
                    o.StageName = 'New';
                    o.Opportunity_Potential__c = 0.00;
                    o.CloseDate = Date.today();
                    o.OriginalOpportunitySource__c = 'Sales Blitz';
                    oppList.add(o);
                }
        }
        If(!oppList.isEmpty()){
            insert oppList;
        }
    }
    
    //Not Now - Check Nurture Paused for 3 weeks if Outcome__c == Follow Up Or TBD, then unpause.
    public void executeNotNow(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && (tsk.Outcome__c == 'Follow Up' || tsk.Outcome__c == 'TBD')){
                //Set c.Nurture_Paused__c = True;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Unpause Nurture - 3 Weeks';
                t.Status = 'Not Started';
                t.Outcome__c = 'Unpause Nurture';
                t.ActivityDate = System.Today().addDays(21);
                taskList.add(t);
            }
            //After 3 weeks, unpause nurture
            //Once closed, uncheck checkbox
            else if (tsk.Status =='Completed' && tsk.Subject == 'Unpause Nurture - 3 Weeks' && tsk.Outcome__c == 'Unpause Nurture'){
                //Set c.Nurture_Paused__c = False;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = false;
                    cSet.add(c);
                }
            }
        }
        If(!taskList.isEmpty()){
            insert t;
        }
        if(!cSet.isEmpty()){
            update new List <Contact>(cSet);
        }
    }
    //Hard No - Create reminder task to close in 90 days to unpause nurture
    public void executeHardNo(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && tsk.Outcome__c == 'Not Interested' && tsk.Subject.contains('Sales Blitz')){
                //Set c.Nurture_Paused__c = True;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Unpause Nurture - 3 Months';
                t.Status = 'Not Started';
                t.Outcome__c = 'Unpause Nurture';
                t.ActivityDate = System.Today().addDays(90);
                taskList.add(t);
            }
            //After 3 months, unpause nurture
            //Once closed, uncheck checkbox
            else if (tsk.Status =='Completed' && tsk.Subject == 'Unpause Nurture - 3 Months' && tsk.Outcome__c == 'Unpause Nurture'){
                //Set c.Nurture_Paused__c = False;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = false;
                    cSet.add(c);
                }
            }
        }
        If(!taskList.isEmpty()){
            insert t;
        }
        if(!cSet.isEmpty()){
            update new List <Contact>(cSet);
        }
    }
}

 
Not sure why I 'm getting a null pointer error here in the batch process, any thoughts are appreciated :)

Code
public Database.QueryLocator start(Database.BatchableContext BC)  
{
    String query = 'SELECT Id,  (SELECT ContactId, IsPrimary FROM OpportunityContactRoles ORDER BY IsPrimary DESC) FROM Opportunity WHERE LastModifiedDate = LAST_N_DAYS:365';
    return Database.getQueryLocator(query); 
}

public void execute(Database.BatchableContext BC, List < sObject > s)
{
    List < Opportunity > oppsToUpdate = new List < Opportunity > ();
    for (sObject ssss: s)
    {
        Opportunity o = (Opportunity) ssss;
        List < OpportunityContactRole > opptys = new List < OpportunityContactRole > ();
        opptys = (List < OpportunityContactRole > ) o.getsobjects('OpportunityContactRoles'); //o.getsobjects will return a List<SObject>, in the same line we cast those into List<OpportunityContactRole>

        for (OpportunityContactRole optt: opptys) // HERE IS WHERE THE ERROR IS.  LOOPING THROUGH SUB QUERY LIST
        {
            String contId = '';
            contId = String.ValueOf(optt.ContactId);
            if (!String.IsBlank(contId))
            {
                o.Primary_Contact_Id__c = contId;
                oppsToUpdate.add(o);
                break;
            }
        }
    }

    update oppsToUpdate;

}
plz help me with this.
1) I am having an User (let’s say Stephan). Who has a custom Field called : Immediate Manager. (Hierarchy Field)
2) We have an Account (let’s Say : Google). Whose owner is Stephan.
3) Whenever I will deactivate that user, then that User’s Immediate manager will become owner of all Account, which Stephan owned. Code with all best practices. (Bulkifying).
Also write Test method for this , which should cover at least 85%. functionality should be checked if working or not in test Class also.

trigger RecordOwnerChangeEx on User (after update) {   
 list<user> u=[select id, isActive, ManagerId from user where id in:trigger.new];
  // list<account> acc=[select id, ownerId from Account where ownerId in: ids ];
    list<account> ac=new list<account>();
    for(User uu:u){
        if(uu.IsActive == false && uu.ManagerId != null){
        for(account a:[select id, ownerId from Account where ownerId =:uu.id ]){
            a.ownerId = uu.ManagerId;
            ac.add(a);
        }
    }
    }
    update ac;

Tried with this but not working. 
How to get rid of the issue in visualforce page - Maximum Continuation state size limit (80KB) excceded?
Hi I am trying to populate a custom field on the Account object with the most recent Task Activity Date where the Task Owner = Account Owner. This is the trigger I have so far, I can't figure out how to add the t.ownerid = a.ownerid filter.
 
trigger LastActivityByOwner on task(after insert) {

  map<id,Account> accounts = new map<id,account>();
    
  for(task record:trigger.new) {
      
    if(record.ownerid.getsobjecttype()==user.sobjecttype) {
        
      if(record.ownerid!=null) {
        accounts.put(record.accountid,new account(id=record.accountid,Last_Activity_By_Owner__c=record.ActivityDate));
      }
    }
  }
  update accounts.values();
}

 

Hi,

has anyone sucessfully integrated google prediction api with salesforce?

i had seen a dreamforce video regarding this but unfortunately i couldnt find the Source code repo .

If any of you has sucessuly implemented prediction api in salesforce, can you please share the code?

Thanks,
Ravi Narayanan

Hi All

 

I wish to enable INTELLISENSE feature in my VF Input Textbox, so that as soon as i start entering something, it shows a dropdown of items listing the most viable choices.

 

Kindly help!!!

 

Thanx in Advance

Shiv