• Gab Silvermotion
  • NEWBIE
  • 45 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 22
    Replies

Hello! I am using a custom form in a webtab, and when it's filled I am redirecting to the newly created opportunity, and it's works fine. 

However, it shows multiple sidebars and headers, I am trying to prevent that. 

I tried the various ?isdtp= parameters, and they prevent javascript from working, so i cannot click on other records to open them

is there a way to refresh the whole thing when redirecting? so it loads only the record I want rather than the record within the Iframe?
 
see below. Thanks


User-added image

Hello, I am trying to create a process where depending on the values of some field on the contact record, I will either update the existing opportunity, or create it if it's not existing already. I want to avoid creating a duplicate opportunity if it exists already.  How would I do that?

thanks!
Hello! We started using a booking solution and they have a bunch of way we can add this to our website and marketing emails and we did. I'd love to place that widget on my opportunity layout. is there a way to do this?

This is what the code looks like.: 
Website (HTML)
<img id="scheduling-12773625" src="https://www.agendize.com/web//img/scheduling_en.gif" onclick="openScheduling(12773625)" style="cursor : pointer; border: 0"/> <script type="text/javascript">var scheduling = {server: 'www.agendize.com', button: '16065759', lang: 'en'};</script> <script type="text/javascript" src="https://www.agendize.com/web/scheduling.js"></script>


iFrame
<iframe src="https://www.agendize.com/book/iframe/12773625?lang=en" frameborder="0" style="width: 750px; height: 510px; border: 0" marginwidth="0" scrolling="auto"></iframe>


 
Hello! I am new to apex development and any help is greatly appreciated. 

Here is the issue i am having. 

We are a real estate developer, and we use the case objects to log defiencies in condos (missing a door, scratches in the paint, cracks in a counter, etc)

our assets are in the following format : (project name) - (condo number)

instead of using the standard lookup field functionality (the looking glass, then search for keywords), i'd love to have 2 dropdown custom fields on the case object, one for the project, and one for the unit number, and when we save the new case, an apex trigger would run and concatenate the values of those fields into the (project name) - (condo number) format, and update the asset lookup field. 

I tried with a workflow rule + field update, but it won't let me update lookup fields. 

how would i go into doing that?

thank you very much!








Hi all, 

I have this error 2 times in this test class. 

System.ListException: List index out of bounds: 0
Class.FastSubmitAssetsClassTest.SubmitMultipleCaseTest: line 27, column 1

System.ListException: List index out of bounds: 0
Class.FastSubmitAssetsClassTest.SubmitSigleCaseTest: line 8, column 1

Code Sample :

@isTest(SeeAllData=true)
Public Class FastSubmitAssetsClassTest{


    //
    @IsTest Public Static Void SubmitSigleCaseTest(){
        FastSubmitAssetsClass FsA=new FastSubmitAssetsClass();
        FsA.SelectedId=FsA.assetContainers.get(0).cases.get(0).kase.id;           
        system.assertNotEquals(NULL,FsA.SubmitForApproval());
        
        PageReference submitPage=Page.FastSubmitAssetsPage;
        Test.setCurrentPageReference(submitPage);        
        ApexPages.CurrentPage().getParameters().put('assetId',FsA.assetContainers.get(0).asset.id);
        system.assertNotEquals(NULL,FsA.SubmitForApproval());
        
        //Action page testing
        PageReference actionPage=Page.FastSubmitActionPage;
        Test.setCurrentPageReference(actionPage);
        ApexPages.CurrentPage().getParameters().put('id',FsA.SelectedId);
        FastSubmitActionClass action=new FastSubmitActionClass();
        system.assertEquals(NULL,action.yes());
        system.assertNotEquals(NULL,action.no());
        
    }
    @IsTest Public Static Void SubmitMultipleCaseTest(){
        FastSubmitAssetsClass FsA=new FastSubmitAssetsClass();
        FastSubmitAssetsClass.CaseContainer cc=FsA.assetContainers.get(0).cases.get(0);
        cc.isSelected=true;           
        system.assertNotEquals(NULL,FsA.SubmitSelected());
        
        //Action page testing
        PageReference actionPage=Page.FastSubmitActionMultiplePage ;
        Test.setCurrentPageReference(actionPage);
        ApexPages.CurrentPage().getParameters().put('allids',cc.Kase.id);
        FastSubmitActionClass action=new FastSubmitActionClass();
        system.assertNotEquals(NULL,action.YesMulti());
        system.assertNotEquals(NULL,action.NoMulti());
        
        
    }
    //Product_udpate and OpportunityLine Item testing 
    @IsTest Public static void AdditionalTesting(){
        Product2 prod=[Select Id,Name from Product2 LIMIT 1];
        prod.Name='Name Changing';
        update prod;
        
        OpportunityLineItem oli=[SELECT id,PriceBookEntryId 
                                 FROM OpportunityLineItem LIMIT 1];
        UPDATE Oli;
        
    
    }

}



Hello! I have this error when running tests. 

System.QueryException: List has no rows for assignment to SObject
Class.FastSubmitAssetsClassTest.AdditionalTesting: line 43, column 1

Code Sample :

@isTest(SeeAllData=true)
Public Class FastSubmitAssetsClassTest{


    //
    @IsTest Public Static Void SubmitSigleCaseTest(){
        FastSubmitAssetsClass FsA=new FastSubmitAssetsClass();
        FsA.SelectedId=FsA.assetContainers.get(0).cases.get(0).kase.id;           
        system.assertNotEquals(NULL,FsA.SubmitForApproval());
        
        PageReference submitPage=Page.FastSubmitAssetsPage;
        Test.setCurrentPageReference(submitPage);        
        ApexPages.CurrentPage().getParameters().put('assetId',FsA.assetContainers.get(0).asset.id);
        system.assertNotEquals(NULL,FsA.SubmitForApproval());
        
        //Action page testing
        PageReference actionPage=Page.FastSubmitActionPage;
        Test.setCurrentPageReference(actionPage);
        ApexPages.CurrentPage().getParameters().put('id',FsA.SelectedId);
        FastSubmitActionClass action=new FastSubmitActionClass();
        system.assertEquals(NULL,action.yes());
        system.assertNotEquals(NULL,action.no());
        
    }
    @IsTest Public Static Void SubmitMultipleCaseTest(){
        FastSubmitAssetsClass FsA=new FastSubmitAssetsClass();
        FastSubmitAssetsClass.CaseContainer cc=FsA.assetContainers.get(0).cases.get(0);
        cc.isSelected=true;           
        system.assertNotEquals(NULL,FsA.SubmitSelected());
        
        //Action page testing
        PageReference actionPage=Page.FastSubmitActionMultiplePage ;
        Test.setCurrentPageReference(actionPage);
        ApexPages.CurrentPage().getParameters().put('allids',cc.Kase.id);
        FastSubmitActionClass action=new FastSubmitActionClass();
        system.assertNotEquals(NULL,action.YesMulti());
        system.assertNotEquals(NULL,action.NoMulti());
        
        
    }
    //Product_udpate and OpportunityLine Item testing 
    @IsTest Public static void AdditionalTesting(){
        Product2 prod=[Select Id,Name from Product2 LIMIT 1];
        prod.Name='Name Changing';
        update prod;
        
        OpportunityLineItem oli=[SELECT id,PriceBookEntryId 
                                 FROM OpportunityLineItem LIMIT 1];
        UPDATE Oli;
        
    
    }

}



Hello! i have a visual force page that list cases, that we use for massive ''submit for approval" requests. 

I have sharing rules in place that allows only certain cases to be displayed to certain users, based on asset names

My case are set to private, since we have portal users.

I have replaced all the ''public class" with "public with sharing class" in the apex code of the corresponding apex classes. 

however, when i access the visualforce page from a user that should only see certain cases, he sees them all. 

here is a screenshot of my sharing rules, and the code for the 2 apex classes in question. Highlighted in yellow is the sharing rule where my user should only see cases from assets that contain "M9 Phase 4"

maybe someone can point out where i am doing something wrong?  Many thanks!

User-added image


public with sharing class FastSubmitAssetsClass {
    
    
    public PageReference SubmitSelected()
    {
        string assetId = Apexpages.currentPage().getParameters().get('assetId');
        String allIds = '';
        for(assetContainer ac : assetContainers)
        {
            for(CaseContainer c : ac.cases)
            {
                
                if(c.isSelected)
                {
                    allIds = allIds + c.kase.Id;
                }
            }
            
        }
        if(allIds == '')
        {
            return null;
            //insert error message here}
        }
        else
        {
            return new PageReference('/apex/FastSubmitActionMultiplePage?allids=' + allIds);       
        }
    }        
    
    public PageReference SubmitForApproval()
    {
        string assetId = Apexpages.currentPage().getParameters().get('assetId');
        if(assetId != null && assetId != ''){
            return new PageReference('/apex/FastSubmitActionPage?id=' + SelectedId + '&redirect=' + assetId + '&action=Submit');  
        }else{
            return new PageReference('/apex/FastSubmitActionPage?id=' + SelectedId + '&action=Submit');
        }
        return null;
    }
    
    public string SelectedId {get;set;}
    
    
    public with sharing class AssetContainer implements Comparable {
        public Asset asset {get;set;}
        public string name;
        public List<CaseContainer> cases {get;set;}
        public Boolean hasCases {
            get {
                return cases != null && !cases.isEmpty();
            }
        }
        public AssetContainer(Asset a) {
            asset = a;
            name = a.Name;
            cases = new List<CaseContainer>();
        }
        
        public Integer compareTo(Object compareTo){
            AssetContainer assetToCom = (AssetContainer)compareTo;
            if(name == assetToCom.asset.Name) return 0;
            if(name > assetToCom.asset.Name) return 1;
            return -1;
        }
    
    }
    
    public with sharing class CaseContainer {
        public Case kase {get;set;}
        public boolean isSelected{get;set;}
        
        public Boolean hasCase{
            get {
                return kase != null;
            }
        }
    
        public CaseContainer(Case c) {
            kase = c;
            system.debug('====+++=='+kase);
            isSelected=false;            
        
        }
    }

    public List<AssetContainer> assetContainers {get;set;}
    public List<Asset> assetContainersOrd {get;set;}
    
    
    public FastSubmitAssetsClass() {
        // Pierre Dufour - 2012-12-14 - Gabriel and France need to see what need to be Submited by construction user.
        //List<ProcessInstanceWorkitem> workItems = [SELECT ActorId,CreatedById,CreatedDate,Id,OriginalActorId,ProcessInstanceId FROM ProcessInstanceWorkitem where ActorId =: UserInfo.getUserId()] ;
        List<ProcessInstanceWorkitem> workItems = [SELECT ActorId,CreatedById,CreatedDate,Id,OriginalActorId,ProcessInstanceId FROM ProcessInstanceWorkitem where ActorId =: Constants.constructionUserId] ;        
        
        List<Id> processInstanceId = new List<Id>();
        for(ProcessInstanceWorkitem wi : workItems)
        {
            processInstanceId.add(wi.ProcessInstanceId);
        }
        Map<Id,ProcessInstance> processInstances = new Map<Id,ProcessInstance>([SELECT CreatedById,CreatedDate,Id,IsDeleted,LastModifiedById,LastModifiedDate,Status,SystemModstamp,TargetObjectId FROM ProcessInstance where Id in :processInstanceId ]);
        List<Id> casesId=new List<id>();
        for(ProcessInstance process:processInstances.values()){
            casesId.add(process.TargetObjectId);
        }                
        Map<Id,Case> cases =new Map<Id,Case>([Select Id,CaseNumber,Status, Subject,Asset.Name,Asset.CreatedDate,AssetId from Case where Id NOT in : casesId AND Status IN('New','Open','Reopened')]);
        Map<Id,String> assets = new Map<Id,String>();
        Map<Id,List<Case>> casesByAsset = new Map<Id,List<Case>>();
        for(Case c : cases.values())
        {
            if(!casesByAsset.containsKey(c.AssetId))
            {
                casesByAsset.put(c.AssetId, new List<Case>());
            }
            casesByAsset.get(c.AssetId).add(c);
            //assets.put(c.AssetId, c.Asset.Name);
            assets.put(c.AssetId, c.Asset.Name);
            //createdDate = c.Asset.CreatedDate;
        }
        assetContainers = new List<AssetContainer>();
        Boolean passe = false;
        for(string assId : assets.keySet())
        {
            Asset a  = new Asset(Id = assId,Name=assets.get(assId));
            AssetContainer ac = new AssetContainer(a);
            
            
            //kevin C035536 11-04-2014
            string assetId = Apexpages.currentPage().getParameters().get('assetId');
            
            if(assetId != null && assetId != ''){
                if(assetId == a.Id){
                    for(Case c : casesByAsset.get(a.Id))
                    {
                        ac.cases.add(new CaseContainer(c));
                    }
                    assetContainers.add(ac);
                }
            }else{
                for(Case c : casesByAsset.get(a.Id))
                {
                    
                    ac.cases.add(new CaseContainer(c));
                }
                assetContainers.add(ac);
            }
            
            
            assetContainers.sort();
        }                
    }
    
}



public with sharing class FastSubmitActionClass {
    public string AssetName {get;set;}
    public string CaseId {get;set;}
    public list<String> caseIdList {get; set;}
    public list<Case> caseList {get; set;}
    public string CaseNumber {get;set;}
    public string CaseSubject{get;set;}
    public string SelectedAction {get;set;}
    public string ProcessId {get;set;}
    public boolean Reject {get;set;}
    public string Reason {get;set;}
    public boolean Reopen {get;set;}
    public string StringForPage {get; set;}
    public FastSubmitActionClass()
    {
        if(ApexPages.currentPage().getparameters().get('allids') != '' &&
        ApexPages.currentPage().getparameters().get('allids') != null) // multiple cases to Submit
        {
            StringForPage = '';
            String IDListString = ApexPages.currentPage().getparameters().get('allids');
            list<String> caseIDs = new list<ID>();
            while(IDListString.length() > 1)
            {
                caseIds.add(IDListString.substring(0,18));
                IDListString = IDListString.substring(18);
            }
            caseIdList = caseIDs;
            //Query should never be empty since method doesn't run if no cases are selected from the FastSubmitAssets page
            list<Case> tempCaseList = [SELECT ID, CaseNumber, Subject, Status, Asset.Name FROM Case WHERE ID in : caseIds];
            caseList = tempCaseList;
        }
        else
        {
            CaseId = ApexPages.currentPage().getparameters().get('id');
            Case c = [ Select Id, CaseNumber, Subject, Asset.Name from Case where Id =:CaseId];
            CaseNumber = c.CaseNumber;
            AssetName = c.Asset.Name;
            CaseSubject = c.Subject;
            SelectedAction = ApexPages.currentPage().getparameters().get('action');
            Reject = SelectedAction == 'Reject';
            Reopen = true;
        }
    }
    
    
    public PageReference YesMulti()
    {
        list<Case> listCases=[SELECT id, Subject, Status
                              FROM Case
                              WHERE id IN:CaseIdList];                
        List<Approval.ProcessSubmitRequest> listRequests = 
            new List<Approval.ProcessSubmitRequest>();
        Approval.ProcessSubmitRequest req;
        for(Case cse:listCases){
            req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitting request for approval.');
            req.setObjectId(cse.id);
            listRequests.add(req);
        }
        try{        
            // Submit the approval request for the account
            List<Approval.ProcessResult> results = Approval.process(listRequests);        
            // Verify the result
            for(Approval.ProcessResult aPResult:results){
                System.assert(aPResult.isSuccess());        
                System.assertEquals('Pending', aPResult.getInstanceStatus(), 'Instance Status'+aPResult.getInstanceStatus()); 
            }                       
            return new PageReference('/apex/FastSubmitAssetsPage');
        }catch(Exception e){
            ApexPages.Message errMsg = new ApexPages.Message(ApexPages.SEVERITY.ERROR, e.getMessage());    
            ApexPages.addMessages(e);
            return Null; 
        }
        return null;
    }
    
    public PageReference NoMulti()
    {
        return new PageReference('/apex/FastSubmitAssetsPage');
    }
    
    public PageReference Yes()
    {
        Case cse=[SELECT id, Subject, Status
                              FROM Case
                              WHERE id =:CaseId];
        Approval.ProcessSubmitRequest req;
        if(SelectedAction=='Submit'){
            req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitting request for approval.');
            req.setObjectId(cse.id);    
        }   
        try{
            // Submit the approval request for the account
            Approval.ProcessResult result = Approval.process(req);             
            
            string redirect = Apexpages.currentPage().getParameters().get('redirect'); 
            
            //C030817 kevin ky 11-04-2014
            if(redirect != null && redirect != ''){
                return new PageReference('/apex/FastSubmitAssetsPage?assetId='+redirect);
            }
            return new PageReference('/apex/FastSubmitAssetsPage');
        }catch(Exception e){
            ApexPages.Message errMsg = new ApexPages.Message(ApexPages.SEVERITY.ERROR, e.getMessage());    
            ApexPages.addMessages(e);
            return Null; 
        }  
        return null;  
    }
    public PageReference No()
    {
        //C030817 kevin ky 11-04-2014
        string redirect = Apexpages.currentPage().getParameters().get('redirect'); 
        if(redirect != null && redirect != ''){
            return new PageReference('/apex/FastSubmitAssetsPage?assetId='+redirect);
        }
        return new PageReference('/apex/FastSubmitAssetsPage');
    }
}



Hello SF community!

How would i perform the following : restrict case access to customer portal users so they only see cases matching certain criterias. i tried a sharing rule but they can still see them all. 

normally i would make lists and that would be it. but now i have made a visualForce page to list cases for the postal users, and they see all the cases. 

I must be doing something wrong. 

thank you!
Hello!

I have this apex code that changes automatically the stage of the opportunity based on the activities made in the opportunities. 

I move it from one SF instance to another using packages. It works as intended in the source instance, but in the target instance it give me the following error

Apex trigger nubik_OpportunityAutoStage caused an unexpected exception, contact your administrator: nubik_OpportunityAutoStage: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.nubik_OpportunityAutoStage: line 52, column 1

anyone knows why?


here is the code of the trigger: line 52 is this one :  if(t.Type.toLowerCase().startsWith('call')) 


// This trigger set the stage of an opp based on 4 actions ;
// 1. Email Counter
// 2. Phone Calls
// 3. Visits Sales Office (walk-in counter)
// 4. Underwriting (see the closing_details__c object)
trigger nubik_OpportunityAutoStage on Opportunity (before update, before insert) {

map<string, list<Task>> taskMap = new map<string, list<Task>>();
map<string, list<Event>> eventMap = new map<string, list<Event>>();

if (trigger.isUpdate)
{
  for(Task t : [Select Id, Status, WhatId, Type, Subject from Task where WhatId in : Trigger.newMap.keyset()])
  {
   if (!taskMap.containsKey(t.WhatId))
    taskMap.put(t.WhatId, new list<Task>());
  
   taskMap.get(t.WhatId).add(t);
  }
 
  system.debug('nubik_OpportunityAutoStage taskMap ' + taskMap);
 
  for(Event e : [Select Id, WhatId, Type, Subject from Event where WhatId in : Trigger.newMap.keyset()])
  {
   if (!eventMap.containsKey(e.WhatId))
    eventMap.put(e.WhatId, new list<Event>());
  
   eventMap.get(e.WhatId).add(e);
  }
 
  system.debug('nubik_OpportunityAutoStage eventMap ' + eventMap);
 
  for(string oppId : trigger.newMap.keyset())
  {
   system.debug('nubik_OpportunityAutoStage oppId ' + oppId );
  
   integer question = 0;
   integer walkIn = 0;
   integer email = 0;
   integer call = 0;
  
   if (taskMap.get(oppId) != null)
   {
    system.debug('nubik_OpportunityAutoStage oppId relate tasks ' + taskMap.get(oppId));
    for(Task t : taskMap.get(oppId))
    {
     if (t.Type != null && t.Type == 'Question' && t.Status != 'Completed')
      question++;
     
     
     if(t.Type.toLowerCase().startsWith('call'))
      call++;
          
          if(t.Type.toLowerCase().startsWith('email'))
           email++;
          
         
    }
   }
  
   if (eventMap.get(oppId) != null)
   {
    for(Event e : eventMap.get(oppId))
    {
     if (e.Type != null && (e.Type == 'Walk-In' || e.Type.contains('Meeting')))
      walkin++;
    }
   }
  
   system.debug('nubik_OpportunityAutoStage oppId ' + oppId );
  
   Trigger.newMap.get(oppId).Question_Counter__c = question;
   Trigger.newMap.get(oppId).Email_Attemps_Counter__c = email;
   Trigger.newMap.get(oppId).Walking_Attemps_Counter__c = walkin;
   Trigger.newMap.get(oppId).Call_Attemps_Counter__c = call;
  }
}

map<string, Closing_Detail__c> closingMap = new map<string, Closing_Detail__c>();
map<string, VIP__c> vipMap = new map<string, VIP__c>();

if (trigger.isUpdate)
{
  for (Closing_Detail__c tempClosing : [Select Id, Opportunity__c, Bank_Approval__c , Bank_Refusal__c from Closing_Detail__c  where Opportunity__c in : trigger.newMap.keyset()])
  {
   closingMap.put(tempClosing.Opportunity__c, tempClosing);
  }
 
  for (VIP__c tempVIP : [Select Id, Opportunity__c, Canceled__c from VIP__c  where Opportunity__c in : trigger.newMap.keyset()])
  {
   vipMap.put(tempVIP.Opportunity__c, tempVIP);
  }
 
  system.debug('VIP Count ' + vipMap.size());
}

for (Opportunity tempOpp : trigger.new)
{
  // If it's a manual update, don't touch to the stage.
  if(trigger.isUpdate)
  {
   Opportunity oldOpp = trigger.oldMap.get(tempOpp.Id);
   if (tempOpp.StageName != oldOpp.StageName)
   {
    system.debug('Opportunity Auto Stage Skipped -> Manual Stage');
    continue;
   }
  }
 
 
  // If a closing details have been created -> Min Stage = Underwriting
  if(tempOpp.StageName == null || tempOpp.StageName.toLowerCase().indexof('closed') != -1)
  {
   system.debug('Opportunity Auto Stage Skipped -> Stage Closed or Null');
   continue;
  }
  if (closingMap.containsKey(tempOpp.Id))
  {
   Closing_Detail__c c = closingMap.get(tempOpp.Id);
   if (c.Bank_Approval__c)
    tempOpp.StageName = 'Closed – Win';
   else if(c.Bank_Refusal__c)
   {
    tempOpp.StageName = 'Closed - Lost';
    tempOpp.Lost_Reason__c = 'Bank Refusal';
   }
   else
    tempOpp.StageName = 'Underwriting';
  }
  // Then check if there is a remaining question
  else if (tempOpp.Question_Counter__c > 0)  
  {
   tempOpp.StageName = 'Question to Answer';
  }
  else
  {
   if (tempOpp.VIP__c != null)
   {
    VIP__c tempVIP = vipMap.get(tempOpp.Id);
    system.debug('Found VIP');
    if(tempVip != null)
    {
     if (tempVip.Canceled__c != null)
     {
      if (tempVip.Canceled__c == true)
      {
       tempOpp.StageName = 'Closed-Lost';
       tempOpp.Lost_Reason__c = 'VIP Canceled';
      }
     }
    }
    else
    {
     tempOpp.StageName = 'VIP';
    }
    
   }
   else if (tempOpp.Walking_Attemps_Counter__c >= 3)
   {
    tempOpp.StageName = '3+ Visits Sales Office';
   }
   else if (tempOpp.Walking_Attemps_Counter__c >= 2)
   {
    tempOpp.StageName = '2 Visits Sales Office';
   }
   else if (tempOpp.Walking_Attemps_Counter__c >= 1)
   {
    tempOpp.StageName = '1 Visit Sales Office';
   }
   else if (tempOpp.Call_Attemps_Counter__c >= 3)
   {
    tempOpp.StageName = '3+ Calls Made';
   }
   else if (tempOpp.Call_Attemps_Counter__c >= 2)
   {
    tempOpp.StageName = '2 Calls Made';
   }
   else if (tempOpp.Call_Attemps_Counter__c >= 1)
   {
    tempOpp.StageName = '1 Call Made';
   }
   else
   {
    tempOpp.StageName = '0 Call Made';
   }
  }
}
 
return;
Hello!

i need to implement a multi level approval process for cases.  it concerns 2 regular salesforce users and 2 portal users. 

let's call them user A, B, C and D

so users A and B needs to be able to send their cases for approval to user C.  user C will decide if it's ok or not and approve and reject the case. however, on a second level, user C needs also to create cases of its own and send them for approval to user D only.  how do i pull that off?

so to recap

A  --> C
B  --> C
C --> D

thanks!
Hello, i need to modify the code of an existing trigger in our salesforce. the original trigger was coded by a firm we a no longer dealing with.

basically, the trigger automatically changes the stage of the opportunity depending on actions the sales rep are doing (calling, sending emails, receiving prospects in the sales office)

so here's the deal.

existing code :

if (e.Type != null && e.Type == 'Walk-In')
      walkin++;

id like to modify it so the walkin+++ occurs not only when there is a event named ''walk-in", but also for all those containing "Meeting".

the event type "walk-in" is for when a prospect visits a sales office unnanounced.  we added 1st meeting, 2nd meeting, 3rd meeting, 4th+ meeting as event types to log when the prospects visits after they have talked to a sales rep.

so i guess something like

If (e.Type !=null && (e.Type == ‘Walk-In’ || e.Type.contains(‘Meeting’))
Walkin++

??

thanks for the help, i'm new at apex development and it's a bit overwhelmong at first.

since i'm modifying an existing trigger, can i just change it in the dev console and save?

thank you!

Hello!  We are a real estate developer. We receive deposits from customers, and we track them with salesforce. I'd love an email alert to automatically fire a couple days before the deposit deadline to the corresponding contact.  I have no problems creating the time-based workflow rule, but i cant seem to be able to set the email update to be sent to the contact (there is only one in the account).  We manage deposits in a custom objects called ''deposits'' which is linked to assets.   Is it possible to do what i want to do?

 

thanks in advance,

Hello!

 

i'm trying to find a way to report on our sales rep activities, and i'd like to use a stackable date range formula.   To be precise, i'dl like to separate activities into 3 dates range, 0-7 days, 0-30 days, and 0-90 days. 

 

using this formula, i am able to obtain a date range, but it's not stackablecumulative, meaning that the 0-7 days value won't be included in the 0-30 and 0-90 days periods

 

IF(AND(FLOOR(TODAY()-DATEVALUE(CreatedDate))>= 0,FLOOR(TODAY()-DATEVALUE(CreatedDate))<=7), "00-07 Days", 
IF(AND(FLOOR(TODAY()-DATEVALUE(CreatedDate))>= 0,FLOOR(TODAY()-DATEVALUE(CreatedDate))<=30), "07-30 Days", 
IF(AND(FLOOR(TODAY()-DATEVALUE(CreatedDate))>= 0,FLOOR(TODAY()-DATEVALUE(CreatedDate))<=90), "30-90 Days", 
"Older than 90 days" 
)))

 

 

for exemple, i am getting this 

 

 

0-7 days : 5

7-30 days : 5

30-90 days : 5

total : 15

 

and i'd like to get this

 

0-7 days : 5

7-30 days : 10

30-90 days : 15

total : 15

 

in other words, the 0-90 days includes stuff from the 0-30 and 0-7 days. 

the 0-30 days includes stuff from the 0-7 days

 

how can i do that?

 

thanks!

 

Hello, i'm looking for help (my first trigger woohoo!) to do the following

 

after a sales rep calls a prospect (by logging a ''Call'' type task in opportunities), and the prospect says ''never call me again'', the reps select the ''do not call again'' call conclusion.

 

i'd like to make a trigger where when this is selected and saved, it would automatically update the ''do not call'' field in opps and in contact.

 

 

 

 

 

 

Hello!

I'm looking to create a trigger that will populate a picklist field from the asset name. Like If asset name starts with X, then set value Y. I tried with field updates but it won't fire until i save the record, and i need it to fire at the creation of the record (when i click on ''new case'')

the reason why i need a picklist auto populated is because i need it to control another picklist, and it won't work with a formula field.

can anyone help?

thanks!

Hello!

 

Is there a way to copy over a few fields from contacts to opportunity? For exemple, i'd like to copy over the value of phone number, language, and some other info so my sales rep don't have to constantly go back & forth form the contact to the opportunity (like retrieving the phone number of the contact before logging a call, or verifying his language before ssending and email and selecting the right email template)

 

i have been trying with formula fields but i can only select account fields, not contacts.

 

 

thank you very much!

Hello! I am new to apex development and any help is greatly appreciated. 

Here is the issue i am having. 

We are a real estate developer, and we use the case objects to log defiencies in condos (missing a door, scratches in the paint, cracks in a counter, etc)

our assets are in the following format : (project name) - (condo number)

instead of using the standard lookup field functionality (the looking glass, then search for keywords), i'd love to have 2 dropdown custom fields on the case object, one for the project, and one for the unit number, and when we save the new case, an apex trigger would run and concatenate the values of those fields into the (project name) - (condo number) format, and update the asset lookup field. 

I tried with a workflow rule + field update, but it won't let me update lookup fields. 

how would i go into doing that?

thank you very much!








Hi all, 

I have this error 2 times in this test class. 

System.ListException: List index out of bounds: 0
Class.FastSubmitAssetsClassTest.SubmitMultipleCaseTest: line 27, column 1

System.ListException: List index out of bounds: 0
Class.FastSubmitAssetsClassTest.SubmitSigleCaseTest: line 8, column 1

Code Sample :

@isTest(SeeAllData=true)
Public Class FastSubmitAssetsClassTest{


    //
    @IsTest Public Static Void SubmitSigleCaseTest(){
        FastSubmitAssetsClass FsA=new FastSubmitAssetsClass();
        FsA.SelectedId=FsA.assetContainers.get(0).cases.get(0).kase.id;           
        system.assertNotEquals(NULL,FsA.SubmitForApproval());
        
        PageReference submitPage=Page.FastSubmitAssetsPage;
        Test.setCurrentPageReference(submitPage);        
        ApexPages.CurrentPage().getParameters().put('assetId',FsA.assetContainers.get(0).asset.id);
        system.assertNotEquals(NULL,FsA.SubmitForApproval());
        
        //Action page testing
        PageReference actionPage=Page.FastSubmitActionPage;
        Test.setCurrentPageReference(actionPage);
        ApexPages.CurrentPage().getParameters().put('id',FsA.SelectedId);
        FastSubmitActionClass action=new FastSubmitActionClass();
        system.assertEquals(NULL,action.yes());
        system.assertNotEquals(NULL,action.no());
        
    }
    @IsTest Public Static Void SubmitMultipleCaseTest(){
        FastSubmitAssetsClass FsA=new FastSubmitAssetsClass();
        FastSubmitAssetsClass.CaseContainer cc=FsA.assetContainers.get(0).cases.get(0);
        cc.isSelected=true;           
        system.assertNotEquals(NULL,FsA.SubmitSelected());
        
        //Action page testing
        PageReference actionPage=Page.FastSubmitActionMultiplePage ;
        Test.setCurrentPageReference(actionPage);
        ApexPages.CurrentPage().getParameters().put('allids',cc.Kase.id);
        FastSubmitActionClass action=new FastSubmitActionClass();
        system.assertNotEquals(NULL,action.YesMulti());
        system.assertNotEquals(NULL,action.NoMulti());
        
        
    }
    //Product_udpate and OpportunityLine Item testing 
    @IsTest Public static void AdditionalTesting(){
        Product2 prod=[Select Id,Name from Product2 LIMIT 1];
        prod.Name='Name Changing';
        update prod;
        
        OpportunityLineItem oli=[SELECT id,PriceBookEntryId 
                                 FROM OpportunityLineItem LIMIT 1];
        UPDATE Oli;
        
    
    }

}



Hello! I have this error when running tests. 

System.QueryException: List has no rows for assignment to SObject
Class.FastSubmitAssetsClassTest.AdditionalTesting: line 43, column 1

Code Sample :

@isTest(SeeAllData=true)
Public Class FastSubmitAssetsClassTest{


    //
    @IsTest Public Static Void SubmitSigleCaseTest(){
        FastSubmitAssetsClass FsA=new FastSubmitAssetsClass();
        FsA.SelectedId=FsA.assetContainers.get(0).cases.get(0).kase.id;           
        system.assertNotEquals(NULL,FsA.SubmitForApproval());
        
        PageReference submitPage=Page.FastSubmitAssetsPage;
        Test.setCurrentPageReference(submitPage);        
        ApexPages.CurrentPage().getParameters().put('assetId',FsA.assetContainers.get(0).asset.id);
        system.assertNotEquals(NULL,FsA.SubmitForApproval());
        
        //Action page testing
        PageReference actionPage=Page.FastSubmitActionPage;
        Test.setCurrentPageReference(actionPage);
        ApexPages.CurrentPage().getParameters().put('id',FsA.SelectedId);
        FastSubmitActionClass action=new FastSubmitActionClass();
        system.assertEquals(NULL,action.yes());
        system.assertNotEquals(NULL,action.no());
        
    }
    @IsTest Public Static Void SubmitMultipleCaseTest(){
        FastSubmitAssetsClass FsA=new FastSubmitAssetsClass();
        FastSubmitAssetsClass.CaseContainer cc=FsA.assetContainers.get(0).cases.get(0);
        cc.isSelected=true;           
        system.assertNotEquals(NULL,FsA.SubmitSelected());
        
        //Action page testing
        PageReference actionPage=Page.FastSubmitActionMultiplePage ;
        Test.setCurrentPageReference(actionPage);
        ApexPages.CurrentPage().getParameters().put('allids',cc.Kase.id);
        FastSubmitActionClass action=new FastSubmitActionClass();
        system.assertNotEquals(NULL,action.YesMulti());
        system.assertNotEquals(NULL,action.NoMulti());
        
        
    }
    //Product_udpate and OpportunityLine Item testing 
    @IsTest Public static void AdditionalTesting(){
        Product2 prod=[Select Id,Name from Product2 LIMIT 1];
        prod.Name='Name Changing';
        update prod;
        
        OpportunityLineItem oli=[SELECT id,PriceBookEntryId 
                                 FROM OpportunityLineItem LIMIT 1];
        UPDATE Oli;
        
    
    }

}



Hello! i have a visual force page that list cases, that we use for massive ''submit for approval" requests. 

I have sharing rules in place that allows only certain cases to be displayed to certain users, based on asset names

My case are set to private, since we have portal users.

I have replaced all the ''public class" with "public with sharing class" in the apex code of the corresponding apex classes. 

however, when i access the visualforce page from a user that should only see certain cases, he sees them all. 

here is a screenshot of my sharing rules, and the code for the 2 apex classes in question. Highlighted in yellow is the sharing rule where my user should only see cases from assets that contain "M9 Phase 4"

maybe someone can point out where i am doing something wrong?  Many thanks!

User-added image


public with sharing class FastSubmitAssetsClass {
    
    
    public PageReference SubmitSelected()
    {
        string assetId = Apexpages.currentPage().getParameters().get('assetId');
        String allIds = '';
        for(assetContainer ac : assetContainers)
        {
            for(CaseContainer c : ac.cases)
            {
                
                if(c.isSelected)
                {
                    allIds = allIds + c.kase.Id;
                }
            }
            
        }
        if(allIds == '')
        {
            return null;
            //insert error message here}
        }
        else
        {
            return new PageReference('/apex/FastSubmitActionMultiplePage?allids=' + allIds);       
        }
    }        
    
    public PageReference SubmitForApproval()
    {
        string assetId = Apexpages.currentPage().getParameters().get('assetId');
        if(assetId != null && assetId != ''){
            return new PageReference('/apex/FastSubmitActionPage?id=' + SelectedId + '&redirect=' + assetId + '&action=Submit');  
        }else{
            return new PageReference('/apex/FastSubmitActionPage?id=' + SelectedId + '&action=Submit');
        }
        return null;
    }
    
    public string SelectedId {get;set;}
    
    
    public with sharing class AssetContainer implements Comparable {
        public Asset asset {get;set;}
        public string name;
        public List<CaseContainer> cases {get;set;}
        public Boolean hasCases {
            get {
                return cases != null && !cases.isEmpty();
            }
        }
        public AssetContainer(Asset a) {
            asset = a;
            name = a.Name;
            cases = new List<CaseContainer>();
        }
        
        public Integer compareTo(Object compareTo){
            AssetContainer assetToCom = (AssetContainer)compareTo;
            if(name == assetToCom.asset.Name) return 0;
            if(name > assetToCom.asset.Name) return 1;
            return -1;
        }
    
    }
    
    public with sharing class CaseContainer {
        public Case kase {get;set;}
        public boolean isSelected{get;set;}
        
        public Boolean hasCase{
            get {
                return kase != null;
            }
        }
    
        public CaseContainer(Case c) {
            kase = c;
            system.debug('====+++=='+kase);
            isSelected=false;            
        
        }
    }

    public List<AssetContainer> assetContainers {get;set;}
    public List<Asset> assetContainersOrd {get;set;}
    
    
    public FastSubmitAssetsClass() {
        // Pierre Dufour - 2012-12-14 - Gabriel and France need to see what need to be Submited by construction user.
        //List<ProcessInstanceWorkitem> workItems = [SELECT ActorId,CreatedById,CreatedDate,Id,OriginalActorId,ProcessInstanceId FROM ProcessInstanceWorkitem where ActorId =: UserInfo.getUserId()] ;
        List<ProcessInstanceWorkitem> workItems = [SELECT ActorId,CreatedById,CreatedDate,Id,OriginalActorId,ProcessInstanceId FROM ProcessInstanceWorkitem where ActorId =: Constants.constructionUserId] ;        
        
        List<Id> processInstanceId = new List<Id>();
        for(ProcessInstanceWorkitem wi : workItems)
        {
            processInstanceId.add(wi.ProcessInstanceId);
        }
        Map<Id,ProcessInstance> processInstances = new Map<Id,ProcessInstance>([SELECT CreatedById,CreatedDate,Id,IsDeleted,LastModifiedById,LastModifiedDate,Status,SystemModstamp,TargetObjectId FROM ProcessInstance where Id in :processInstanceId ]);
        List<Id> casesId=new List<id>();
        for(ProcessInstance process:processInstances.values()){
            casesId.add(process.TargetObjectId);
        }                
        Map<Id,Case> cases =new Map<Id,Case>([Select Id,CaseNumber,Status, Subject,Asset.Name,Asset.CreatedDate,AssetId from Case where Id NOT in : casesId AND Status IN('New','Open','Reopened')]);
        Map<Id,String> assets = new Map<Id,String>();
        Map<Id,List<Case>> casesByAsset = new Map<Id,List<Case>>();
        for(Case c : cases.values())
        {
            if(!casesByAsset.containsKey(c.AssetId))
            {
                casesByAsset.put(c.AssetId, new List<Case>());
            }
            casesByAsset.get(c.AssetId).add(c);
            //assets.put(c.AssetId, c.Asset.Name);
            assets.put(c.AssetId, c.Asset.Name);
            //createdDate = c.Asset.CreatedDate;
        }
        assetContainers = new List<AssetContainer>();
        Boolean passe = false;
        for(string assId : assets.keySet())
        {
            Asset a  = new Asset(Id = assId,Name=assets.get(assId));
            AssetContainer ac = new AssetContainer(a);
            
            
            //kevin C035536 11-04-2014
            string assetId = Apexpages.currentPage().getParameters().get('assetId');
            
            if(assetId != null && assetId != ''){
                if(assetId == a.Id){
                    for(Case c : casesByAsset.get(a.Id))
                    {
                        ac.cases.add(new CaseContainer(c));
                    }
                    assetContainers.add(ac);
                }
            }else{
                for(Case c : casesByAsset.get(a.Id))
                {
                    
                    ac.cases.add(new CaseContainer(c));
                }
                assetContainers.add(ac);
            }
            
            
            assetContainers.sort();
        }                
    }
    
}



public with sharing class FastSubmitActionClass {
    public string AssetName {get;set;}
    public string CaseId {get;set;}
    public list<String> caseIdList {get; set;}
    public list<Case> caseList {get; set;}
    public string CaseNumber {get;set;}
    public string CaseSubject{get;set;}
    public string SelectedAction {get;set;}
    public string ProcessId {get;set;}
    public boolean Reject {get;set;}
    public string Reason {get;set;}
    public boolean Reopen {get;set;}
    public string StringForPage {get; set;}
    public FastSubmitActionClass()
    {
        if(ApexPages.currentPage().getparameters().get('allids') != '' &&
        ApexPages.currentPage().getparameters().get('allids') != null) // multiple cases to Submit
        {
            StringForPage = '';
            String IDListString = ApexPages.currentPage().getparameters().get('allids');
            list<String> caseIDs = new list<ID>();
            while(IDListString.length() > 1)
            {
                caseIds.add(IDListString.substring(0,18));
                IDListString = IDListString.substring(18);
            }
            caseIdList = caseIDs;
            //Query should never be empty since method doesn't run if no cases are selected from the FastSubmitAssets page
            list<Case> tempCaseList = [SELECT ID, CaseNumber, Subject, Status, Asset.Name FROM Case WHERE ID in : caseIds];
            caseList = tempCaseList;
        }
        else
        {
            CaseId = ApexPages.currentPage().getparameters().get('id');
            Case c = [ Select Id, CaseNumber, Subject, Asset.Name from Case where Id =:CaseId];
            CaseNumber = c.CaseNumber;
            AssetName = c.Asset.Name;
            CaseSubject = c.Subject;
            SelectedAction = ApexPages.currentPage().getparameters().get('action');
            Reject = SelectedAction == 'Reject';
            Reopen = true;
        }
    }
    
    
    public PageReference YesMulti()
    {
        list<Case> listCases=[SELECT id, Subject, Status
                              FROM Case
                              WHERE id IN:CaseIdList];                
        List<Approval.ProcessSubmitRequest> listRequests = 
            new List<Approval.ProcessSubmitRequest>();
        Approval.ProcessSubmitRequest req;
        for(Case cse:listCases){
            req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitting request for approval.');
            req.setObjectId(cse.id);
            listRequests.add(req);
        }
        try{        
            // Submit the approval request for the account
            List<Approval.ProcessResult> results = Approval.process(listRequests);        
            // Verify the result
            for(Approval.ProcessResult aPResult:results){
                System.assert(aPResult.isSuccess());        
                System.assertEquals('Pending', aPResult.getInstanceStatus(), 'Instance Status'+aPResult.getInstanceStatus()); 
            }                       
            return new PageReference('/apex/FastSubmitAssetsPage');
        }catch(Exception e){
            ApexPages.Message errMsg = new ApexPages.Message(ApexPages.SEVERITY.ERROR, e.getMessage());    
            ApexPages.addMessages(e);
            return Null; 
        }
        return null;
    }
    
    public PageReference NoMulti()
    {
        return new PageReference('/apex/FastSubmitAssetsPage');
    }
    
    public PageReference Yes()
    {
        Case cse=[SELECT id, Subject, Status
                              FROM Case
                              WHERE id =:CaseId];
        Approval.ProcessSubmitRequest req;
        if(SelectedAction=='Submit'){
            req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitting request for approval.');
            req.setObjectId(cse.id);    
        }   
        try{
            // Submit the approval request for the account
            Approval.ProcessResult result = Approval.process(req);             
            
            string redirect = Apexpages.currentPage().getParameters().get('redirect'); 
            
            //C030817 kevin ky 11-04-2014
            if(redirect != null && redirect != ''){
                return new PageReference('/apex/FastSubmitAssetsPage?assetId='+redirect);
            }
            return new PageReference('/apex/FastSubmitAssetsPage');
        }catch(Exception e){
            ApexPages.Message errMsg = new ApexPages.Message(ApexPages.SEVERITY.ERROR, e.getMessage());    
            ApexPages.addMessages(e);
            return Null; 
        }  
        return null;  
    }
    public PageReference No()
    {
        //C030817 kevin ky 11-04-2014
        string redirect = Apexpages.currentPage().getParameters().get('redirect'); 
        if(redirect != null && redirect != ''){
            return new PageReference('/apex/FastSubmitAssetsPage?assetId='+redirect);
        }
        return new PageReference('/apex/FastSubmitAssetsPage');
    }
}



Hello!

I have this apex code that changes automatically the stage of the opportunity based on the activities made in the opportunities. 

I move it from one SF instance to another using packages. It works as intended in the source instance, but in the target instance it give me the following error

Apex trigger nubik_OpportunityAutoStage caused an unexpected exception, contact your administrator: nubik_OpportunityAutoStage: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.nubik_OpportunityAutoStage: line 52, column 1

anyone knows why?


here is the code of the trigger: line 52 is this one :  if(t.Type.toLowerCase().startsWith('call')) 


// This trigger set the stage of an opp based on 4 actions ;
// 1. Email Counter
// 2. Phone Calls
// 3. Visits Sales Office (walk-in counter)
// 4. Underwriting (see the closing_details__c object)
trigger nubik_OpportunityAutoStage on Opportunity (before update, before insert) {

map<string, list<Task>> taskMap = new map<string, list<Task>>();
map<string, list<Event>> eventMap = new map<string, list<Event>>();

if (trigger.isUpdate)
{
  for(Task t : [Select Id, Status, WhatId, Type, Subject from Task where WhatId in : Trigger.newMap.keyset()])
  {
   if (!taskMap.containsKey(t.WhatId))
    taskMap.put(t.WhatId, new list<Task>());
  
   taskMap.get(t.WhatId).add(t);
  }
 
  system.debug('nubik_OpportunityAutoStage taskMap ' + taskMap);
 
  for(Event e : [Select Id, WhatId, Type, Subject from Event where WhatId in : Trigger.newMap.keyset()])
  {
   if (!eventMap.containsKey(e.WhatId))
    eventMap.put(e.WhatId, new list<Event>());
  
   eventMap.get(e.WhatId).add(e);
  }
 
  system.debug('nubik_OpportunityAutoStage eventMap ' + eventMap);
 
  for(string oppId : trigger.newMap.keyset())
  {
   system.debug('nubik_OpportunityAutoStage oppId ' + oppId );
  
   integer question = 0;
   integer walkIn = 0;
   integer email = 0;
   integer call = 0;
  
   if (taskMap.get(oppId) != null)
   {
    system.debug('nubik_OpportunityAutoStage oppId relate tasks ' + taskMap.get(oppId));
    for(Task t : taskMap.get(oppId))
    {
     if (t.Type != null && t.Type == 'Question' && t.Status != 'Completed')
      question++;
     
     
     if(t.Type.toLowerCase().startsWith('call'))
      call++;
          
          if(t.Type.toLowerCase().startsWith('email'))
           email++;
          
         
    }
   }
  
   if (eventMap.get(oppId) != null)
   {
    for(Event e : eventMap.get(oppId))
    {
     if (e.Type != null && (e.Type == 'Walk-In' || e.Type.contains('Meeting')))
      walkin++;
    }
   }
  
   system.debug('nubik_OpportunityAutoStage oppId ' + oppId );
  
   Trigger.newMap.get(oppId).Question_Counter__c = question;
   Trigger.newMap.get(oppId).Email_Attemps_Counter__c = email;
   Trigger.newMap.get(oppId).Walking_Attemps_Counter__c = walkin;
   Trigger.newMap.get(oppId).Call_Attemps_Counter__c = call;
  }
}

map<string, Closing_Detail__c> closingMap = new map<string, Closing_Detail__c>();
map<string, VIP__c> vipMap = new map<string, VIP__c>();

if (trigger.isUpdate)
{
  for (Closing_Detail__c tempClosing : [Select Id, Opportunity__c, Bank_Approval__c , Bank_Refusal__c from Closing_Detail__c  where Opportunity__c in : trigger.newMap.keyset()])
  {
   closingMap.put(tempClosing.Opportunity__c, tempClosing);
  }
 
  for (VIP__c tempVIP : [Select Id, Opportunity__c, Canceled__c from VIP__c  where Opportunity__c in : trigger.newMap.keyset()])
  {
   vipMap.put(tempVIP.Opportunity__c, tempVIP);
  }
 
  system.debug('VIP Count ' + vipMap.size());
}

for (Opportunity tempOpp : trigger.new)
{
  // If it's a manual update, don't touch to the stage.
  if(trigger.isUpdate)
  {
   Opportunity oldOpp = trigger.oldMap.get(tempOpp.Id);
   if (tempOpp.StageName != oldOpp.StageName)
   {
    system.debug('Opportunity Auto Stage Skipped -> Manual Stage');
    continue;
   }
  }
 
 
  // If a closing details have been created -> Min Stage = Underwriting
  if(tempOpp.StageName == null || tempOpp.StageName.toLowerCase().indexof('closed') != -1)
  {
   system.debug('Opportunity Auto Stage Skipped -> Stage Closed or Null');
   continue;
  }
  if (closingMap.containsKey(tempOpp.Id))
  {
   Closing_Detail__c c = closingMap.get(tempOpp.Id);
   if (c.Bank_Approval__c)
    tempOpp.StageName = 'Closed – Win';
   else if(c.Bank_Refusal__c)
   {
    tempOpp.StageName = 'Closed - Lost';
    tempOpp.Lost_Reason__c = 'Bank Refusal';
   }
   else
    tempOpp.StageName = 'Underwriting';
  }
  // Then check if there is a remaining question
  else if (tempOpp.Question_Counter__c > 0)  
  {
   tempOpp.StageName = 'Question to Answer';
  }
  else
  {
   if (tempOpp.VIP__c != null)
   {
    VIP__c tempVIP = vipMap.get(tempOpp.Id);
    system.debug('Found VIP');
    if(tempVip != null)
    {
     if (tempVip.Canceled__c != null)
     {
      if (tempVip.Canceled__c == true)
      {
       tempOpp.StageName = 'Closed-Lost';
       tempOpp.Lost_Reason__c = 'VIP Canceled';
      }
     }
    }
    else
    {
     tempOpp.StageName = 'VIP';
    }
    
   }
   else if (tempOpp.Walking_Attemps_Counter__c >= 3)
   {
    tempOpp.StageName = '3+ Visits Sales Office';
   }
   else if (tempOpp.Walking_Attemps_Counter__c >= 2)
   {
    tempOpp.StageName = '2 Visits Sales Office';
   }
   else if (tempOpp.Walking_Attemps_Counter__c >= 1)
   {
    tempOpp.StageName = '1 Visit Sales Office';
   }
   else if (tempOpp.Call_Attemps_Counter__c >= 3)
   {
    tempOpp.StageName = '3+ Calls Made';
   }
   else if (tempOpp.Call_Attemps_Counter__c >= 2)
   {
    tempOpp.StageName = '2 Calls Made';
   }
   else if (tempOpp.Call_Attemps_Counter__c >= 1)
   {
    tempOpp.StageName = '1 Call Made';
   }
   else
   {
    tempOpp.StageName = '0 Call Made';
   }
  }
}
 
return;
Hello, i need to modify the code of an existing trigger in our salesforce. the original trigger was coded by a firm we a no longer dealing with.

basically, the trigger automatically changes the stage of the opportunity depending on actions the sales rep are doing (calling, sending emails, receiving prospects in the sales office)

so here's the deal.

existing code :

if (e.Type != null && e.Type == 'Walk-In')
      walkin++;

id like to modify it so the walkin+++ occurs not only when there is a event named ''walk-in", but also for all those containing "Meeting".

the event type "walk-in" is for when a prospect visits a sales office unnanounced.  we added 1st meeting, 2nd meeting, 3rd meeting, 4th+ meeting as event types to log when the prospects visits after they have talked to a sales rep.

so i guess something like

If (e.Type !=null && (e.Type == ‘Walk-In’ || e.Type.contains(‘Meeting’))
Walkin++

??

thanks for the help, i'm new at apex development and it's a bit overwhelmong at first.

since i'm modifying an existing trigger, can i just change it in the dev console and save?

thank you!

Hello!  We are a real estate developer. We receive deposits from customers, and we track them with salesforce. I'd love an email alert to automatically fire a couple days before the deposit deadline to the corresponding contact.  I have no problems creating the time-based workflow rule, but i cant seem to be able to set the email update to be sent to the contact (there is only one in the account).  We manage deposits in a custom objects called ''deposits'' which is linked to assets.   Is it possible to do what i want to do?

 

thanks in advance,

Hello, i'm looking for help (my first trigger woohoo!) to do the following

 

after a sales rep calls a prospect (by logging a ''Call'' type task in opportunities), and the prospect says ''never call me again'', the reps select the ''do not call again'' call conclusion.

 

i'd like to make a trigger where when this is selected and saved, it would automatically update the ''do not call'' field in opps and in contact.

 

 

 

 

 

 

Hello!

I'm looking to create a trigger that will populate a picklist field from the asset name. Like If asset name starts with X, then set value Y. I tried with field updates but it won't fire until i save the record, and i need it to fire at the creation of the record (when i click on ''new case'')

the reason why i need a picklist auto populated is because i need it to control another picklist, and it won't work with a formula field.

can anyone help?

thanks!