• Chiyan
  • NEWBIE
  • 30 Points
  • Member since 2019

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

trigger OpportunityTrigger on Opportunity (before update) {
    if(Trigger.isBefore && Trigger.isUpdate){
        for(Opportunity op:Trigger.new){
            if((Trigger.oldMap.get(op.id).Amount!=Trigger.newMap.get(op.Id).Amount) && op.StageName=='Closed Won'){
                op.addError('you cannot change Amount on Won stage');
            }
        }
    }
}
  • February 06, 2019
  • Like
  • 0
Public class Stage{
 List<Opportunity> ops;
 String[] Stage = new String[]{};
 Public String[] getStage(){
 return Stage;
 }
 
 Public List<SelectOption> getitems(){
 List<SelectOption> Options= new List<SelectOption>();
  options.add(new SelectOption('Closed Won', 'Closed Won'));
  options.add(new SelectOption('Closed Lost', 'Closed Lost'));
  options.add(new SelectOption('Qualification', 'Open'));
  return options;
  }
  
  Public void setStage(String[] Stage){
  this.Stage = Stage;
  }
  
 Public List<Opportunity> getOpp(){
    return ops;
   } 
 
 Public Pagereference Result(){
 ops = [select name, stagename, closedate from Opportunity where stagename =: Stage];
 return null;
 }
 
 
}
  • February 04, 2019
  • Like
  • 0
public class Lookup {

    
    @AuraEnabled 
    public static String searchDB(String objectName, String fld_API_Text, String fld_API_Val, 
                                  Integer lim,String fld_API_Search,String searchText ){
        
        searchText='\'%' + String.escapeSingleQuotes(searchText.trim()) + '%\'';

        
        String query = 'SELECT '+fld_API_Text+' ,'+fld_API_Val+
                        ' FROM '+objectName+
                            ' WHERE '+fld_API_Search+' LIKE '+searchText+ 
                        ' LIMIT '+lim;
        
        List<sObject> sobjList = Database.query(query);
        List<ResultWrapper> lstRet = new List<ResultWrapper>();
        
        for(SObject s : sobjList){
            ResultWrapper obj = new ResultWrapper();
            obj.objName = objectName;
            obj.text = String.valueOf(s.get(fld_API_Text)) ;
            obj.val = String.valueOf(s.get(fld_API_Val))  ;
            lstRet.add(obj);
        } 
         return JSON.serialize(lstRet) ;
    }
    
    public class ResultWrapper{
        public String objName {get;set;}
        public String text{get;set;}
        public String val{get;set;}
    }
}
  • February 04, 2019
  • Like
  • 1
public class AccountController {
    @AuraEnabled
    public static List<Account> getLimitedAccounts(){
        List<Account> accounts = [SELECT Id, Name, Phone
                                  FROM Account ORDER BY CreatedDate LIMIT 20];  
        return accounts;
    }
}
  • February 01, 2019
  • Like
  • 0
trigger leadDuplicatePreventer on Lead (before insert,after update) {
  list<lead> lead = new   list<lead>(); 
 for(lead a: trigger.new)
 {
lead=[select id,name,email from lead where email=:a.email];
  if(lead.size()>0)
  {
   a.email.adderror('email already exist');
  }
 }
}
  • February 01, 2019
  • Like
  • 0
Hi 
here is the code


Public with sharing class KeywordSearch{
 Public List<Opportunity> optyList {get;set;}
 Public List<contact> conList{get;set;}
 Public List<account> accList{get;set;}

 Public String searchStr{get;set;}
   Public KeywordSearch(){
   }

  Public void soslSearchmethod (){
   optyList = New List<Opportunity>();
   conList = New List<contact>();
   accList = New List<account>();
   if(searchStr.length() > 2){
   String searchStr1 = '*'+searchStr+'*';
   String searchQuery = 'FIND \'' + searchStr1 + '\' IN ALL FIELDS RETURNING  Account (Id,Name,type),Contact(name,email),Opportunity(name,StageName)';
   List<List <sObject>> searchList = search.query(searchQuery);
   accList = ((List<Account>)searchList[0]);
   conList  = ((List<contact>)searchList[1]);
   optyList = ((List<Opportunity>)searchList[2]);
   if(accList.size() == 0 && conList.size() == 0 && optyList.size() == 0){
       apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Sory, no results returned with matching string..'));
       return;
   }
   }
   else{
   apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Please enter at least three characters..'));
   return;
   }
  }
}
  • January 31, 2019
  • Like
  • 0
trigger RollUpOppAmt on Opportunity (after insert) {
    
    Set<Id> setOpportunityIds=new Set<Id>();
    for(Opportunity o:Trigger.new)
        setOpportunityIds.add(o.id);
    
    List<Account> ListOfAmt = [select id, Amount__c from Account];
    List<Account> lstAmtToUpdate=new List<Account>();
    
    for(AggregateResult result:[SELECT AccountId, SUM(Amount) FROM Opportunity 
                                WHERE Id IN :setOpportunityIds GROUP BY AccountId]) {
        for(Account acc : ListOfAmt) {
            if(result.get('AccountId') == acc.Id) {
                if(acc.Amount__c == null) {
                    acc.Amount__c = 0;
                }
                acc.Amount__c = acc.Amount__c + Decimal.ValueOf(String.ValueOf(result.get('expr0')));
                lstAmtToUpdate.add(acc);
            }
        }
    }
    if(lstAmtToUpdate.size()>0) {
        UPDATE lstAmtToUpdate;
    }
}
  • January 31, 2019
  • Like
  • 0
public class opportunityReportController {
    public List<opportunity> oppList { get; set; }
    public boolean Lost { get; set; }
    public boolean Won { get; set; }
    public boolean Open { get; set; }
    
    public opportunityReportController (){
    open=false;
    lost=false;
    won=false;
    }
    public void mytableData() {
    oppList =new List<opportunity>();
    list<opportunity> oppOpenList=[Select id,name,amount,stageName from opportunity where stageName NOT IN('Closed Won','Closed Lost')];
    list<opportunity> oppWonList=[Select id,name,amount,stageName from opportunity where stageName ='Closed Won'];
    list<opportunity> oppLostList=[Select id,name,amount,stageName from opportunity where stageName ='Closed Lost'];
    
    system.debug('>>>>>i am here>>');
    if(open==true && Won==false && Lost==False){
        oppList.addall(oppOpenList);
    }
    else if(open==true && Won==true && Lost==False){
        oppList.addall(oppOpenList);
        oppList.addall(oppWonList);
    }
   else if(open==true && Won==true && Lost==true){
        oppList.addall(oppOpenList);
        oppList.addall(oppWonList);
        oppList.addall(oppLostList);
    }
    else if(open==false && Won==true && Lost==false){
        oppList.addall(oppWonList);
    }
    else if(open==false && Won==true && Lost==true){
        oppList.addall(oppWonList);
        oppList.addall(oppLostList);
    }
    else if(open==false && Won==false && Lost==true){
        oppList.addall(oppLostList);
    }
    else if(open==true && Won==false && Lost==true){
        oppList.addall(oppLostList);
        oppList.addall(oppOpenList);
    }
    
    }

    
}
  • January 31, 2019
  • Like
  • 0
public class Lookup {

    
    @AuraEnabled 
    public static String searchDB(String objectName, String fld_API_Text, String fld_API_Val, 
                                  Integer lim,String fld_API_Search,String searchText ){
        
        searchText='\'%' + String.escapeSingleQuotes(searchText.trim()) + '%\'';

        
        String query = 'SELECT '+fld_API_Text+' ,'+fld_API_Val+
                        ' FROM '+objectName+
                            ' WHERE '+fld_API_Search+' LIKE '+searchText+ 
                        ' LIMIT '+lim;
        
        List<sObject> sobjList = Database.query(query);
        List<ResultWrapper> lstRet = new List<ResultWrapper>();
        
        for(SObject s : sobjList){
            ResultWrapper obj = new ResultWrapper();
            obj.objName = objectName;
            obj.text = String.valueOf(s.get(fld_API_Text)) ;
            obj.val = String.valueOf(s.get(fld_API_Val))  ;
            lstRet.add(obj);
        } 
         return JSON.serialize(lstRet) ;
    }
    
    public class ResultWrapper{
        public String objName {get;set;}
        public String text{get;set;}
        public String val{get;set;}
    }
}
  • February 04, 2019
  • Like
  • 1