• Abhijeet Anand 6
  • NEWBIE
  • 95 Points
  • Member since 2016
  • Senior Salesforce Consultant
  • Deloitte Australia

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 41
    Replies
Hey guys I came across this trigger that says it will do just exactly what I needed it to do but with a few changes to do I've modified it so that a new custom object is created when the Opoortunity is won.

I'm running this in Sandbox and can't seem to figure out why the trigger isn't activating.

Basically:
I have a custom object Sponsorship and I want a new sponsor to be created when an Opportunity is won and the appropriate fields to be inserted as well.
trigger createSponsorOnOpportunityWon on Opportunity (after insert) {
    
    List <Sponsorship__c> sponsToInsert = new List <Sponsorship__c> ();
    // or whatever your custom object name put instead of Sponsorship__c
    
    for (Opportunity o : Trigger.new) {
        
        
        // here is where you check if opportunity that is being inserted
        //meets the criteria
        if (o.StageName == 'Closed Won'){
        
        Sponsorship__c s = new Sponsorship__c (); //instantiate the object to put values for future record
        
        // now map opportunity fields to new vehicle object that is being created with this opportunity
        
        s.Name = o.Name; // and so on so forth untill you map all the fields. 
        s.Sponsor_Account__c = o.AccountId;
        //once done, you need to add this new object to the list that would be later inserted. 
        //don't worry about the details for now
        
        sponsToInsert.add(s);
        
        
        }//end if
        
    }//end for o
    
    //once loop is done, you need to insert new records in SF
    // dml operations might cause an error, so you need to catch it with try/catch block.
    try {
        insert sponsToInsert; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
    
}

Right now it should just create the new object with the name and and account taken from the opportunity. But nothing happens. Any ideas?
Hello All,
 
  can any one help me with writting the bellow code 
1) by using Map
2) with best pracitces 

trigger UpdatePhone1 on contact (After insert) {
    list<account> acc= new list<account>();
    
    for(contact con:trigger.new)
    {
        account a= [select id, name,phone from account where id=: con.accountid];
        a.phone= con.phone;
        acc.add(a);
    }
    update acc;

}
Hello all.  I am VERY new to the development side of SF but have been doing admin for over 5 years.  I want to use Apex to edit a checkbox on the contacts object every day...it can run once daily or throughout the day if possible.  How do I accomplish this?  I assume I need to write an apex class but have no idea what the code should be.  Please help.
I have a specifc query I would like to export and I am a complete novice to SOQL syntax.

What I need is all instances of an object that does not have attached to them a PDF that follows the format [Name] & ‘.pdf’

Given the structure of these in salesforce, if I was to achieve this in SQL Server I would do the below:
SELECT
      Object.id
      Object.Name
FROM Object
LEFT JOIN
      (SELECT
            Attachments.ParentID
      FROM Attachments
      INNER JOIN Object ON
            Attachments.ParentID = Object.ID
      WHERE Attachments.Name = Object.Name + '.pdf') AS PDF ON
            PDF.ParentID = Object.id
WHERE PDF.ParentID is null

Is this possible through the data loader in any way?

Thanks
 
I am new to coding and saw this code to capture the date of the first Activity of a Lead. I keep on receving this issue "Varable does not exist: WhoID"

What do I need to do specifically to fix this?

Here is trigger:
trigger LeadResponseTrigger on Task (before insert, before update) {
    
    Set<Id> leadsToCheck = new Set<Id>();
    for(Task t : Trigger.new) {
        if(t.WhoId != null && String.valueOf(t.WhoId).startsWith('00Q') && t.Status != 'Completed' && t.ActivityDate <= Date.Today()) {
            leadsToCheck.add(t.WhoId);
        
    }

    List<Lead> leadsToUpdate = [Select Id, CreatedDate 
                                From Lead 
                                where ID in :leadsToCheck and First_Activity_Date__c = null AND CreatedDate > 2010-05-31T12:00:00Z ];
    for(Lead l : leadsToUpdate) {

        l.First_Activity_Date__c = System.now();
    }
    update leadsToUpdate;

    }
}
  • June 02, 2016
  • Like
  • 0
Hi Team,
I am getting error on bulk Lead import, "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:CheckLeadDNCR: System.LimitException: Apex CPU time limit exceeded:--".
I checked trigger CheckLeadDNCR, it is not inserting/updating any data its a normal if else and very short trigger. Then why this error is coming on this trigger
Hi SFDC Devs,

I am hoping someone here can help me. I have a set of custom objects to monitor inventory and quality control for my org. On the quality control (QC) record page, I have a custom button that executes some JS that updates all of the individual fields in that record to "Approve All" and thus pass that QC.

However, it is a hassle to have to click into each QC record to approve it, and would save our team some time if the record can be updated from the parent related list but clicking an action or link. I would like to ideally add an action next to delete or edit on the parent related list to "Approve All" that would update that record.

User-added image
I have tried creating an action but I don't think that is the right kind of action in this case. I know I can create a related list button that can execute apex to update all child records here, but I want to be able to specify which QC records get updated.

Can anyone point me in the right direction?

Thank you,
Brian
Example:

ABC Company
Jane Smith is contact, but i want to designate her as the signor, to later map her name onto a drawloop template on loan documents....

It would be ideal to do this also with gurantors 
I keep getting this error when I try to create an account after I hit save when done entering my information.  The only required field is the account name field and it is definitely not blank.  I've tried it in different browsers and I am still getting the same result.
Hi,

I'm new to salesforce. Can someone help me out with the test class for the below trigger:
trigger CheckDuplicateIrrs on IRR_s__c (before insert, before update) {
if ( CommonMessages.IRRTriggerFirstRun ) {
        CommonMessages.IRRTriggerFirstRun = false;
    List < String > samplenames = new List < String >();
    for (IRR_s__c s : trigger.new) {
        if ( String.isNotBlank(s.name) ) {
            if ( trigger.isInsert ) {
                samplenames.add('IRR' + '-' + '07' + '-' + s.IRR_Year__c.RIGHT(2) + '-' + String.valueOf(s.Sequential_Number__c).leftPad(4, '0')); 
            } else if ( trigger.isUpdate ) {
                if ( s.Sequential_Number__c != trigger.oldMap.get(s.Id).Sequential_Number__c || s.Name != trigger.oldMap.get(s.Id).Name ) {
                    samplenames.add('IRR' + '-' + '07' + '-' + s.IRR_Year__c.RIGHT(2) + '-' + String.valueOf(s.Sequential_Number__c).leftPad(4, '0')); 
                }
            }
        }
    }    
    
    if ( samplenames.size() > 0 ) {
        List < IRR_s__c > dupsamples =  [ SELECT Id, Name, Sequential_Number__c FROM IRR_s__c WHERE Name IN: samplenames ];
        if ( dupsamples.size() > 0 ) {
            Map < String, IRR_s__c > mapNameIRR = new Map < String, IRR_s__c >();
            for ( IRR_s__c IRR : dupsamples ) {
                mapNameIRR.put(IRR.Name, IRR);
            }
            
            for (IRR_s__c s : trigger.new) {
                if ( mapNameIRR.containsKey('IRR' + '-' + '07' + '-' + s.IRR_Year__c.RIGHT(2) + '-' + String.valueOf(s.Sequential_Number__c).leftPad(4, '0')) ) {
                    s.addError('This IRR already exists with same Name');
                }
            }
        }
    }  
   }

 
Hi all, 

I am experiencing issues with the “Lead Trigger” that has been developed for us. Our leads, coming in through Pardot, are being stuck in the que. I reached out to the SFDC supprt team and the told me the issue arises from the Lead Trigger. .

This is the error we are getting from Pardot: 

LeadTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.LeadTrigger: line 27, column 1 | CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

Any direction as how to fix this would be truly helpful.
 
For your reference,  here is the code of the LeadTrigger:
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
trigger LeadTrigger on Lead (before insert, before update) {
   Set<String> codeSet = NEW Set<String>();
   Map<String,String> regionMap = new Map<String,String> ();
   if(Trigger.isInsert){
       for(Lead LD :Trigger.new){
           if(LD.Phone <> NULL){
               String numericPhone = LD.Phone.replaceAll('[^0-9]', '');
               String areaCode = numericPhone.substring(0,3);
               codeSet.add(areaCode);
           }
       }
   }
   if(Trigger.isUpdate){
       for(Lead LD :Trigger.new){
           if(LD.Phone != Null && LD.Phone <> Trigger.oldMap.get(LD.id).Phone){
               String numericPhone = LD.Phone.replaceAll('[^0-9]', '');
               String areaCode = numericPhone.substring(0,3);
               codeSet.add(areaCode);
           }
       }
   }
   IF(!codeSet.isEmpty()){
       for(Region_Lookup__c ch:[select Name,Area_code__C from Region_Lookup__c where Area_code__C IN:codeSet]){
           regionMap.put(ch.Area_code__C,ch.Name);
       }
       for(Lead LD :Trigger.new){
           String numericPhone = LD.Phone.replaceAll('[^0-9]', '');
           String areaCode = numericPhone.substring(0,3);
           if(regionMap.containsKey(areaCode)){
               LD.Lead_Region__c = regionMap.get(areaCode);
               
           }
       }  
       
   }
}
 

Thank you in advance for your time.
 
@IsTest(SeeAllData=true)
public class FileUploaderTest
{
  @isTest static void testVerifySingleUser()
  {
     FileUploader fu = new FileUploader();
     fu.firstname = 'elias';
     fu.lastname = 'yanni';
     fu.useraddress = '1013 Young Cir';
     fu.usercity = 'Corona';
     fu.userstate = 'CA';
     fu.userpostalcode = '92881';
     test.startTest();
         Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
         HttpResponse res = CalloutClass.getInfoFromExternalService();
         test.stopTest();
        // Verify response received contains fake values
        String contentType = res.getHeader('Content-Type');
        System.assert(contentType == 'application/json');
        String actualValue = res.getBody();
        String expectedValue = '{"foo":"bar"}';
        System.assertEquals(actualValue, expectedValue);
        System.assertEquals(200, res.getStatusCode());
     
  }
  static testMethod void testVerifyAccurateAppendApi()
  {
     test.startTest();
      Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
      HttpResponse res = CalloutClass.getInfoFromExternalService();
        String contentType = res.getHeader('Content-Type');
        System.assert(contentType == 'application/json');
        String actualValue = res.getBody();
        String expectedValue = '{"foo":"bar"}';
        System.assertEquals(actualValue, expectedValue);
        System.assertEquals(200, res.getStatusCode());

     test.stopTest();

  }
  static testmethod void testfileupload(){
        Test.startTest();
        PageReference pageRef = Page.helloworldpage;
        Test.setCurrentPage(pageRef);
        Account ac=new Account();ac.Name='rakuten12345';
        insert ac;
        String resourceName = 'Csvfiles';
        Document document;

        
        
        Document lstDocument = [Select id,name,Body from Document where Name ='csvContacts' ];
        Blob content= lstDocument.Body;
        String myCSVFile = lstDocument.Body.toString();
        System.debug('myCSVFile = ' + myCSVFile);
        FileUploader file=new FileUploader();
        file.contentFile = content;
        file.ReadFile(); 
        file.getuploadedAccounts();
        //file.nameFiles=content.toString();
        String nameFiles= content.toString();
        String[] filelines = nameFiles.split('\n');
        
        for(Integer i=1;i<filelines.size();i++)
        {
        String[] inputvalues = new String[]{};
        inputvalues = filelines[i].split(',');
        
                        Contact a = new Contact();
                        a.FirstName  = 'elias';
                        a.LastName = 'yanni';
                        
                        a.MailingStreet = '301 street';
                        a.MailingCity = 'Corona';
                        a.MailingState = 'CA';
                        a.MailingCountry = 'US';
                        a.MailingPostalCode = 'B12123';
                        
                        accstoupload.add(a);                
             try{
                insert accstoupload;
                System.assertEquals(1,accstoupload.size());
                Test.stopTest();
            }
            catch (Exception e)
            {
                ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template');
                ApexPages.addMessage(errormsg);
            }
        }
  }
        
        
  
  static testMethod void testgetuploadedAccounts()
  {
        test.startTest();
         FileUploader fu = new FileUploader();
         fu.ReadFile();
        test.stopTest();          
  }

}
<apex:page>
 <apex:form >
   <apex:pageBlock title="Order Create/Edit">
      
       <apex:actionRegion >

          <apex:pageBlockSection title="Account Information">
         <apex:inputField value="{!order.AccountId}" id="exname">
            <apex:actionSupport event="onchange" action="{!AccountPopulated}"   oncomplete="grabExName();" rerender="accinfo, msgs"/> 
         </apex:inputField>
   
         <apex:outputField id="messageText" value="{!order.Account.Message__c}"/>
     <!--<apex:variable var="new" value="{!order.Account.Message__c}"/> -->
       
        </apex:pageBlockSection>


</apex:form>
<apex:page>
Hi,
I have pasted my code here. The problem i am facing is that the alert is not showing any value when the oncomplete event occurs.Pl help
 
Hi All,

I have a visual force page with the input field name "owner". I want to add an icon to this field and when ever it is clicked, I want to display a popup window with all the users who are available in the users object . Once the user name is selected from the popup then that user name should be populated into the input field which is available in visual force page. If there is any standard functionality, please let me know.

If there is no standard functionality then please send me the sample code to achive this requirment.

 
Hi all.

Im having issues getting my code coverage up to 75% for a Task Trigger.  Please see Trigger and Test Class below.  My APEX skills are very basic.  Any advice on how to boost my coverage is much appreciated.  Thanks in advance!!
trigger TaskTrigger on Task (before insert, before update) 
{
    List<Id> OppIds=new List<Id>();
    for(Task t:trigger.new)
    {
        if(t.Status=='Completed')
        {
            if(t.whatId != null && String.valueOf(t.whatId).startsWith('006')==TRUE) //check if the task is associated with an Opp
            {
                OppIds.add(t.whatId);
                //System.debug('In here:' + t.whatid);
            }//if 2
        }//if 1
    }//for
        
    map<id,Opportunity> OpptaskMap = new map<id,Opportunity>([SELECT Id, Situation__c, Forecast_Delivery_Start_Date__c, Forecast_Delivery_End_Date__c, Bypass_Validation_Rule__c, Problem__c, Implication__c, Need_Payoff__c , Involves_Active_Partners__c, Google_Drive_URL__c, StageName, (Select ID From OpportunityLineItems) FROM Opportunity WHERE Id IN :OppIds]);
    
    
    List<OpportunityContactRole> OCR = [select id from OpportunityContactRole where OpportunityId IN :oppIds];
    List<OpportunityPartner> OPartner = [select id from OpportunityPartner where OpportunityId in :oppIds];
       
    
    
    
    for(Task tsk:trigger.new)
    {   
      if(OpptaskMap.keyset().contains(tsk.whatid))
      {
            OpptaskMap.get(tsk.whatid).Bypass_Validation_Rule__c = TRUE;
      
            if(tsk.Status == 'Completed' && tsk.Subject == 'Communicate with Client')
            {
                OpptaskMap.get(tsk.whatid).StageName = '2-Identified';
                //System.debug('Communicate with Client:' + OpptaskMap.get(tsk.whatid).StageName);
            }
            
            Else if( tsk.Status == 'Completed' && tsk.Subject == 'Validate Opportunity')
            {
                If (OpptaskMap.get(tsk.whatid).Situation__c == Null ||  OpptaskMap.get(tsk.whatid).Problem__c == Null || OpptaskMap.get(tsk.whatid).Implication__c == Null || OpptaskMap.get(tsk.whatid).Need_Payoff__c == Null || OpptaskMap.get(tsk.whatid).Involves_Active_Partners__c == Null)
                {
                    tsk.adderror('Task cannot be completed until the following Opportunity fields have been populated: Situation, Problem, Implication, Need & PayOff, Involves Active Partners.');
                }
                Else
                {
                    OpptaskMap.get(tsk.whatid).StageName = '3-Validated';
                }
                    
            }
            
          //  System.debug('1 condition:' + LeadtaskMap.get(tsk.whatid).Description == NULL);
          //  System.debug('2 condition:' + tsk.Status == 'Completed');
          //  System.debug('3 condition:' + tsk.Subject == 'Make contact with Lead');
          //  System.debug('task:' + tsk);
            
            Else if(tsk.Status == 'Completed' && tsk.Subject == 'Qualify Opportunity and Identify Contact Roles')
            {
                If(OpptaskMap.get(tsk.whatid).Forecast_Delivery_Start_Date__c==Null || OpptaskMap.get(tsk.whatid).Forecast_Delivery_End_Date__c==Null)
                {
                     tsk.adderror('Please add the Forecast Delivery Start and End Dates to the "Delivery Details" section of the Opportunity');
                }
                
                If(OpptaskMap.get(tsk.whatid).Involves_Active_Partners__c == 'Yes') 
                { 
                    If (OpptaskMap.get(tsk.whatid).OpportunityLineItems.isEmpty() || OCR.size()==0 || OPartner.size()==0) 
                    {
                        tsk.adderror('Task cannot be completed until Contact Roles, Products AND Partners have been added to the Opportunity');
                    
                    }
                    Else
                    {
                        OpptaskMap.get(tsk.whatid).StageName = '4-Qualified';
                    }
                }
                Else If(OpptaskMap.get(tsk.whatid).Involves_Active_Partners__c == 'No')
                {
                    If (OpptaskMap.get(tsk.whatid).OpportunityLineItems.isEmpty() || OCR.size()==0) 
                    {
                        tsk.adderror('Task cannot be completed until Contact Roles AND Products have been added to the Opportunity');
                    
                    }
                    Else
                    {
                        OpptaskMap.get(tsk.whatid).StageName = '4-Qualified';
                    }
                
                }
                Else
                {
                    //OpptaskMap.get(tsk.whatid).StageName = '4-Qualified';
                }
            }
            
            Else if(tsk.Status == 'Completed' && tsk.Subject == 'Create quote and submit for approval')
            {
                If(OpptaskMap.get(tsk.whatid).Google_Drive_URL__c==Null)
                {
                        tsk.adderror('Task cannot be completed until associated Google Drive URL has been added to the Opportunity');
                    
                }
                Else
                {
                    OpptaskMap.get(tsk.whatid).StageName = '5-Proposal';
                }
            }
            
            Else if(tsk.Status == 'Completed' && tsk.Subject == 'Proposal Outcome')
            {
                If (tsk.Proposal_Outcome__c == 'Commercial Agreement')
                {
                    OpptaskMap.get(tsk.whatid).StageName = '6-Commercial Agreement';
                }
                Else If (tsk.Proposal_Outcome__c == 'Lost')
                {
                    If (tsk.Loss_Abandonment_Reason__c == Null)
                    {
                        tsk.adderror('Please enter a reason for Loss / Abandonment');
                    }
                    Else
                    {
                        OpptaskMap.get(tsk.whatid).StageName = '9-Lost';
                        OpptaskMap.get(tsk.whatid).Opportunity_Loss_Abandoned_Reason__c = tsk.Loss_Abandonment_Reason__c;
                        OpptaskMap.get(tsk.whatid).Opp_Other_Loss_Abandonment_Comments__c = tsk.Other_Loss_Abandonment_Comments__c;
                    }
                }
                Else
                {
                    If (tsk.Loss_Abandonment_Reason__c == Null)
                    {
                        tsk.adderror('Please enter a reason for Loss / Abandonment');
                    }
                    Else
                    {
                        OpptaskMap.get(tsk.whatid).StageName = '8-Abandoned';
                        OpptaskMap.get(tsk.whatid).Opportunity_Loss_Abandoned_Reason__c = tsk.Loss_Abandonment_Reason__c;
                        OpptaskMap.get(tsk.whatid).Opp_Other_Loss_Abandonment_Comments__c = tsk.Other_Loss_Abandonment_Comments__c;
                    }
                }
            }
            
            Else if(tsk.Status == 'Completed' && tsk.Subject == 'Opportunity Outcome')
            {
                If (tsk.Opportunity_Outcome__c == 'Won')
                {
                    OpptaskMap.get(tsk.whatid).StageName = '7-Won';
                }
                Else If (tsk.Opportunity_Outcome__c == 'Lost')
                {
                    If (tsk.Loss_Abandonment_Reason__c == Null)
                    {
                        tsk.adderror('Please enter a reason for Loss / Abandonment');
                    }
                    Else
                    {
                        OpptaskMap.get(tsk.whatid).StageName = '9-Lost';
                        OpptaskMap.get(tsk.whatid).Opportunity_Loss_Abandoned_Reason__c = tsk.Loss_Abandonment_Reason__c;
                        OpptaskMap.get(tsk.whatid).Opp_Other_Loss_Abandonment_Comments__c = tsk.Other_Loss_Abandonment_Comments__c;
                    }
                }
                Else
                {
                    If (tsk.Loss_Abandonment_Reason__c == Null)
                    {
                        tsk.adderror('Please enter a reason for Loss / Abandonment');
                    }
                    Else
                    {
                        OpptaskMap.get(tsk.whatid).StageName = '8-Abandoned';
                        OpptaskMap.get(tsk.whatid).Opportunity_Loss_Abandoned_Reason__c = tsk.Loss_Abandonment_Reason__c;
                        OpptaskMap.get(tsk.whatid).Opp_Other_Loss_Abandonment_Comments__c = tsk.Other_Loss_Abandonment_Comments__c;
                    }
                }
            }
            
            Else 
            {
                //OpptaskMap.get(tsk.whatid).StageName = '7-Won';
            }
      }
    } 
    
    List<Opportunity> OppList = OpptaskMap.values(); 
      update OppList;
      }
Hey guys I came across this trigger that says it will do just exactly what I needed it to do but with a few changes to do I've modified it so that a new custom object is created when the Opoortunity is won.

I'm running this in Sandbox and can't seem to figure out why the trigger isn't activating.

Basically:
I have a custom object Sponsorship and I want a new sponsor to be created when an Opportunity is won and the appropriate fields to be inserted as well.
trigger createSponsorOnOpportunityWon on Opportunity (after insert) {
    
    List <Sponsorship__c> sponsToInsert = new List <Sponsorship__c> ();
    // or whatever your custom object name put instead of Sponsorship__c
    
    for (Opportunity o : Trigger.new) {
        
        
        // here is where you check if opportunity that is being inserted
        //meets the criteria
        if (o.StageName == 'Closed Won'){
        
        Sponsorship__c s = new Sponsorship__c (); //instantiate the object to put values for future record
        
        // now map opportunity fields to new vehicle object that is being created with this opportunity
        
        s.Name = o.Name; // and so on so forth untill you map all the fields. 
        s.Sponsor_Account__c = o.AccountId;
        //once done, you need to add this new object to the list that would be later inserted. 
        //don't worry about the details for now
        
        sponsToInsert.add(s);
        
        
        }//end if
        
    }//end for o
    
    //once loop is done, you need to insert new records in SF
    // dml operations might cause an error, so you need to catch it with try/catch block.
    try {
        insert sponsToInsert; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
    
}

Right now it should just create the new object with the name and and account taken from the opportunity. But nothing happens. Any ideas?
can we have extensions in custom controllers?
Can anybody help me to write a javascript to check "if the field is blank in a visualforce page" and show the error messages below the field itself? I am new to javascript and not knowing how to write the JS code. Thank you.
Hello all.  I am VERY new to the development side of SF but have been doing admin for over 5 years.  I want to use Apex to edit a checkbox on the contacts object every day...it can run once daily or throughout the day if possible.  How do I accomplish this?  I assume I need to write an apex class but have no idea what the code should be.  Please help.