• Vishnu7700
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 28
    Questions
  • 52
    Replies
Hi,
While checking the product duplicate i'm faceing Apex CPU Time out limit Exception.Here is the code
public list<BD_Identifier__c> LegacyproductBDlistinputcheck(list<BD_Identifier__c> bdlist)//bdllist contains list of products
    {
        set<string> dupcodeinput = new set<string>();
        system.debug('Class duplicate count:'+bdlist.size());//Size was 456 records
        for(BD_Identifier__c b: bdlist)
        {
            system.debug('Class duplicate:'+dupcodeinput.size());
            if (dupcodeinput.size()>0)
            {
                while (dupcodeinput.contains(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c))//After processing 64 records time out error was shown
                {
                    
                    if(b.SPM_BrokerDealer__c=='FSC')
                    {
                        string code =b.SPM_Legacy_Product_Code__c.right(1);
                        string productcode= b.SPM_Legacy_Product_Code__c;
                        if(code.isNumeric())
                        {
                            Integer i;
                            if(b.SPM_Legacy_Product_Code__c.right(2).isNumeric())
                            {
                                string s=b.SPM_Legacy_Product_Code__c.right(2);
                                Integer c,d;
                                c=Integer.valueOf(s.right(1));
                                d=Integer.valueOf(s.left(1));
                                if(d==c-1){
                                    code=b.SPM_Legacy_Product_Code__c.right(1); 
                                }
                                else{code=b.SPM_Legacy_Product_Code__c.right(2);}
                            }
                            i=Integer.valueOf(code)+1;
                            b.SPM_Legacy_Product_Code__c=((productcode+String.valueOf(i)).right(7));
                        }
                        else
                        {
                            b.SPM_Legacy_Product_Code__c=((productcode+String.valueOf(1)).right(7));
                        }
                    }
                    else if (b.SPM_BrokerDealer__c=='RAA' || b.SPM_BrokerDealer__c=='SPF' || b.SPM_BrokerDealer__c=='WFS')
                    {
                        string code =b.SPM_Legacy_Product_Code__c.right(1);
                        string productcode= b.SPM_Legacy_Product_Code__c;
                        if(code.isNumeric())
                        {
                            Integer i;
                            if(b.SPM_Legacy_Product_Code__c.right(2).isNumeric())
                            {
                                string s=b.SPM_Legacy_Product_Code__c.right(2);
                                integer c,d;
                                c=Integer.valueOf(s.right(1));
                                d=Integer.valueOf(s.left(1));
                                if(d==c-1){
                                    code=b.SPM_Legacy_Product_Code__c.right(1); 
                                }
                                else{code=b.SPM_Legacy_Product_Code__c.right(2);}
                            }
                            i=Integer.valueOf(code)+1;
                            b.SPM_Legacy_Product_Code__c=(b.SPM_Legacy_Sponsor_Code__c +(productcode+String.valueOf(i)).right(6));
                        }
                        else
                        {
                            b.SPM_Legacy_Product_Code__c=(b.SPM_Legacy_Sponsor_Code__c +(productcode+String.valueOf(1)).right(6));
                        }
                    }
                }
                dupcodeinput.add(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c);
            }
            else {dupcodeinput.add(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c);}
        }
        //system.debug('class remove duplicate'+bdlist);
        return bdlist;
    }
Hi All,
Very goodmorning  to all.....here i'm sharing few thoughts on salesforce1 which is next generation mobile app from salesforce.Couple of days back when i started working on salesforce1 i really existed with new features avalaible and now salesforce.com is updating contuniousely related to salesforce1.
I'm haveing a scenario like want to customizie the standard details page with custom page of account object along with Compact pagelayouts,Extended Lookups,RElated list and Mobile cards.
Can any one through light on solutions so that it will be great help for me and at same time want to continue this discussion futher more with all u r support...........

Hi,

Is there any way to get list of all object and feild API names in org.

 

Ideas are appricated.....

Hi All,

I'm haveing scenario like Custom button on opportunity details page.Once we click on the buttom need to validate opportunity stage as prospecting if not error should throws on detils page if yes create a new contract with prepopulated info on the contract and contract information should show on detail page.

 

Wating for help.

Hi can any one help me out to get test coverage for .addError and .add statments

Below is the trigger and test calss.

Bold line are not covered with the existing test class.

trigger Erroriftwoopportunityareopen on Opportunity (before insert) {

 

    Set <id> setAccWithProspectingOpp = new Set <Id>();//Varaible to hold Account with Prospecting opp

    Set <id> setAccId = new Set <Id>();//Varaible to hold Account IDs

   

    if(trigger.isbefore){

        if(trigger.isinsert){

            //Iterate through opportunity

            for(Opportunity o:Trigger.new){

                //System.debug('Account Id -->'+o.Accountid);

                //Verify account id not null and opportunity stagename is Prospecting

                if(o.Accountid != Null && o.StageName == 'Prospecting'){

                    setAccId.add(o.Accountid);//Account is added to setAccId(Varaible)

                }

            }

            //System.debug('Set of accounts -->'+setAccId);

            //Fetch the accounitid of opportunity from aetAccId(Varaible)

            for(Opportunity Opp : [Select id,accountid from opportunity where accountid in :setAccId]){

                setAccWithProspectingOpp.add(Opp.accountid);//Add opportunity account id in setAccWithProspectingOpp(Variable)

            }

            //System.debug('Set of accounts with Prosp Opp-->'+setAccWithProspectingOpp);

            //Iterate through opportunity object

            for(Opportunity o:Trigger.new){

                //Chack condition that in setAccWithProspectingOpp(Varaible)contains opportunity account id

                if(setAccWithProspectingOpp.contains(o.accountid))

                    o.addError('This account already has Opportunity with StageName as Prospecting');  

            }

           

        }

    }

}

Test class

@isTest

    public class ErroriftwoopportunityareopenTest{

        static testMethod void Test(){

        User thisUser = [ Select Id from User where Id = :UserInfo.getUserId() ];

        Account acc = new Account(Name = 'TestAccount',Rating = 'Hot',Type = 'Prospect');

            //update acc;

        Opportunity opp = new Opportunity(Name = 'TestOpp',Accountid = acc.Id,CloseDate = Date.Today(),StageName = 'Prospecting');

            //update opp;

        Opportunity opp1 = new Opportunity(Name = 'TestOpp1',Accountid = acc.Id,CloseDate = Date.Today(),StageName = 'ClosedWon');

            //update opp1;

        Opportunity opp2 = new Opportunity(Name = 'TestOpp2',Accountid = acc.Id,CloseDate = Date.Today(),StageName = 'ClosedLost');

            //update opp2;

        Task t = new Task(WhatId=acc.Id,WhoId = opp.Id,Subject = 'Email',Status = 'Completed', Priority ='Normal');

            insert t;

        Test.startTest();

            insert acc;

            insert opp;

            insert opp1;

            insert opp2;

             User someOtherUser = [Select Id From User Where Id != :UserInfo.getUserId() And isActive = TRUE LIMIT 1];

    system.runAs(someOtherUser){

          insert opp;

     }

        Test.StopTest();

        }

    }

Hi,

I'm haveing requriment like : There are two accounts A1 and A2,A1 having one open opportunity and A2 having one open opportunity when I try to merge A1 and A2 error should throws

 

for this i need to write trigger to merge account with conditions with custom button.

Hi,

My requriment is to write trigger for scenario Admin wants parent case cant be closed until all child cases are closed.

 

Below is my code

trigger Casecannotcloseifchildcsaeisopen on Case (before insert) {

List<Case> lstcase = new List<Case>();
Set<String> setcase = new Set<String>();

for(Case c : Trigger.new){
if(c.Status == 'Closed'){
setcase.add(c.Id);
}
}

lstcase = [Select Id from Case where id in:setcase];
Case childcase = new Case();
if(setcase.size()>0){
childcase.adderror('Can not delete case if child csae is open');
}
}

 Can any one help out.

 

What is ervice cloud console and mini page console?

What is purpose of Trigger factory and where can we use this?

I had tried with logic as below can any one help to correct the logic.

Code

 

List<Opportunity> opplist = [Select id from opportunity where StageName =:'Prospecting' and StageName =:'Closed Lost' Limit 2];

List<Task> listtask = [Select id,whatId from Task where Id IN :opplist.Id];

if(trigger.isupdate||trigger.isdelete){

if(Task task : Trigger.old)

 if(o.StageName == 'ClosedLost'){
            task.Status == 'Completed';
            listtask.add(task);
            }

      update listtask;

}

Hi,

Can any one pls provide idea how to achive this triggers it will be greate help for me.

1.Write a trigger to check only one opportunity is in open status of all the opportunity

2.Write a trigger once opportunity is closed only Admin can delete or  update the opportunity

 

Waiting for nay help pls.

 

Hi,

Need to assign contacts of one account to another account in  VF.

In above requriment i can able to display list contacts for assicoated account in VF page but unable to add selected contact of one account ot another account.

Any help is highly appricated.

 

Regards,

Vishnu.

Hi

Need help to get test coverage for custom controller calss.

when i tried it is covering on 29%

Controller class

public with sharing class MassUpdateFldSelected {
 //Variables
 Public List<AccountWrapper> AccountWrapList{get;set;}
 Public string inptstring{get;set;}
 Public string Selectedfield{get;set;}
 Public List<string> fieldsfromfieldset{get;set;}
   
 //Construct Class
 public MassUpdateFldSelected(ApexPages.StandardController controller) {
  fieldsfromfieldset = new List<string>();
 }
  
   Public List<AccountWrapper> getwrapperObj(){
 AccountWrapList = New List<AccountWrapper>();
    List<Account> accList = [Select id,name,Phone,BillingCity,Website from account limit 20];
  for(Account acc: accList){
   AccountWrapList.add(New AccountWrapper(acc,false));
  }
      return AccountWrapList;//AccountWrapList
    }
  
   public List<SelectOption> getfieldsfromfs() {
  List<SelectOption> fieldssets= new List<SelectOption>();
   for(Schema.FieldSetMember fld :SObjectType.account.FieldSets.AccountFeilds.getFields()) {    
                fieldssets.add(new SelectOption(fld.getFieldPath(),fld.getFieldPath()));
            }       
               return fieldssets;
    }

   //Method to updated records for selected fields from picklist
   Public void updateSelectedRecords(){
  List<Account> accountList = New List<Account>();    
   for(AccountWrapper wr: AccountWrapList){        
    if(wr.checkBox == true ){           
     wr.accObj.put(selectedField,inptstring);        
    }            
    accountList.add(wr.accObj);    
   }    
  Update accountList;
   }
   //Method to Delete the selected records
   Public void deleteRecords(){
  List<Account> accToDelList = New List<Account>();    
   for(AccountWrapper wr: AccountWrapList){        
    if(wr.checkBox == true ){
     accToDelList.add(wr.accObj);         
             }            
   }    
  delete accToDelList;
    }
   
    public pagereference BackToHomeBtnClick(){
        pagereference homepage = new pagereference('/home/home.jsp');
        homepage.setredirect(true);
        return homepage ;
    } 
    //Account Wrapper calss
    Public Class AccountWrapper{
    Public Account accObj{get;set;}
    Public Boolean checkBox{get;set;}
   
     Public AccountWrapper(Account accRec, boolean SelectBox){
        accObj = accRec;
        checkBox = SelectBox;
     }
   }
}

Test class

@isTest
public class MassUpdateFldSelectedTest{   
static testMethod void test(){       
account a1 = new account(name='abc test',BillingState = 'UK',Phone = '96589658',Website = 'www.abc.com');       
insert a1;

MassUpdateFldSelected massupdt = new MassUpdateFldSelected();
massupdt.updateSelectedRecords();
massupdt.deleteRecords();
massupdt.BackToHomeBtnClick();

//AccountWrapper accwr = new AccountWrapper();
}
}

 

Can any one pls help out it's very urgent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Hi,

I'm trying to create a VF page to mass update the account.Created VF page and on controller i'm trying to put logic with wrapper class concept,but i'm getting error as  Constructor not defined: [massEditComponentController.AccountWrapper].<Constructor>(SOBJECT:Account) at line 36 column 25

Even though i defined the constructor for wrapper calss.Can any one help out how to resolve this issue.

VF code:

<apex:pageBlockTable value="{!Accountrecords}" var="recwrap" id="records">

Controller:

public class massEditComponentController {
    public List<Account> Accountrecords{get;set;}    
    public List<Account> accountslist{get;set;}
    public List<AccountWrapper> AccountWrapList{get;set;}
    public string fileItems{get;set;}
    public string inputVal {get;set;}
    public string selectedField{get;set;}
    Public List<string> AccountfieldList{get;set;}
   
    //Constuct class
    public massEditComponentController(){
     AccountWrapList = New List<AccountWrapper>();        
     }
   
    public List<SelectOption> getfileItems(){
    List<SelectOption> options = new List<SelectOption>();
    for(string st:AccountfieldList)
    options.add(new SelectOption(st,st));
    return options;
    }
   
    public PageReference deleteRecords() {
    List<Account> accToDel = new List<Account>();
    /*for(accountslist wrp : AccountWrapList){
    //Check if record is selected
    if(wrp.isSelected){
    accToDel.add(wrp.myaccount);
     }
      }*/
        return null;
    }
    //Method to query accounts record and populate in wrapper
    public List<AccountWrapper> gerAccountrecords(){
    AccountWrapList.clear();   
    for (Account acc:accountslist)
    AccountWrapList.add(New AccountWrapper (acc));
    return AccountWrapList;       
    }
    public PageReference updateSelectedRecords() {
        return null;
    }
    public pagereference BackToHomeBtnClick(){
        pagereference homepage = new pagereference('/home/home.jsp');
        homepage.setredirect(true);
        return homepage ;
    }
     //WrapperCLass
      public class AccountWrapper{
        public boolean isSelected{get;set;}
        public Account myaccount{get;set;}  
        public boolean checkBox{get;set;} 
              //Constructor
        public AccountWrapper(Account myaccount,Boolean isSelected,Boolean checkBox){
          this.myaccount = myaccount;

          }
}


      }

Error was created on the line marked in red.

 

 

Hi,

I'm trying to trigger to 'Create a new contract once the opportunity reachs the Stagename = Closed/won'

Tried with logic as below but it throws complie errors as Initial term of field expression must be a concrete SObject: LIST<Contract> at line 7

 

trigger CreatecontractonOppstageclosewon on Opportunity (after insert , after update) {
Set<Id> accId = new Set<Id>();
List<Opportunity> opplist = new List<Opportunity>();
List<contract> conrtlist = new List<contract>();
for(Opportunity opp : Trigger.old){
if(opp.StageName == 'Closed/Won'){
conrtlist.Account = 'accid.name';
conrtlist.Status = 'Draft';
conrtlist.StartDate = Today();
conrtlist.ContractTerm = '6';
opp.add(conrtlist);
}
update opp;
}
}

 

Can any one please correct me where i'm worng?

 

Thanks & Regards

Hi,

I had trigger on account to update accountowner on realted list once changed.

Trigger

trigger reassignRelatedContactsnActivitesnOpportunities on Account (after update , after insert) {
 
      Set<Id> accountIds = new Set<Id>(); //set for holding the Ids of all Accounts that have been assigned to new Owners
      Map<Id, String> oldOwnerIds = new Map<Id, String>(); //map for holding the old account ownerId
      Map<Id, String> newOwnerIds = new Map<Id, String>(); //map for holding the new account ownerId
      Contact[] contactUpdates = new Contact[0]; //Contact sObject to hold OwnerId updates
      Opportunity[] opportunityUpdates = new Opportunity[0]; //Opportunity sObject to hold OwnerId updates
      Task[] taskUpdates = new Task[0]; //Task sObject to hold updates
      Event[] eventUpdates = new Event[0]; //Event sObject to hold updates
     
      for (Account a : Trigger.new) { //for all records
         if (a.OwnerId != Trigger.oldMap.get(a.Id).OwnerId) {
            oldOwnerIds.put(a.Id, Trigger.oldMap.get(a.Id).OwnerId); //put the old OwnerId value in a map
            newOwnerIds.put(a.Id, a.OwnerId); //put the new OwnerId value in a map
            accountIds.add(a.Id); //add the Account Id to the set
         }
      }
     
      if (!accountIds.isEmpty()) { //if the accountIds Set is not empty
         for (Account act : [SELECT Id, (SELECT Id, OwnerId FROM Contacts), (SELECT Id, OwnerId FROM Tasks),(SELECT Id, OwnerId FROM Events),(SELECT Id, OwnerId FROM Opportunities WHERE IsClosed = False) FROM Account WHERE Id in :accountIds]) { //SOQL to get Contacts Tasks , Events and Opportunities for updated Accounts
            String newOwnerId = newOwnerIds.get(act.Id); //get the new OwnerId value for the account
            String oldOwnerId = oldOwnerIds.get(act.Id); //get the old OwnerId value for the account
            for (Contact c : act.Contacts) { //for all contacts
               if (c.OwnerId == oldOwnerId) { //if the contact is assigned to the old account Owner
                  Contact updatedContact = new Contact(Id = c.Id, OwnerId = newOwnerId); //create a new Contact sObject
                  contactUpdates.add(updatedContact); //add the contact to our List of updates
               }
            }
            for (Task t : act.Tasks) { //for all tasks
                if(t.OwnerId == oldOwnerId){ //if the task is assigned to the old account owner
                    Task updatedTask = new Task(Id = t.Id, OwnerId = newOwnerId); //create a new Task sObject
                    taskUpdates.add(updatedTask); //add the task to our List of updates
                }
            }
            for (Event e : act.Events){//for all Events
                if(e.OwnerId ==oldOwnerId){ //if the event is assigned to the old account Owner
                    Event updatedEvent = new Event(Id= e.Id, OwnerId = newOwnerId); //create a new Event sObject
                    eventUpdates.add(updatedEvent); //add the event to our List of Updates
                }
            }
            for (Opportunity o : act.Opportunities) { //for all opportunities
               if (o.OwnerId == oldOwnerId) { //if the opportunity is assigned to the old account Owner
                  Opportunity updatedOpportunity = new Opportunity(Id = o.Id, OwnerId = newOwnerId); //create a new Opportunity sObject
                  opportunityUpdates.add(updatedOpportunity); //add the opportunity to our List of updates
               }
            }
         }
         update contactUpdates; //update the Contacts
         update taskUpdates; //update the Tasks
         update eventUpdates; //update the Events
         update opportunityUpdates; //update the Opportunities
      }
   
}

 

Test Method (25%):

@isTest
 public class reassignRelatedContactsAndOppTest{
   static testMethod void test(){
   User thisUser = [ Select Id from User where Id = :UserInfo.getUserId() ]; 
   
   Account acc = new Account(name='abc test',BillingState = 'UK',Phone = '96589658',Website = 'www.abc.com');
   insert acc;
   
   Contact con = new Contact(lastname = 'abctest',OwnerId = acc.Id, Phone = '89563254');
   insert con;
   //reassignRelatedContactsAndOpp rrco = new reassignRelatedContactsAndOpp();
   }
 }

Any help is highly appricated.

 

Regards,

 

Hi,

when the owner of account is changed the realted list objects owner neeed to be changed.

Related objects like contact/opportunity/event/task/contract.

 

Can any help me out how to frame the logic to achive this funcationality.

 

Any help is highly appriciated.

 

Regards,

Vishnu.

Hi,

Can any one help me to get codecoverage for leadconvert trigger

trigger ConvertLead on Lead (after insert , after update) {
    Integer Count = 0;
     //Array that stores all leads to convert
     Database.LeadConvert[] leadConvertarray = new Database.LeadConvert[trigger.new.size()];
        for(lead lea : Trigger.new){
            if(lea.LeadSource == 'Other' && lea.rating == 'Hot'){
                //Create new instance for variable
                Database.LeadConvert convrLead = new Database.LeadConvert();
                convrLead.setLeadId(lea.id);
                convrLead.setConvertedStatus('Closed - Converted');
                convrLead.setDoNotCreateOpportunity(False);
                leadConvertarray[Count]=convrLead;
                Count++;
                //System.debug('@@@@@@@@@Count'+ Count);
            }
        }
        //Array store actual count of lead converstion
        Database.LeadConvertResult[] LeaConvResults = Database.convertLead(leadConvertarray,false);
        //System.debug('@@@@@@@@@LeaConvResults'+ LeaConvResults);
    }

Hi,

Can any help to resolve the error.

Trigger is to convert to account,contact and opportunity once lead is created or updated

Code:

       trigger leadtoaccnconandopp on Lead (after Insert, after Update) {
        List<Lead> leadlist = new List<Lead>(); 
        List<Account> acclist = new List<Account>();
        List<Opportunity> opplist = new List<Opportunity>();
            if(Trigger.isInsert && Trigger.isUpdate){ 
                   for(Lead le:Trigger.new){     
                        if(le.IsConverted){
                               acclist.name = leadlist.name;
                               opplist.name = acclist.name;
                               opplist.CloseDate = Date.Today();             
                        }     
                        update opplist;       
                        update acclist;      
                    }    
                }  
            }

Hi Team,

I'm new to apex pls help me.

Can any tell me how achive the below requriment.Tried but unable to process selected records.

 

Develop a grid of records which can be selected. Once selected and the “Show SelectedRecords” button is clicked, information from the selected records is displayed in the “Selected Records” table.

 

Help is appricated.

 

Regards,

Vishnu

Hi,
While checking the product duplicate i'm faceing Apex CPU Time out limit Exception.Here is the code
public list<BD_Identifier__c> LegacyproductBDlistinputcheck(list<BD_Identifier__c> bdlist)//bdllist contains list of products
    {
        set<string> dupcodeinput = new set<string>();
        system.debug('Class duplicate count:'+bdlist.size());//Size was 456 records
        for(BD_Identifier__c b: bdlist)
        {
            system.debug('Class duplicate:'+dupcodeinput.size());
            if (dupcodeinput.size()>0)
            {
                while (dupcodeinput.contains(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c))//After processing 64 records time out error was shown
                {
                    
                    if(b.SPM_BrokerDealer__c=='FSC')
                    {
                        string code =b.SPM_Legacy_Product_Code__c.right(1);
                        string productcode= b.SPM_Legacy_Product_Code__c;
                        if(code.isNumeric())
                        {
                            Integer i;
                            if(b.SPM_Legacy_Product_Code__c.right(2).isNumeric())
                            {
                                string s=b.SPM_Legacy_Product_Code__c.right(2);
                                Integer c,d;
                                c=Integer.valueOf(s.right(1));
                                d=Integer.valueOf(s.left(1));
                                if(d==c-1){
                                    code=b.SPM_Legacy_Product_Code__c.right(1); 
                                }
                                else{code=b.SPM_Legacy_Product_Code__c.right(2);}
                            }
                            i=Integer.valueOf(code)+1;
                            b.SPM_Legacy_Product_Code__c=((productcode+String.valueOf(i)).right(7));
                        }
                        else
                        {
                            b.SPM_Legacy_Product_Code__c=((productcode+String.valueOf(1)).right(7));
                        }
                    }
                    else if (b.SPM_BrokerDealer__c=='RAA' || b.SPM_BrokerDealer__c=='SPF' || b.SPM_BrokerDealer__c=='WFS')
                    {
                        string code =b.SPM_Legacy_Product_Code__c.right(1);
                        string productcode= b.SPM_Legacy_Product_Code__c;
                        if(code.isNumeric())
                        {
                            Integer i;
                            if(b.SPM_Legacy_Product_Code__c.right(2).isNumeric())
                            {
                                string s=b.SPM_Legacy_Product_Code__c.right(2);
                                integer c,d;
                                c=Integer.valueOf(s.right(1));
                                d=Integer.valueOf(s.left(1));
                                if(d==c-1){
                                    code=b.SPM_Legacy_Product_Code__c.right(1); 
                                }
                                else{code=b.SPM_Legacy_Product_Code__c.right(2);}
                            }
                            i=Integer.valueOf(code)+1;
                            b.SPM_Legacy_Product_Code__c=(b.SPM_Legacy_Sponsor_Code__c +(productcode+String.valueOf(i)).right(6));
                        }
                        else
                        {
                            b.SPM_Legacy_Product_Code__c=(b.SPM_Legacy_Sponsor_Code__c +(productcode+String.valueOf(1)).right(6));
                        }
                    }
                }
                dupcodeinput.add(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c);
            }
            else {dupcodeinput.add(b.SPM_BrokerDealer__C+b.SPM_Legacy_Product_Code__c);}
        }
        //system.debug('class remove duplicate'+bdlist);
        return bdlist;
    }
Hi All,
Very goodmorning  to all.....here i'm sharing few thoughts on salesforce1 which is next generation mobile app from salesforce.Couple of days back when i started working on salesforce1 i really existed with new features avalaible and now salesforce.com is updating contuniousely related to salesforce1.
I'm haveing a scenario like want to customizie the standard details page with custom page of account object along with Compact pagelayouts,Extended Lookups,RElated list and Mobile cards.
Can any one through light on solutions so that it will be great help for me and at same time want to continue this discussion futher more with all u r support...........

Hi,

Is there any way to get list of all object and feild API names in org.

 

Ideas are appricated.....

I am newbie to developing test cases. can anybody guide me in writing a test class for the following code.

 

 

public class MyController {
   public MyController(ApexPages.StandardController controller) { 
   
    }
    Lead lead1;
    public PageReference save() {   
       if (lead1.Company == 'Unknown')
              {
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Do not Enter Uknown as Company Name'));
                return null;
            }  
        update lead1;        
        return null;
     }
    public String getName() {
        return 'MyController';
    }
    public Lead getLead() {
        if(lead1 == null) 
            lead1 = [select id,Company,Phone, name,Email,Notes__c,
                     Street,city,State,Availability_for_Call__c,
                      LeadSource
                     from Lead
                     where id = :ApexPages.currentPage().getParameters().get('id')];
        return lead1; 
    } 
}

 

 

  • September 13, 2013
  • Like
  • 0

Hi,

I have a trigger on Opportunity which fires once opportunity stage = closed won. My Test method passes but shows error on class?

 

/*
Author: Mahfuz Choudhury
Date: 13.09.13
TestClassName:TestCloneOppLineItem on Opportunity
*/
@isTest(seeAllData=true) 
private class TestCloneOppLineItem{
    static testMethod void TestOppMethod() {
        List<Contact> contlist = new List<Contact>{};
        
        //Start of the test execution
        Test.starttest();
        //create a new account to associate with the opportunity
        Account a = new Account(Name = 'Test Account');
        insert a;
        
        //Create a contact to assign as primary contact role
        Contact con = new Contact(FirstName = 'Maf', LastName = 'Sample', AccountId = a.Id);
        Contact con1 = new Contact(FirstName = 'Lewis', LastName = 'Test', AccountId = a.Id);
        contlist.add(con);
        contlist.add(con1);
        insert contlist;
        
        //Select A Standard pricebook for the product
        Pricebook2  standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1];
        
        //Create a Test PriceBook for OpportunityLineItem
        Pricebook2 pbk = new Pricebook2 (Name='Test Pricebook Entry 1',Description='Test Pricebook Entry 1', isActive=true);
        insert pbk;
        
        //Insert a new Product for test class
        Product2 prd = new Product2 (Name='Premium Product',Description='Test Product Entry 1',productCode = 'ABC', isActive = true);
        insert prd;
        
        //Insert a new Pricebook entry
        PricebookEntry pbe = new PricebookEntry (Product2ID=prd.id,Pricebook2ID=standardPb.id,UnitPrice=50, isActive=true,UseStandardPrice=false);
        insert pbe;
        
        //create a new opportunity to test
        Opportunity opp = new Opportunity();
        opp.Name = 'Test Opportunity';
        Opp.AccountId = a.id;
        Opp.StageName = 'Closed Won';
        Opp.Type = 'Existing Business';
        Opp.CloseDate =  Date.today()+2;
        insert opp;
        
        OpportunityLineItem OLI = new OpportunityLineItem();
        OLI.Quantity = 2;
        OLI.UnitPrice = 5.00;
        OLI.OpportunityId = Opp.id;
        //OLI.ProductId = pbe.Id;
        OLI.PricebookEntryId = pbe.id;
        insert OLI;
        
        //creating opportunity contact role and make it primary
        OpportunityContactRole ocr = new OpportunityContactRole(OpportunityId = Opp.Id, ContactId = Con.Id, IsPrimary = true);
        insert ocr;
        
        System.assertEquals('Closed Won',Opp.StageName);
        System.assertEquals(Opp.IsOnlineOrder__c, false);
        
        Opp.IsOnlineOrder__c = true;
        Update Opp;
        System.assertEquals(Opp.IsOnlineOrder__c, true);
        Test.stopTest();
    }
}

 Can I get some help on this plz...

  • September 13, 2013
  • Like
  • 0

Hi All,

I'm haveing scenario like Custom button on opportunity details page.Once we click on the buttom need to validate opportunity stage as prospecting if not error should throws on detils page if yes create a new contract with prepopulated info on the contract and contract information should show on detail page.

 

Wating for help.

Hi can any one help me out to get test coverage for .addError and .add statments

Below is the trigger and test calss.

Bold line are not covered with the existing test class.

trigger Erroriftwoopportunityareopen on Opportunity (before insert) {

 

    Set <id> setAccWithProspectingOpp = new Set <Id>();//Varaible to hold Account with Prospecting opp

    Set <id> setAccId = new Set <Id>();//Varaible to hold Account IDs

   

    if(trigger.isbefore){

        if(trigger.isinsert){

            //Iterate through opportunity

            for(Opportunity o:Trigger.new){

                //System.debug('Account Id -->'+o.Accountid);

                //Verify account id not null and opportunity stagename is Prospecting

                if(o.Accountid != Null && o.StageName == 'Prospecting'){

                    setAccId.add(o.Accountid);//Account is added to setAccId(Varaible)

                }

            }

            //System.debug('Set of accounts -->'+setAccId);

            //Fetch the accounitid of opportunity from aetAccId(Varaible)

            for(Opportunity Opp : [Select id,accountid from opportunity where accountid in :setAccId]){

                setAccWithProspectingOpp.add(Opp.accountid);//Add opportunity account id in setAccWithProspectingOpp(Variable)

            }

            //System.debug('Set of accounts with Prosp Opp-->'+setAccWithProspectingOpp);

            //Iterate through opportunity object

            for(Opportunity o:Trigger.new){

                //Chack condition that in setAccWithProspectingOpp(Varaible)contains opportunity account id

                if(setAccWithProspectingOpp.contains(o.accountid))

                    o.addError('This account already has Opportunity with StageName as Prospecting');  

            }

           

        }

    }

}

Test class

@isTest

    public class ErroriftwoopportunityareopenTest{

        static testMethod void Test(){

        User thisUser = [ Select Id from User where Id = :UserInfo.getUserId() ];

        Account acc = new Account(Name = 'TestAccount',Rating = 'Hot',Type = 'Prospect');

            //update acc;

        Opportunity opp = new Opportunity(Name = 'TestOpp',Accountid = acc.Id,CloseDate = Date.Today(),StageName = 'Prospecting');

            //update opp;

        Opportunity opp1 = new Opportunity(Name = 'TestOpp1',Accountid = acc.Id,CloseDate = Date.Today(),StageName = 'ClosedWon');

            //update opp1;

        Opportunity opp2 = new Opportunity(Name = 'TestOpp2',Accountid = acc.Id,CloseDate = Date.Today(),StageName = 'ClosedLost');

            //update opp2;

        Task t = new Task(WhatId=acc.Id,WhoId = opp.Id,Subject = 'Email',Status = 'Completed', Priority ='Normal');

            insert t;

        Test.startTest();

            insert acc;

            insert opp;

            insert opp1;

            insert opp2;

             User someOtherUser = [Select Id From User Where Id != :UserInfo.getUserId() And isActive = TRUE LIMIT 1];

    system.runAs(someOtherUser){

          insert opp;

     }

        Test.StopTest();

        }

    }

Hi,

My requriment is to write trigger for scenario Admin wants parent case cant be closed until all child cases are closed.

 

Below is my code

trigger Casecannotcloseifchildcsaeisopen on Case (before insert) {

List<Case> lstcase = new List<Case>();
Set<String> setcase = new Set<String>();

for(Case c : Trigger.new){
if(c.Status == 'Closed'){
setcase.add(c.Id);
}
}

lstcase = [Select Id from Case where id in:setcase];
Case childcase = new Case();
if(setcase.size()>0){
childcase.adderror('Can not delete case if child csae is open');
}
}

 Can any one help out.