• Abhi Malik
  • NEWBIE
  • 99 Points
  • Member since 2016
  • Salesforce Developer
  • Techmatrix Consulting


  • Chatter
    Feed
  • 1
    Best Answers
  • 7
    Likes Received
  • 1
    Likes Given
  • 12
    Questions
  • 13
    Replies
is there any online aptitude test for salesforce?
am completly new to salesforce plese help.
Trigger:
trigger QuantityMOQValidate on OpportunityLineItem (after insert, after update) {
if(checkRecursive.runOnce()){
    Set<Id> pbeIds = new Set<Id>();
    for (OpportunityLineItem oli : Trigger.new){
        pbeIds.add(oli.pricebookentryid);
        system.debug('adding to pbeIds ------>' + oli.pricebookentry.id);
    }
    Map<Id, double> entries = new Map<Id, Decimal>();
    for(PricebookEntry pbe : [select id, MOQ__c from PricebookEntry where id IN : pbeIds]){
        entries.put(pbe.id, pbe.MOQ__c);
        system.debug('putting in a map id------>' + pbe.id);
        system.debug('putting in a map value------>' + pbe.MOQ__c);
    }
    list<OpportunityLineItem> upOLI = new list<OpportunityLineItem>();
    for(OpportunityLineItem oli: Trigger.new){
        if((oli.Quantity < entries.get(oli.pricebookEntryId)) && entries.get(oli.pricebookEntryId) != Null ){
            system.debug('Quantity less than MOQ');            
            oli.addError('Quantity less than MOQ ['+ Integer.valueof(entries.get(oli.pricebookEntryId))+']');
        }        
        system.debug('>>>>>>>>Quantity----->' + oli.Quantity+'>>MOQ val----->'+ entries.get(oli.pricebookEntryId));        
    }   
}
}

Testclass:

@istest
public class TestQuantityMOQValidate {
 static testMethod void myUnitTest() {       

//Data Prep
//Create Account, Opportunity, Product, etc.
        Account acct1 = new Account(name='test Account One1');
        insert acct1;
//Create Opportunity on Account
        Opportunity Oppty1 = new Opportunity(name='test Oppty One1');
        Oppty1.StageName = 'Selected';
        Oppty1.CloseDate = Date.today() + 30;
        insert Oppty1;         

// Create Products 
         Product2 testprod1 = new Product2 (name='test product one1');
         testprod1.productcode = 'test pd code1one';
        
                insert testprod1;
         Product2 testprod2 = new Product2 (name='test product two2');
         testprod2.productcode = 'test pd code2two';
         
         
         insert testprod2;
// Get Pricebook
         Pricebook2 testpb = [select id from Pricebook2 where IsStandard = true];
         testpb.IsActive=true;
         update testpb;   
// Add to pricebook
        PriceBookEntry pbe1 = new PricebookEntry();
        pbe1.UnitPrice = 100;
        pbe1.Product2Id = testprod1.Id;
        pbe1.Pricebook2Id = testpb.id;
        pbe1.IsActive = true;
        pbe1.useStandardPrice = false;
        insert pbe1;
        PriceBookEntry pbe2 = new PricebookEntry();
        pbe2.UnitPrice = 200;
        pbe2.Product2Id = testprod2.Id; 
        pbe2.Pricebook2Id = testpb.id;
        pbe2.IsActive = true;
        pbe2.useStandardPrice = false;
        insert pbe2;

Test.startTest();

Oppty1.StageName='Selected';
update Oppty1;
System.assertNotEquals('Prospecting', Oppty1.StageName); 

Test.stopTest();
}
}
Duration and Enddate both are not null at same time , and if both are provied a value then the value of both is equal then only record will be saved. otherwise through an error.
the null part is done like this( ISBLANK( Duration__c )&& ISBLANK( End_Date__c ) ) but how to check the value of duration and enddate.
 
Hi everyone
am trying to write a batch class for my project 
when i will create a pledge for donation then based on the duration our transactions are created by trigger but those transactions are not more then 12 but, if my duration is 24 months then .it will create 12 transaction by trigger after that when my list size of transactions is less then 12 every month then it will create a new transaction for that 12 th month and repeat this process for the complete duration .
code:

global class BatchClassPledgeTransaction implements Database.batchable<sObject> {
        String query;
     list<Transaction__c > transList=new list<Transaction__c >();
     // Start Method
    global Database.querylocator start(Database.BatchableContext BC){
        Query = 'Select id,name,Duration__c,Start_Date__c,End_Date__c from Pledge__c';   
        return Database.getQueryLocator(query);
    }
     // Execute Logic
    global void execute(Database.BatchableContext BC, List<Pledge__c> Scope){
       Id PledgeRecTypeCard = Schema.SObjectType.Pledge__c.getRecordTypeInfosByName().get('Card').getRecordTypeId();
       Id PledgeRecTypeGIRO = Schema.SObjectType.Pledge__c.getRecordTypeInfosByName().get('GIRO').getRecordTypeId();
       Id PledgeRecTypeOnline = Schema.SObjectType.Pledge__c.getRecordTypeInfosByName().get('Online').getRecordTypeId();
       Id PledgeRecTypeRecurringCash = Schema.SObjectType.Pledge__c.getRecordTypeInfosByName().get('Recurring Cash').getRecordTypeId();
       Id PledgeRecTypeRecurringCheque  = Schema.SObjectType.Pledge__c.getRecordTypeInfosByName().get('Recurring Cheque ').getRecordTypeId();
       Id TransactionRecTypeCard = Schema.SObjectType.Transaction__c .getRecordTypeInfosByName().get('Card').getRecordTypeId();
       Id TransactionRecTypeGIRO = Schema.SObjectType.Transaction__c .getRecordTypeInfosByName().get('GIRO').getRecordTypeId();
       Id TransactionRecTypeOnline = Schema.SObjectType.Transaction__c .getRecordTypeInfosByName().get('Online').getRecordTypeId();
       Id TransactionRecTypeRecurringCash = Schema.SObjectType.Transaction__c .getRecordTypeInfosByName().get('Recurring Cash').getRecordTypeId();
       Id TransactionRecTypeRecurringCheque  = Schema.SObjectType.Transaction__c .getRecordTypeInfosByName().get('Recurring Cheque ').getRecordTypeId();
       
       for(Pledge__c plg:Scope){
            Integer i=0;
            Integer loopiterater=0;
            Integer j=integer.valueof(plg.Duration__c)-12;
            Integer monthDiff = plg.Start_Date__c.monthsBetween(plg.End_Date__c);
            loopiterater=monthDiff;
        
       if(integer.valueof(plg.Duration__c)>12||loopiterater>12){ 
              for(i=0;i<=j;i++){
                Transaction__c tran= new Transaction__c ();
                       tran.Transaction_Date__c=plg.Start_Date__c.addMonths(i);
                       tran.Pledge__c=plg.id;
                       tran.Amount_Reconciled__c=plg.Amount__c;
                       tran.Donor__c=plg.Account__c;
                       tran.Status__c=plg.Status__c;
                      
                           if(plg.recordtypeid==PledgeRecTypeCard){
                              tran.recordtypeid=TransactionRecTypeCard;
                           } 
                            
                           if(plg.recordtypeid==PledgeRecTypeGIRO){
                              tran.recordtypeid=TransactionRecTypeGIRO;
                           } 
                           
                           if(plg.recordtypeid==PledgeRecTypeOnline){
                              tran.recordtypeid=TransactionRecTypeOnline;
                           } 
                           
                           if(plg.recordtypeid==PledgeRecTypeRecurringCash){
                              tran.recordtypeid=TransactionRecTypeRecurringCash;
                           } 
                           
                           if(plg.recordtypeid==PledgeRecTypeRecurringCheque){
                              tran.recordtypeid=TransactionRecTypeRecurringCheque;
                           } 
                       translist.add(tran);
            }
        
         }
        
       }
    }
     global void finish(Database.BatchableContext BC){
    }
}
Hi everyone
am trying to write a batch class for my project 
when i will create a pledge for donation then based on the duration our transactions are created by trigger but those transactions are not more then 12 but, if my duration is 24 months then .it will create 12 transaction by trigger after that when my list size of transactions is less then 12 every month then it will create a new transaction for that 12 th month and repeat this process for the complete duration .
********************trigger*****************

trigger WorkerStatusBefore on schnja__Worker_Status__c (before delete, before insert, before update) {
    
    if(Trigger.isInsert){
            TriggersWorkerStatus.handleBeforeInsert(Trigger.new);
    }
    else if(Trigger.isUpdate){
        TriggersWorkerStatus.handleBeforeUpdate(Trigger.oldMap,Trigger.newMap);
    }
    else if(trigger.isDelete){
        UtilWorkerStatus.checkAccessList(trigger.old);
    }  
}


********************UtilWorkerStatusClass*****************************
public with sharing class UtilWorkerStatus {
    
    public static Worker_Status__c createWorkerStatus(Id workerId, DateTime startDateTime, DateTime endDateTime, Id recordType){
        Worker_Status__c newWorkerStatus = generateWorkerStatus(workerId, startDateTime, endDateTime, recordType);
        insert newWorkerStatus;
        return newWorkerStatus;
    }
    public static Worker_Status__c generateWorkerStatus(Id workerId, DateTime startDateTime, DateTime endDateTime, Id recordType){
        return new Worker_Status__c(
            Worker__c = workerId, 
            Start_Date_Time__c = startDateTime, 
            End_Date_Time__c = endDateTime,
            RecordTypeId = recordType);
    }
    
    public static Worker_Status__c createDummyWorkerStatus(Id workerId, Id orgId){
        Worker_Status__c newWorkerStatus = generateDummyWorkerStatus(workerId, orgId);
        insert newWorkerStatus;
        return newWorkerStatus;
    }
    
    public static Worker_Status__c generateDummyWorkerStatus(Id workerId, Id orgId){
        if(orgId == null){
            orgId = UtilOrgLevel.createOrgLevel('Dummy', null).Id;
        }
        if(workerId == null){
            workerId = UtilWorker.createWorker('Dummy', 'Worker', orgId).Id;
        }
        return generateWorkerStatus(workerId, DateTime.now().addHours(1), DateTime.now().addHours(6), UtilGeneral.getRecordTypeId('schnja__Worker_Status__c', 'One-Time Availability'));
    }
    
    public static Map<Id,Boolean> checkAccessList (List<Worker_Status__c> record){
        Map <Id, boolean> accessMap = new Map <Id, boolean> ();
        //Check to see if the current user is an Availability Admin, If so return true for all Ids
        if(UtilGeneral.avilabilityPermissions.Availability_Admin__c){
            //Iterate through records, add them to accessMap with True and return it
            for(Worker_Status__c accessRecord:record){
                accessMap.put(accessRecord.Id,True);
            }
            return accessMap;
        }
        //Build a list of Ids of the scheduled Workerss
        system.debug(record);
        List <Id> workerIDs = new List <Id> ();
        for (Worker_Status__c accessRecord:record){
            workerIDs.add(accessRecord.Worker__c);
        }

        // Query to get the contact record of the scheduled workers
        Map <Id, Worker__c> currentWorker = new Map <Id,Worker__c> ([select Id, User_Record__c, Reports_To__r.User_Record__c from Worker__c where Id in :workerIds]);
        Id currentUser = UserInfo.getUserId();
        Boolean managersCanEdit = UtilGeneral.defaultSettings.Managers_Can_Edit_Availability__c;

        // Iterate through records, check to see if the user has access to change that record.  Add the Id and true to accessMap if they have access, false if not
        for (Worker_Status__c accessRecord:record){ 
            if(currentUser == currentWorker.get(accessRecord.Worker__c).User_Record__c || managersCanEdit && currentWorker.get(accessRecord.Worker__c).Reports_To__r.User_Record__c == currentUser){
                accessMap.put(accessRecord.Id,True);
            }else{
                accessMap.put(accessRecord.Id,False);
            }
        }
        return accessMap;
    }
    public static List<Worker_Status__c> generateNewInstances(Worker_Status__c recurring)
    {
        List<Worker_Status__c> newInstances = new List<Worker_Status__c>{};
        // Set the beginning Instance date to the start date of the 
        //  recurring or budget transaction
        DateTime currentStart = recurring.schnja__Start_Date_Time__c;
        DateTime currentEnd = recurring.schnja__End_Date_Time__c;
        
        // Determine the end date for the instance transactions
        // TODO:  Update this to look at the organization's Availability Settings
        Date finalDate = recurring.schnja__Repeat_Until__c == null ? (Date) recurring.schnja__Start_Date_Time__c.addYears(2) : recurring.schnja__Repeat_Until__c; 
        
        Id instanceRecordTypeId = UtilGeneral.getRecordTypeId('schnja__Worker_Status__c', 'Availability Instance');
        
        while(currentStart<=finalDate)
        {
            Worker_Status__c newStatus = UtilWorkerStatus.generateWorkerStatus(recurring.schnja__Worker__c, currentStart, currentEnd, instanceRecordTypeId);
            newStatus.Instance_Of__c = recurring.Id;
            newStatus.Description__c = recurring.Description__c;
            
            newInstances.add(newStatus);
            
            if(recurring.schnja__Recurrence_Interval__c == 'Days')
            {
                currentStart = currentStart.addDays(recurring.schnja__Recurs_Every__c.intValue());
                currentEnd = currentEnd.addDays(recurring.schnja__Recurs_Every__c.intValue());
            }
            else if(recurring.schnja__Recurrence_Interval__c == 'Weeks')
            {
                currentStart = currentStart.addDays(recurring.schnja__Recurs_Every__c.intValue() * 7);
                currentEnd = currentEnd.addDays(recurring.schnja__Recurs_Every__c.intValue() * 7);
            }
            else if(recurring.schnja__Recurrence_Interval__c == 'Months'){
                currentStart = currentStart.addMonths(recurring.schnja__Recurs_Every__c.intValue());
                currentEnd = currentEnd.addMonths(recurring.schnja__Recurs_Every__c.intValue());
            }
            else{
                currentStart = currentStart.addYears(recurring.schnja__Recurs_Every__c.intValue());
                currentEnd = currentEnd.addYears(recurring.schnja__Recurs_Every__c.intValue());
            }
        }
        
        return newInstances;
    }


********************TriggersWorkerStatusClass***********************


public class TriggersWorkerStatus {
    public static void handleAfterInsert(Map<Id, Worker_Status__c> triggerMap){
        //Get list of recurring Worker Statuses
        //system.debug(Schema.getGlobalDescribe().get('schnja__Worker_Status__c').getDescribe().getRecordtypeInfosByName());
        
        list <Worker_Status__c> recurringStatus = new list <Worker_Status__c>();
        Id recurringStatusID = UtilGeneral.getRecordTypeId('schnja__Worker_Status__c', 'Recurring Availability');
        for (Worker_Status__c newStatus: triggerMap.values()){
            if (newStatus.RecordTypeID == recurringStatusID) recurringStatus.add(newStatus);
        }
        //If the list isn't empty, iterate through list and pass them to generateNewInstances
        if (!recurringStatus.isEmpty()){
            list <Worker_Status__c> newInstances = new list <Worker_Status__c>();
            for(Worker_Status__c newRecurringStatus: recurringStatus){
                newInstances.addAll(UtilWorkerStatus.generateNewInstances(newRecurringStatus));
            }
            //Insert list of new Instance records if it is not empty
            if (!newInstances.isEmpty()) insert newInstances;
        }
    }
    public static void handleAfterUpdate(Map<Id, Worker_Status__c> beforeMap, Map<Id, Worker_Status__c> afterMap){
        //create blank list of Worker Statuses
        list <Id> busyStatus = new list <Id>();
        //iterate through list of updated records
        for (Worker_Status__c updatedRecord: afterMap.values()){
            //check to see if the status is canceled.
            if(updatedRecord.Status__c == 'Canceled'){
                //If the status is cancelled, check to see if the dates or times have changed
                if (updatedRecord.Start_Date_Time__c != beforeMap.get(updatedRecord.ID).Start_Date_Time__c || updatedRecord.End_Date_Time__c != beforeMap.get(updatedRecord.ID).End_Date_Time__c){
                    //If they have set the Worker Status to Busy and add them to the list of Worker statuses to update
                    busyStatus.add(updatedRecord.Id);
                }
            }    
        }
        
        //Update the changed statuses if the list isn't empty (and everything that goes with it)
        if (!busyStatus.isEmpty()){
            list <Worker_Status__c> updatedStatus = [SELECT Id, Status__c from Worker_Status__c where Id in :busyStatus];
            for (Worker_Status__c statusRecord : updatedStatus){
                statusRecord.Status__c = 'Busy';
            }
            update updatedStatus;
        }
    }
    public static void handleBeforeUpdate(Map<Id, Worker_Status__c> beforeMap, Map<Id, Worker_Status__c> afterMap){
        //Check access and attach errors to records that the user doesn't have permission to modify
        Map <Id,Boolean> accessMap = UtilWorkerStatus.checkAccessList(afterMap.Values());
        for(Worker_Status__c statusRecord:afterMap.Values()){
            if(!accessMap.get(statusRecord.Id)) statusRecord.addError('You have insufficient rights to update this Worker Status record.');
        }
    }
    public static void handleBeforeInsert(List <Worker_Status__c> beforeList){
        //Check access and attach errors to records that the user doesn't have permission to modify
        // system.debug(beforeList);
        Map <Id,Boolean> accessMap = UtilWorkerStatus.checkAccessList(beforeList);
        for(Worker_Status__c statusRecord:beforeList){
            if(!accessMap.get(statusRecord.Id)) statusRecord.addError('You have insufficient rights to update this Worker Status record.');
        }
    }
    
    public static void handleBeforeDelete(List <Worker_Status__c> AfterList){
        //Check access and attach errors to records that the user doesn't have permission to Delete
        Map <Id,Boolean> deletemap = UtilWorkerStatus.checkAccessList(AfterList);
        for(Worker_Status__c statusRecord:AfterList){
            if(!deletemap.get(statusRecord.Id)) statusRecord.addError('You have insufficient rights to Delete this Worker Status record.');
        }
    }
}
 
If the User edits the Start Date, End Date, Recurs Every, or Recurrence Interval fields, the system will automatically update, create, or remove any related Availability Instance records based on the new parameters. Availability Instance records where the Start Date & Time has already occurred should not be updated.

Hi all
am working on this page where i want, when i click on the account tab my data will be shown in the related list section and when i select that account from related list that account will be editable below the account tab and i want same for payment tab also please help am completly stuck in this problem . please shARE SOME releated examples to this .User-added image
User-added image
Hi all
am working on this page where i want, when i click on the account tab my data will be shown in the related list section and when i select that account from related list that account will be editable below the account tab and i want same for payment tab also please help am completly stuck in this problem . please shARE SOME releated examples to this .
 
Am trying to use javascript in a very simple VF page but it is not working can anybody please help me to find out the error.
<----------------PAGE---------------->
<apex:page controller="Example2">

 <script type="text/javascript">
 
    function validate()
    {
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi1.aa}').value == '')
        {
            alert("FIRST NAME is mandatory");
        }
        if(document.getElementById('{!$Component.frm.pb.pbs.bb}').value == '')
        {
            alert("LAST NAME is mandatory");
        }
         else
        {
            callmove();
            alert("NAME has been inserted CONCATINATED");
        }
    }
        
  </script>  
  <apex:form id="frm"> 
  <apex:actionFunction action="{!move}" name="move" reRender="pb"/>  
   <apex:pageBlock id="pb">   
    <apex:pageBlockSection id="pbs">
               <apex:pageBlockSectionItem ><apex:outputLabel value="FIRST NAME"/></apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem id="pbsi1"><apex:inputText value="{!aa}" id="aa"/></apex:pageBlockSectionItem>
              <apex:pageBlockSectionItem ><apex:outputLabel value="LAST NAME"/></apex:pageBlockSectionItem> 
            <apex:pageBlockSectionItem id="pbsi2"><apex:inputText value="{!bb}" id="bb"/></apex:pageBlockSectionItem>
       <apex:pageBlockSectionItem ><apex:outputLabel value="FULL NAME"/></apex:pageBlockSectionItem> 
            <apex:pageBlockSectionItem id="pbsi3"><apex:inputText value="{!cc}" id="cc"/></apex:pageBlockSectionItem>        
    </apex:pageBlockSection>    
      <apex:pageBlockButtons location="bottom" >      
    <apex:commandButton value="CONCAT" action="{!move}" onclick="move();"/>
        </apex:pageBlockButtons>  
   </apex:pageBlock>
     </apex:form>
 </apex:page>

<----------------CLASS---------------->
public class Example2 {

    public PageReference move() {
    cc=aa+bb;
        return null;
    }

public string aa{get;set;}
public string bb{get;set;}
public string cc{get;set;}
 
public pagereference getMove() {
cc=aa+bb;
return null;
        
    }

}
I am trying to Schedule an class at the interval of 5 minutes but am not getting any idea how to perform it, i have seen some examples but they are not working properly please help if any body can.
There was an unhandled exception. Please reference ID: EMRPTZQO. Error: Faraday::ResourceNotFound. Message: NOT_FOUND: The requested resource does not exist 
Note: you may run into errors if you've skipped previous steps.
Duration and Enddate both are not null at same time , and if both are provied a value then the value of both is equal then only record will be saved. otherwise through an error.
the null part is done like this( ISBLANK( Duration__c )&& ISBLANK( End_Date__c ) ) but how to check the value of duration and enddate.
 
User-added image
Hi all
am working on this page where i want, when i click on the account tab my data will be shown in the related list section and when i select that account from related list that account will be editable below the account tab and i want same for payment tab also please help am completly stuck in this problem . please shARE SOME releated examples to this .
 
Am trying to use javascript in a very simple VF page but it is not working can anybody please help me to find out the error.
<----------------PAGE---------------->
<apex:page controller="Example2">

 <script type="text/javascript">
 
    function validate()
    {
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi1.aa}').value == '')
        {
            alert("FIRST NAME is mandatory");
        }
        if(document.getElementById('{!$Component.frm.pb.pbs.bb}').value == '')
        {
            alert("LAST NAME is mandatory");
        }
         else
        {
            callmove();
            alert("NAME has been inserted CONCATINATED");
        }
    }
        
  </script>  
  <apex:form id="frm"> 
  <apex:actionFunction action="{!move}" name="move" reRender="pb"/>  
   <apex:pageBlock id="pb">   
    <apex:pageBlockSection id="pbs">
               <apex:pageBlockSectionItem ><apex:outputLabel value="FIRST NAME"/></apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem id="pbsi1"><apex:inputText value="{!aa}" id="aa"/></apex:pageBlockSectionItem>
              <apex:pageBlockSectionItem ><apex:outputLabel value="LAST NAME"/></apex:pageBlockSectionItem> 
            <apex:pageBlockSectionItem id="pbsi2"><apex:inputText value="{!bb}" id="bb"/></apex:pageBlockSectionItem>
       <apex:pageBlockSectionItem ><apex:outputLabel value="FULL NAME"/></apex:pageBlockSectionItem> 
            <apex:pageBlockSectionItem id="pbsi3"><apex:inputText value="{!cc}" id="cc"/></apex:pageBlockSectionItem>        
    </apex:pageBlockSection>    
      <apex:pageBlockButtons location="bottom" >      
    <apex:commandButton value="CONCAT" action="{!move}" onclick="move();"/>
        </apex:pageBlockButtons>  
   </apex:pageBlock>
     </apex:form>
 </apex:page>

<----------------CLASS---------------->
public class Example2 {

    public PageReference move() {
    cc=aa+bb;
        return null;
    }

public string aa{get;set;}
public string bb{get;set;}
public string cc{get;set;}
 
public pagereference getMove() {
cc=aa+bb;
return null;
        
    }

}
Trigger:
trigger QuantityMOQValidate on OpportunityLineItem (after insert, after update) {
if(checkRecursive.runOnce()){
    Set<Id> pbeIds = new Set<Id>();
    for (OpportunityLineItem oli : Trigger.new){
        pbeIds.add(oli.pricebookentryid);
        system.debug('adding to pbeIds ------>' + oli.pricebookentry.id);
    }
    Map<Id, double> entries = new Map<Id, Decimal>();
    for(PricebookEntry pbe : [select id, MOQ__c from PricebookEntry where id IN : pbeIds]){
        entries.put(pbe.id, pbe.MOQ__c);
        system.debug('putting in a map id------>' + pbe.id);
        system.debug('putting in a map value------>' + pbe.MOQ__c);
    }
    list<OpportunityLineItem> upOLI = new list<OpportunityLineItem>();
    for(OpportunityLineItem oli: Trigger.new){
        if((oli.Quantity < entries.get(oli.pricebookEntryId)) && entries.get(oli.pricebookEntryId) != Null ){
            system.debug('Quantity less than MOQ');            
            oli.addError('Quantity less than MOQ ['+ Integer.valueof(entries.get(oli.pricebookEntryId))+']');
        }        
        system.debug('>>>>>>>>Quantity----->' + oli.Quantity+'>>MOQ val----->'+ entries.get(oli.pricebookEntryId));        
    }   
}
}

Testclass:

@istest
public class TestQuantityMOQValidate {
 static testMethod void myUnitTest() {       

//Data Prep
//Create Account, Opportunity, Product, etc.
        Account acct1 = new Account(name='test Account One1');
        insert acct1;
//Create Opportunity on Account
        Opportunity Oppty1 = new Opportunity(name='test Oppty One1');
        Oppty1.StageName = 'Selected';
        Oppty1.CloseDate = Date.today() + 30;
        insert Oppty1;         

// Create Products 
         Product2 testprod1 = new Product2 (name='test product one1');
         testprod1.productcode = 'test pd code1one';
        
                insert testprod1;
         Product2 testprod2 = new Product2 (name='test product two2');
         testprod2.productcode = 'test pd code2two';
         
         
         insert testprod2;
// Get Pricebook
         Pricebook2 testpb = [select id from Pricebook2 where IsStandard = true];
         testpb.IsActive=true;
         update testpb;   
// Add to pricebook
        PriceBookEntry pbe1 = new PricebookEntry();
        pbe1.UnitPrice = 100;
        pbe1.Product2Id = testprod1.Id;
        pbe1.Pricebook2Id = testpb.id;
        pbe1.IsActive = true;
        pbe1.useStandardPrice = false;
        insert pbe1;
        PriceBookEntry pbe2 = new PricebookEntry();
        pbe2.UnitPrice = 200;
        pbe2.Product2Id = testprod2.Id; 
        pbe2.Pricebook2Id = testpb.id;
        pbe2.IsActive = true;
        pbe2.useStandardPrice = false;
        insert pbe2;

Test.startTest();

Oppty1.StageName='Selected';
update Oppty1;
System.assertNotEquals('Prospecting', Oppty1.StageName); 

Test.stopTest();
}
}
Duration and Enddate both are not null at same time , and if both are provied a value then the value of both is equal then only record will be saved. otherwise through an error.
the null part is done like this( ISBLANK( Duration__c )&& ISBLANK( End_Date__c ) ) but how to check the value of duration and enddate.
 
Hi everyone
am trying to write a batch class for my project 
when i will create a pledge for donation then based on the duration our transactions are created by trigger but those transactions are not more then 12 but, if my duration is 24 months then .it will create 12 transaction by trigger after that when my list size of transactions is less then 12 every month then it will create a new transaction for that 12 th month and repeat this process for the complete duration .
code:

global class BatchClassPledgeTransaction implements Database.batchable<sObject> {
        String query;
     list<Transaction__c > transList=new list<Transaction__c >();
     // Start Method
    global Database.querylocator start(Database.BatchableContext BC){
        Query = 'Select id,name,Duration__c,Start_Date__c,End_Date__c from Pledge__c';   
        return Database.getQueryLocator(query);
    }
     // Execute Logic
    global void execute(Database.BatchableContext BC, List<Pledge__c> Scope){
       Id PledgeRecTypeCard = Schema.SObjectType.Pledge__c.getRecordTypeInfosByName().get('Card').getRecordTypeId();
       Id PledgeRecTypeGIRO = Schema.SObjectType.Pledge__c.getRecordTypeInfosByName().get('GIRO').getRecordTypeId();
       Id PledgeRecTypeOnline = Schema.SObjectType.Pledge__c.getRecordTypeInfosByName().get('Online').getRecordTypeId();
       Id PledgeRecTypeRecurringCash = Schema.SObjectType.Pledge__c.getRecordTypeInfosByName().get('Recurring Cash').getRecordTypeId();
       Id PledgeRecTypeRecurringCheque  = Schema.SObjectType.Pledge__c.getRecordTypeInfosByName().get('Recurring Cheque ').getRecordTypeId();
       Id TransactionRecTypeCard = Schema.SObjectType.Transaction__c .getRecordTypeInfosByName().get('Card').getRecordTypeId();
       Id TransactionRecTypeGIRO = Schema.SObjectType.Transaction__c .getRecordTypeInfosByName().get('GIRO').getRecordTypeId();
       Id TransactionRecTypeOnline = Schema.SObjectType.Transaction__c .getRecordTypeInfosByName().get('Online').getRecordTypeId();
       Id TransactionRecTypeRecurringCash = Schema.SObjectType.Transaction__c .getRecordTypeInfosByName().get('Recurring Cash').getRecordTypeId();
       Id TransactionRecTypeRecurringCheque  = Schema.SObjectType.Transaction__c .getRecordTypeInfosByName().get('Recurring Cheque ').getRecordTypeId();
       
       for(Pledge__c plg:Scope){
            Integer i=0;
            Integer loopiterater=0;
            Integer j=integer.valueof(plg.Duration__c)-12;
            Integer monthDiff = plg.Start_Date__c.monthsBetween(plg.End_Date__c);
            loopiterater=monthDiff;
        
       if(integer.valueof(plg.Duration__c)>12||loopiterater>12){ 
              for(i=0;i<=j;i++){
                Transaction__c tran= new Transaction__c ();
                       tran.Transaction_Date__c=plg.Start_Date__c.addMonths(i);
                       tran.Pledge__c=plg.id;
                       tran.Amount_Reconciled__c=plg.Amount__c;
                       tran.Donor__c=plg.Account__c;
                       tran.Status__c=plg.Status__c;
                      
                           if(plg.recordtypeid==PledgeRecTypeCard){
                              tran.recordtypeid=TransactionRecTypeCard;
                           } 
                            
                           if(plg.recordtypeid==PledgeRecTypeGIRO){
                              tran.recordtypeid=TransactionRecTypeGIRO;
                           } 
                           
                           if(plg.recordtypeid==PledgeRecTypeOnline){
                              tran.recordtypeid=TransactionRecTypeOnline;
                           } 
                           
                           if(plg.recordtypeid==PledgeRecTypeRecurringCash){
                              tran.recordtypeid=TransactionRecTypeRecurringCash;
                           } 
                           
                           if(plg.recordtypeid==PledgeRecTypeRecurringCheque){
                              tran.recordtypeid=TransactionRecTypeRecurringCheque;
                           } 
                       translist.add(tran);
            }
        
         }
        
       }
    }
     global void finish(Database.BatchableContext BC){
    }
}
<apex:page id="Page" showHeader="false" controller="MyCustomVFPage_CTR" action="{!InitPage}" cache="false">
    <apex:form >
        Thank you for your response.
    </apex:form>
</apex:page>
^ Visualforce page. When someone clicks a link in an alert email I sent them it directs them here, and appends a value in the url based on what link in the alert they click: accepted or rejected. 
 
public class MyCustomVFPage_CTR {
    public String ObjectId {get;set;}
    public String ResponseCode {get;set;}
    public MyCustomVFPage_CTR () {
        ObjectId = ApexPages.currentPage().getParameters().get('ObjectId');
        ResponseCode = ApexPages.currentPage().getParameters().get('ResponseCode');
    }
    public PageReference InitPage() {
        List<Lead> CustomerIssues = [SELECT Id, Status FROM Lead WHERE Id=:ObjectId LIMIT 1];
        if(!CustomerIssues.IsEmpty()){
            CustomerIssues[0].Status = ResponseCode;
            UPDATE CustomerIssues;
        }
        Return null;
    }
}
^ class takes the value that's passed from the url, and updates the related record.

I don't know how to get code coverage for that class. Do I need to write something to test going to a visualforce page?





 
is there any online aptitude test for salesforce?
am completly new to salesforce plese help.
Am trying to use javascript in a very simple VF page but it is not working can anybody please help me to find out the error.
<----------------PAGE---------------->
<apex:page controller="Example2">

 <script type="text/javascript">
 
    function validate()
    {
        if(document.getElementById('{!$Component.frm.pb.pbs.pbsi1.aa}').value == '')
        {
            alert("FIRST NAME is mandatory");
        }
        if(document.getElementById('{!$Component.frm.pb.pbs.bb}').value == '')
        {
            alert("LAST NAME is mandatory");
        }
         else
        {
            callmove();
            alert("NAME has been inserted CONCATINATED");
        }
    }
        
  </script>  
  <apex:form id="frm"> 
  <apex:actionFunction action="{!move}" name="move" reRender="pb"/>  
   <apex:pageBlock id="pb">   
    <apex:pageBlockSection id="pbs">
               <apex:pageBlockSectionItem ><apex:outputLabel value="FIRST NAME"/></apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem id="pbsi1"><apex:inputText value="{!aa}" id="aa"/></apex:pageBlockSectionItem>
              <apex:pageBlockSectionItem ><apex:outputLabel value="LAST NAME"/></apex:pageBlockSectionItem> 
            <apex:pageBlockSectionItem id="pbsi2"><apex:inputText value="{!bb}" id="bb"/></apex:pageBlockSectionItem>
       <apex:pageBlockSectionItem ><apex:outputLabel value="FULL NAME"/></apex:pageBlockSectionItem> 
            <apex:pageBlockSectionItem id="pbsi3"><apex:inputText value="{!cc}" id="cc"/></apex:pageBlockSectionItem>        
    </apex:pageBlockSection>    
      <apex:pageBlockButtons location="bottom" >      
    <apex:commandButton value="CONCAT" action="{!move}" onclick="move();"/>
        </apex:pageBlockButtons>  
   </apex:pageBlock>
     </apex:form>
 </apex:page>

<----------------CLASS---------------->
public class Example2 {

    public PageReference move() {
    cc=aa+bb;
        return null;
    }

public string aa{get;set;}
public string bb{get;set;}
public string cc{get;set;}
 
public pagereference getMove() {
cc=aa+bb;
return null;
        
    }

}
I am trying to Schedule an class at the interval of 5 minutes but am not getting any idea how to perform it, i have seen some examples but they are not working properly please help if any body can.
I have a trigger that has to delete an Account record associated with a Contact record when that particular contact  record gets deleted, However I get the following error when the DML  statement delete get's executed.

"15:14:59:227 FATAL_ERROR System.DmlException: Delete failed. First exception on row 0 with id 0011100000R5Gf0AAF; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 0031100000QId7U) is currently in trigger deleteAccountRecord, therefore it cannot recursively delete itself: []"

here is my code: 

trigger deleteAccountRecord on Contact (before delete) {


    RecordType donorRecType = [SELECT ID FROM RecordType WHERE sObjectType = 'Contact' AND DeveloperName = 'Donor_Contact'];
    if(Trigger.isDelete){
        List<ID> contactIDList = new List<ID>();
        for(Contact contactToDelete: Trigger.old) {
            if (contactToDelete.RecordTypeId != donorRecType.Id ) {
                  
                    contactIDList.add(contactToDelete.id);
            }
        }
      
       
       List<Account> DelAccountRecordList = [select id from Account where Id IN(SELECT accountId FROM Contact WHERE Id IN :contactIDList)];

        if(DelAccountRecordList.size() >0 && RecursiveTriggerHelper.isFirstRun){
           RecursiveTriggerHelper.isFirstRun = false;
           delete DelAccountRecordList ;
         
        }
     }
  }

//Helps to stop the trigger from firing twice. (at least It should but it's not working)
public class RecursiveTriggerHelper {

     public static boolean isFirstRun = true;
  
}

I have tried using "After Insert" but DelAccountRecordList returns null with no records. Is there a way to deal with my error without changing "Before Update". I am totally out of ideas on how to solve this issue.

Thanks in advance for your help.
is there any online aptitude test for salesforce?
am completly new to salesforce plese help.