• Azhar Aziz G
  • NEWBIE
  • 40 Points
  • Member since 2014


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 11
    Replies
if (selectedAccount == null && ApexPages.currentPage().getParameters().get('id') != null && ApexPages.currentPage().getParameters().get('id') !='') {
                ID accId = ApexPages.currentPage().getParameters().get('id');system.debug('>>accid'+accId );
                String strQuery = 'SELECT Id,Name,BillingStreet,Phone,BillingCity,BillingState,BillingPostalCode,BillingCountry,BIN__c FROM Account WHERE id='+ '\'' + accId +'\'';
                system.debug('>>strQuery'+strQuery);
                selectedAccount = Database.query(strQuery);
            }
I created a custom date field on the Account called Account_Last_Activity__c and I want to update it based on the last activity by specific Users. I then want to run a report based on the Last Activtiy and by whom. I got this far on my apex code and received an "unexpected toke" error. I have not been able to include the specific User IDs in the code either. Any help would be appreciated. Thank you!


rigger UpdateAccountLastActivityAccount on Task (after insert, after update) {
    Set<String> whatIds = new Set<String>();
    
    for (Task t : Trigger.new) {
        whatIds.add(t.WhatId);
    }
    
    List<Account> acct = [SELECT Id, Account_Last_Activity__c FROM Account WHERE Id =: whatIds];
    
    Map<String, Task> taskMap = new Map<String, Task>();
    
                }
        }   
    }
         
    for (Account a : acct) {
        if (taskMap.containsKey(a.Id)) {
            a.Account_Last_Activity__c = taskMap.get(a.Id).ActivityDate;
        }
    }
    update acct;
}
Attempt to de-reference a null object - Need Help with Trigger

Hi, 
I need help with a trigger. Someone please help me on what I am doing wrong. Thank you.
My scenario is - For a person Account - Address, City & Zip are filled.
When a Case is created for that Customer - Address, City & Zip should automatically be filled. So that Sales reps don't have to fill those 3 fields again.
Here is my CODE
trigger CasesTrigger on Case (after insert){
    Set<Id> accIds = new Set<Id>();
    List<Case> lstCases = new List<Case>();
    for(Case objCase:trigger.new){
        accIds.add(objCase.AccountId);
        system.debug('ACCOUNTIDS'+accIds);
    }
    Map<ID, Account> MapAccIdtoAccount = new Map<ID, Account>([Select Id, Street__c, City__c, State__c, Zip__c from Account where Id IN:accIds]);
system.debug('ACCOUNTSMAP'+MapAccIdtoAccount);
    for(Case objCase:Trigger.new){
        Case oCase = new Case();
       
    if(MapAccIdtoAccount.containsKey(objCase.AccountId))
{
         oCase.Address_Line1__c = MapAccIdtoAccount.get(oCase.AccountId).Street__c ;
            system.debug('ADDRESS---'+oCase.Address_Line1__c); 
           oCase.City__c = MapAccIdtoAccount.get(oCase.AccountId).City__c ;
            oCase.State__c = MapAccIdtoAccount.get(oCase.AccountId).State__c ;
           oCase.Zip__c = MapAccIdtoAccount.get(oCase.AccountId).Zip__c ;
        lstCases.add(oCase);
         system.debug('oCASE'+oCase); 
            }
            }
    if(lstCases.size()>0){
        update lstCases;
    }
}
  • September 23, 2015
  • Like
  • 0
I'm trying to modify this SOQL statement in an APEX class:

SELECT Id, Name FROM Inventory__c WHERE Status__c = 'Active' ORDER BY Name

to filter the resulting list by record types from a parent object.  Inventory__c object is the child in a Master-Detail Relationship with a parent Transaction custom object that has two record types the names of which match a field value [Team__c] on the the Inventory object.  So, I want the WHERE clause to include filter to accomplish this intent:

SELECT Id, Name FROM Inventory__c 
WHERE (Inventory__c.Status__c) = 'Active' AND
(Transaction__r.RecordTypeName = Inventory__c.Team__c)

ORDER BY Name

Which I have tried several variations of, none of which work, all of which return errors indicating confusion in trying to resolve the relationship.  [The simple SELECT from Inventory works fine.]

Any suggestions.
trigger TriggerAccountContacts on Account (after insert) {
list<contact> cons=new list<contact>();
    for(account a:trigger.new){
        contact c=new contact();
        c.lastname=a.name;
        c.Phone=a.phone;
        c.Description=a.description;
        c.AccountId=a.id; //what is accountid here is it record id of account object
        cons.add(c);
    }
    insert cons;
}
Here is my apex class.
public class myclass{
 
    
    public Opportunity o;
    String theId = ApexPages.currentPage().getParameters().get('id');
  
    
   @TestVisible public List<WrapperSObject> records {get; set;}
    public Contract con {get; set;}
    public String selectedValue {get; set;}
  
  public  myclass(ApexPages.StandardController stdController) {
        this.o = (Opportunity)stdController.getRecord();
    }
     
    public PageReference autoRun() {
 
        String theId = ApexPages.currentPage().getParameters().get('id');
         if (theId == null) {
            return null;
        }
    
records = new List<WrapperSObject>();
 for (Contract c : [select id, Name, AccountId, StartDate, Status, ContractNumber from Contract where Status='Activated'  ])
 {
 records.add(new WrapperSObject(c, getOptions(), 'Activated')); //this line is not getting covered
 }
     return null;
          
}
 public PageReference MainMethod() {
 
/// other code
    
        return null;        
  }


// To Update contracts 
 public PageReference back() {
       List<Contract> contractToBeUpdate = new List<Contract>();
    for(WrapperSObject wrapper : records){
        wrapper.con.status = wrapper.selectedValue;
        contractToBeUpdate.add(wrapper.con);
    }
    update contractToBeUpdate;
    PageReference pageRef ;    
     return pageRef= MainMethod();
  }
 


@TestVisible public class WrapperSObject {
public Contract con {get; set;}
 public List < SelectOption > options {get; set;}
        public String selectedValue {get; set;}
  
     
    public WrapperSObject( Contract c,List < SelectOption > options, String selectedValue) {
    con=c;
     this.options = options;
     this.selectedValue = selectedValue;
     }
  
  }

public List < SelectOption > getOptions() {
List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Activated','Activated'));
        options.add(new SelectOption('Expired','Expired'));
        options.add(new SelectOption('LAPSE','Lapse'));
        return options;
    }
  }

Here is my test class
@isTest
private class myclassTest {
    private static testMethod void testAutoRun() {

    
        Account acc = new Account(Name='Abce');
  insert acc;
 
  Opportunity  testOppty = new Opportunity();
  testOppty.name='testOppty';
  testOppty.AccountId=acc.id;
  testOppty.CloseDate=System.today();
  testOppty.StageName= 'Closed Won';
  testOppty.Type='EnerLead Renewal';
  testOppty.Description='Newly created Oppertunity';
  insert testOppty;
  
        insert odr;
                  Contract c = new Contract(
                ,StartDate=testOppty.CloseDate
                ,AccountId = testOppty.AccountId
                ,Name = testOppty.Name
                );
            insert c;
  
 List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Activated','Activated'));
        options.add(new SelectOption('Expired','Expired'));
        options.add(new SelectOption('LAPSE','Lapse'));
        
  
        
        test.startTest();
        
            PageReference pageRef = Page.myclass;
            Test.setCurrentPage(pageRef);
            
            pageRef.getParameters().put('id',testOppty.id);
            ApexPages.StandardController sc = new ApexPages.standardController(testOppty);
            
            myclass  controller = new myclass(sc);
            controller.autoRun();
            controller.back();
            controller.MainMethod();
            myclass.WrapperSObject psec = new myclass.WrapperSObject( con, options, 'Activated' );
        
       test.stopTest();
}
}

I am unable to cover the Selection getoption() method to increse code coverage. How to write unit test for selection method ?

records.add(new WrapperSObject(c, getOptions(), 'Activated')); //this line is also not getting covered
 
Hi,

I have a trigger which is firing on feed item which will capture the opp id and account id on posting a chatter posr on opportunity

the trigger is working fine and the update is correctly happening

my issue is when i type @user and post something , the user gets gradeout in black  where the email is not fired to respective users

whereas in other object it is highlighted in blue correclty

let me know whats the issue and how to handle it in my trigger

 
MY TRIGGER :

trigger FeedItemTrigger on FeedItem (before insert,before update) {
    
    set<id> parentAccountIds = new set<id>();

    for(FeedItem fdItem : trigger.new){
        String idStr = fdItem.Parentid;

        if(idStr.startsWith('006')){
           parentAccountIds.add(idStr);
        }
        
        
    }
    
   Map<id,Opportunity> oppty  = new Map<id,Opportunity>([Select id, AccountId  from Opportunity where id in:parentAccountIds]);
   if(oppty.size()>0){
    for(FeedItem fdItem : trigger.new){
        Opportunity parentopportunity = oppty.get(fdItem.Parentid);

        String chatterBody = fdItem.Body;
        
        fdItem.Body = chatterBody + '\n Account Id is :'+ parentopportunity.AccountId + ' \n Opportunity Id :'+parentopportunity.Id;
    }
	}

}

Kindly help me on this regard

Thanks in Advance

 
I deployed a trigger today, and it's running smoothly, but I forgot about a change I wanted to make to it in order to make it run more smoothly/avoid bugs. How do I actually remove an apex trigger from salesforce? Thanks
if (selectedAccount == null && ApexPages.currentPage().getParameters().get('id') != null && ApexPages.currentPage().getParameters().get('id') !='') {
                ID accId = ApexPages.currentPage().getParameters().get('id');system.debug('>>accid'+accId );
                String strQuery = 'SELECT Id,Name,BillingStreet,Phone,BillingCity,BillingState,BillingPostalCode,BillingCountry,BIN__c FROM Account WHERE id='+ '\'' + accId +'\'';
                system.debug('>>strQuery'+strQuery);
                selectedAccount = Database.query(strQuery);
            }
If interested, post your contact information here.

Must be able to be set up as a vendor and be paid by a US company.
Trying to write a test class for this controller extension which allows me to update an opportunity and case from a visualforce page:

public with sharing class controlOppty {
    public Case c;
    public Opportunity oppty;
    
    private ApexPages.StandardController stdController;

    public controlOppty(ApexPages.StandardController controller) {
        this.c= (Case)controller.getRecord();
        this.oppty= c.Opportunity_Name__r ;
        this.stdController= controller;
    }

    public PageReference saveRecord() {
        PageReference ret = stdController.save();
        system.assertNotEquals(null, c.Id);        
        update oppty;
        update c;
        
        return ret;
    }
 }

I've written this:

@isTest
private class TestControlOppty{

    static testMethod void TestControlOppty() {
        Opportunity testOpportunity = new Opportunity();
        testOpportunity.Name = 'Test Opportunity For Test user';
        testOpportunity.StageName = 'Quoted';
        testOpportunity.LeadSource = 'Referral';
        testOpportunity.OwnerId = UserInfo.getUserId();
        testOpportunity.CloseDate = System.today();
        testOpportunity.RecordTypeID = '01280000000BJpn';
        testOpportunity.Amount = Integer.valueOf(Math.random() * 1000);
        testOpportunity.Policy_Type__c = 'Home';
        testOpportunity.Policy_Type_Level_II__c = 'Home';
        testOpportunity.Proof_of_Alarm__c = true;
        testOpportunity.Proof_of_Prior__c = false;
        testOpportunity.Proof_of_Flood_Coverage__c = false;
        testOpportunity.Proof_of_Garaging_Address__c = true;
        testOpportunity.Proof_of_Home_Ownership__c = false;
        testOpportunity.Proof_of_Garaging_Address__c = false;
        testOpportunity.Proof_of_Health_Insurance__c = false;
        testOpportunity.Proof_of_New_Purchase__c = false;
        testOpportunity.Proof_of_Residency__c = false;
        testOpportunity.Proof_of_Wind_Coverage__c = false;
        testOpportunity.Good_Student_Discount__c = true;        
        testOpportunity.Defensive_Driving_Cert__c = true;
        testOpportunity.Appraisal_For_Scheduled_Property__c = true;
        testOpportunity.Roof_Certificate__c = true;
        testOpportunity.Bill_of_Sale__c = false;
        testOpportunity.X4_Point_Inspection__c = true;
        testOpportunity.Wind_Mitigation_Certificate__c = true;
        testOpportunity.Photos__c = false;
        testOpportunity.Other_Trailing_Doc__c = 'Document';
        insert testOpportunity;

        Test.startTest();

        Case c1 = new Case(Opportunity_Name__c = testOpportunity.Id, Subject = 'Test Case', Status = 'New', Due_Date__c = system.today(), Outcome__c = 'Document Received');
                insert c1;
        
        ApexPages.currentPage().getParameters().put('id',c1.id);
        ApexPages.StandardController sc = new ApexPages.StandardController(c1);
        ControlOppty conOpp = new ControlOppty(sc);
        
        update c1;
        update testOpportunity;

        List<Case> c = [SELECT Id FROM Case];
        System.assertEquals(c.size(),1);
        Test.stopTest();
    }
}

And have coverage for:

User-added image

Any help getting these lines covered is appreciated.

 
Hello everyone, 

i was searching one way of take selected fields to be used in next page. 
Ex.: pag1 has 3 fields, they will be selected by js and using some method keep these fields and send to the next pag2.

I can already select the fields, but i still dont know how change the page and keep the previously fields.
Unfortunately i cant use the flow because the user will select the field.

thanks in advance.