• Ashish Arun Waghmare
  • NEWBIE
  • 55 Points
  • Member since 2018
  • Technical Lead
  • ESPL

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

trigger oppattachment on Opportunity (before insert, before update) {


  Opportunity[] opptys = [SELECT Id, (SELECT Id, Name, ContentType FROM Attachments where  (name like  '%declaration%'))
                          //OR (name ='international declaration.txt'))  
                          FROM Opportunity 
                          where id IN :Trigger.newMap.keySet() AND (Not Billing_Address__c  like '%United Arab Emirates%') ];
  for(Opportunity o : opptys){
            Attachment[] attc = o.Attachments;
            System.debug('attc.size() : ' + attc.size());
            if(Trigger.newMap.get(o.Id).StageName=='Booked' || Trigger.newMap.get(o.Id).StageName=='Booked – Contract Received' )
            {
               if(attc.size()>0)
               {
                System.debug('Need to set Is_declaration_attached__c to true for Opportunity Id: ' + o.id);
                System.debug('just testing this: ' + Trigger.newMap.get(o.Id).Id);
             
                Trigger.newMap.get(o.Id).Is_declaration_attached__c = true;
                Trigger.newMap.get(o.Id).International_Client__c = True;
               // o.
               }
               else
               {
                Trigger.newMap.get(o.Id).addError('You are  International Clint Please provide the Internation Declaration Attachment file before saving this record the file name should be contain declaration');
                Trigger.newMap.get(o.Id).Is_declaration_attached__c = false; 
                Trigger.newMap.get(o.Id).International_Client__c = false;  
               }    
           }            
    }

}

 

when i created new opportunity this error Occurs but trigger working fine on exsiting Opportunity please help me need to solve urgent....

Error:
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger oppattachment caused an unexpected exception, contact your administrator: oppattachment: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.oppattachment: line 7, column 1

Hi,
What is the best practice to generate JSON string for HTTP callouts? The options I know are:
1) Using String variables and methods
2) Use JSON.serialize function after defining a class
3) Use JSONGenerator
Using the above 3 methods, if we need to change the request, we have to change the code. Is there any other good solution so that the code need not be chaged even if the JSON request needs to be changed?
What is the best practice in generating JSON request?
Thanks.

Hello All ,
I am trying upload a .wav to voicera ,if the .wav file is greater than  (99 bytes for example) in size then it needs to chunked in  bytes . 
Has anyone worked on the .wav file chunking in salesforce ? 
 
Hi Team,
I have develpoed below JS but it's not working , when i am trying to click a custom button getting an unexpected token alert.
Kindly help out on this.

<script type="text/javascript">
            var newWin;
            function openingwindow()
            {              
               alert('cmng to loop..');
               newWin=window.open("https://api1.cloudagent.in/CAServices/AgentManualDial.php?api_key=KKf490fbb75a904b31bcbe7ddb7a681919&Country={!Lead.Country__c}&Phone={!Lead.Phone}",'width=100,height=100');
               alert(setTimeout(function(){newWin.close()}, 30000));
               setTimeout(function(){newWin.close()}, 30000);
               alert('closed..');
            }
                       
    </script>

trigger oppattachment on Opportunity (before insert, before update) {


  Opportunity[] opptys = [SELECT Id, (SELECT Id, Name, ContentType FROM Attachments where  (name like  '%declaration%'))
                          //OR (name ='international declaration.txt'))  
                          FROM Opportunity 
                          where id IN :Trigger.newMap.keySet() AND (Not Billing_Address__c  like '%United Arab Emirates%') ];
  for(Opportunity o : opptys){
            Attachment[] attc = o.Attachments;
            System.debug('attc.size() : ' + attc.size());
            if(Trigger.newMap.get(o.Id).StageName=='Booked' || Trigger.newMap.get(o.Id).StageName=='Booked – Contract Received' )
            {
               if(attc.size()>0)
               {
                System.debug('Need to set Is_declaration_attached__c to true for Opportunity Id: ' + o.id);
                System.debug('just testing this: ' + Trigger.newMap.get(o.Id).Id);
             
                Trigger.newMap.get(o.Id).Is_declaration_attached__c = true;
                Trigger.newMap.get(o.Id).International_Client__c = True;
               // o.
               }
               else
               {
                Trigger.newMap.get(o.Id).addError('You are  International Clint Please provide the Internation Declaration Attachment file before saving this record the file name should be contain declaration');
                Trigger.newMap.get(o.Id).Is_declaration_attached__c = false; 
                Trigger.newMap.get(o.Id).International_Client__c = false;  
               }    
           }            
    }

}

 

when i created new opportunity this error Occurs but trigger working fine on exsiting Opportunity please help me need to solve urgent....

Error:
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger oppattachment caused an unexpected exception, contact your administrator: oppattachment: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.oppattachment: line 7, column 1

Hello, 

I have a range problem with one of my variables : 
String MCLU1 = 'BK2200 0015 -- 41';

        if (MCLU1 != null || MCLU1 != '') {
            String bk = null; 
            String bk_full = null;
            String bk_extension = '--'; 
            String [] bkAfterSplit = null;
    
            bk_full = MCLU1; 
            if (bk_full.contains(bk_extension)) {
                bkAfterSplit = bk_full.split(' -- ');
                bk = bkAfterSplit[0];
                System.debug(LoggingLevel.DEBUG, 'bk inside my if : ' + bk);
            } else {
                bk = bk_full;
                System.debug(LoggingLevel.DEBUG, 'bk inside my else : ' + bk);
            }
            
        } else {
            System.debug(LoggingLevel.DEBUG, 'MCLU1__c is empty');
        }
        String external_id = 'FRA-BLIP-' + bk;
        System.debug(LoggingLevel.DEBUG, 'bk outside my if/else : ' + bk);
        System.debug(LoggingLevel.DEBUG, 'external_id : ' + external_id);
line 22, I need to get my bk variable but i get a Variable does not exist: bk. And I don't seem to understand why. I try almost the same code in eclipse and it worked : 
public class BkDoesNotExist {

	public static void main(String[] args) {
		
		String MCLU1__c = "BK2200 0015 -- 41";
		
		String bk = null; 
		String bk_full = null;
		String bk_extension = "--"; 
		String [] bkAfterSplit = null;
		
        if (MCLU1__c != null || MCLU1__c != "") {
            
        // variables nécessaires pour split mon BK proprement 

            bk_full = MCLU1__c; 
            if (bk_full.contains(bk_extension)) {
                bkAfterSplit = bk_full.split(" -- ");
                bk = bkAfterSplit[0];
                System.out.println("bk inside my if : " + bk);
            } else {
                bk = bk_full;
            }
            
        } else {
            System.out.println("MCLU1__c is empty");
        }

        String external_id = "FRA-BLIP-"+bk; 
        System.out.println("bk outside my if : " + bk);
        System.out.println("external_id : " + external_id);
	}

}
result in console : 
bk inside my if : BK2200 0015
bk outside my if : BK2200 0015
external_id : FRA-BLIP-BK2200 0015
Any idea on what I am missing here ? 

 

 
Hi Everyone,

Please help me with test class.


global class Constants
{
    // -------- Constants --------    
    // Diagnostic
    public static final String ENTERING = 'Entering: ';
    public static final String EXITING = 'Exiting: ';
    public static final String LOG = 'Diagnostics Log:\n';
    public static final String START_ERROR = 'Exception occurred: ';
    
    // From lead triggers
    public static final String CONVERT_LEAD_DEFAULT_OCR_ROLE = 'Other';
    public static final String LEAD_OPEN_STATUS = 'Open';
    public static final String LEAD_REJECTED_STATUS = 'Rejected';
    public static final String LEAD_REENGAGE_STATUS = 'Re-engage';
    public static final String LEAD_STAGE_SAL = 'Sales Accepted Lead';
    public static final String LEAD_STAGE_SQO = 'Sales Qualified Opportunity';
    public static final String LEAD_STAGE_MQL = 'Marketing Qualified Lead';
    public static final String LEAD_SUBSCRIPTION_UNSUBSCRIBED = 'Unsubscribed';
    public static final String LEAD_SUBSCRIPTION_SUBSCRIBED = 'Subscribed';
    public static final String LEAD_VLP_STATUS = 'VLP';
    
    // Scheduling helpers
    public static final String WEEKLY = 'Weekly';
    public static final String DAILY = 'Daily';
    public static final String HOURLY = 'Hourly';
    
    public static final String MONDAY = 'Monday';
    public static final String TUESDAY = 'Tuesday';
    public static final String WEDNESDAY = 'Wednesday';
    public static final String THURSDAY = 'Thursday';
    public static final String FRIDAY = 'Friday';
    public static final String SATURDAY = 'Saturday';
    public static final String SUNDAY = 'Sunday';
    public static final String MON = 'MON';
    public static final String TUE = 'TUE';
    public static final String WED = 'WED';
    public static final String THU = 'THU';
    public static final String FRI = 'FRI';
    public static final String SAT = 'SAT';
    public static final String SUN = 'SUN';
    
    public static final String AM12 = '12:00 AM';
    public static final String AM1 = '01:00 AM';
    public static final String AM2 = '02:00 AM';
    public static final String AM3 = '03:00 AM';
    public static final String AM4 = '04:00 AM';
    public static final String AM5 = '05:00 AM';
    public static final String AM6 = '06:00 AM';
    public static final String AM7 = '07:00 AM';
    public static final String AM8 = '08:00 AM';
    public static final String AM9 = '09:00 AM';
    public static final String AM10 = '10:00 AM';
    public static final String AM11 = '11:00 AM';
    public static final String PM12 = '12:00 PM';
    public static final String PM1 = '01:00 PM';
    public static final String PM2 = '02:00 PM';
    public static final String PM3 = '03:00 PM';
    public static final String PM4 = '04:00 PM';
    public static final String PM5 = '05:00 PM';
    public static final String PM6 = '06:00 PM';
    public static final String PM7 = '07:00 PM';
    public static final String PM8 = '08:00 PM';
    public static final String PM9 = '09:00 PM';
    public static final String PM10 = '10:00 PM';
    public static final String PM11 = '11:00 PM';
    public static final String MIL_AM12 = '0';
    public static final String MIL_AM1 = '1';
    public static final String MIL_AM2 = '2';
    public static final String MIL_AM3 = '3';
    public static final String MIL_AM4 = '4';
    public static final String MIL_AM5 = '5';
    public static final String MIL_AM6 = '6';
    public static final String MIL_AM7 = '7';
    public static final String MIL_AM8 = '8';
    public static final String MIL_AM9 = '9';
    public static final String MIL_AM10 = '10';
    public static final String MIL_AM11 = '11';
    public static final String MIL_PM12 = '12';
    public static final String MIL_PM1 = '13';
    public static final String MIL_PM2 = '14';
    public static final String MIL_PM3 = '15';
    public static final String MIL_PM4 = '16';
    public static final String MIL_PM5 = '17';
    public static final String MIL_PM6 = '18';
    public static final String MIL_PM7 = '19';
    public static final String MIL_PM8 = '20';
    public static final String MIL_PM9 = '21';
    public static final String MIL_PM10 = '22';
    public static final String MIL_PM11 = '23';
    
    public static final String JAN = 'JAN';
    public static final String FEB = 'FEB';
    public static final String MAR = 'MAR';
    public static final String APR = 'APR';
    public static final String MAY = 'MAY';
    public static final String JUN = 'JUN';
    public static final String JUL = 'JUL';
    public static final String AUG = 'AUG';
    public static final String SEP = 'SEP';
    public static final String OCT = 'OCT';
    public static final String NOV = 'NOV';
    public static final String DEC = 'DEC';
    public static final String LABEL_JANURARY = 'Janurary';
    public static final String LABEL_FEBRUARY = 'February';
    public static final String LABEL_MARCH = 'March';
    public static final String LABEL_APRIL = 'April';
    public static final String LABEL_MAY = 'May';
    public static final String LABEL_JUNE = 'June';
    public static final String LABEL_JULY = 'July';
    public static final String LABEL_AUGUST = 'August';
    public static final String LABEL_SEPTEMBER = 'September';
    public static final String LABEL_OCTOBER = 'October';
    public static final String LABEL_NOVEMBER = 'November';
    public static final String LABEL_DECEMBER = 'December';
    
    // -------- Constructor --------
    // None

    // -------- Variables --------
    // None
    
    // -------- Properties --------
    // None
    
    // -------- Methods --------
    // Return a select option list of days
    public static List<SelectOption> buildListOfDays()
    {
        List<SelectOption> result = new List<SelectOption>();
        result.add(new SelectOption(Constants.MON, Constants.MONDAY));
        result.add(new SelectOption(Constants.TUE, Constants.TUESDAY));
        result.add(new SelectOption(Constants.WED, Constants.WEDNESDAY));
        result.add(new SelectOption(Constants.THU, Constants.THURSDAY));
        result.add(new SelectOption(Constants.FRI, Constants.FRIDAY));
        result.add(new SelectOption(Constants.SAT, Constants.SATURDAY));
        result.add(new SelectOption(Constants.SUN, Constants.SUNDAY));
        
        return result;
    } 
    
    // Return a set of days
    public static Set<String> buildSetOfDays()
    {
        Set<String> result = new Set<String>();
        result.add(Constants.MON);
        result.add(Constants.TUE);
        result.add(Constants.WED);
        result.add(Constants.THU);
        result.add(Constants.FRI);
        result.add(Constants.SAT);
        result.add(Constants.SUN);
        
        return result;
    }
    
    // Return a select options list of hours
    public static List<SelectOption> buildListOfHours()
    {
        List<SelectOption> result = new List<SelectOption>();
        result.add(new SelectOption(Constants.MIL_AM12, Constants.AM12));
        result.add(new SelectOption(Constants.MIL_AM1, Constants.AM1));
        result.add(new SelectOption(Constants.MIL_AM2, Constants.AM2));
        result.add(new SelectOption(Constants.MIL_AM3, Constants.AM3));
        result.add(new SelectOption(Constants.MIL_AM4, Constants.AM4));
        result.add(new SelectOption(Constants.MIL_AM5, Constants.AM5));
        result.add(new SelectOption(Constants.MIL_AM6, Constants.AM6));
        result.add(new SelectOption(Constants.MIL_AM7, Constants.AM7));
        result.add(new SelectOption(Constants.MIL_AM8, Constants.AM8));
        result.add(new SelectOption(Constants.MIL_AM9, Constants.AM9));
        result.add(new SelectOption(Constants.MIL_AM10, Constants.AM10));
        result.add(new SelectOption(Constants.MIL_AM11, Constants.AM11));
        result.add(new SelectOption(Constants.MIL_PM12, Constants.PM12));
        result.add(new SelectOption(Constants.MIL_PM1, Constants.PM1));
        result.add(new SelectOption(Constants.MIL_PM2, Constants.PM2));
        result.add(new SelectOption(Constants.MIL_PM3, Constants.PM3));
        result.add(new SelectOption(Constants.MIL_PM4, Constants.PM4));
        result.add(new SelectOption(Constants.MIL_PM5, Constants.PM5));
        result.add(new SelectOption(Constants.MIL_PM6, Constants.PM6));
        result.add(new SelectOption(Constants.MIL_PM7, Constants.PM7));
        result.add(new SelectOption(Constants.MIL_PM8, Constants.PM8));
        result.add(new SelectOption(Constants.MIL_PM9, Constants.PM9));
        result.add(new SelectOption(Constants.MIL_PM10, Constants.PM10));
        result.add(new SelectOption(Constants.MIL_PM11, Constants.PM11));
        
        return result;
    }
    
    // Return a set of hours
    public static Set<String> buildSetOfHours()
    {
        Set<String> result = new Set<String>();
        result.add(Constants.MIL_AM12);
        result.add(Constants.MIL_AM1);
        result.add(Constants.MIL_AM2);
        result.add(Constants.MIL_AM3);
        result.add(Constants.MIL_AM4);
        result.add(Constants.MIL_AM5);
        result.add(Constants.MIL_AM6);
        result.add(Constants.MIL_AM7);
        result.add(Constants.MIL_AM8);
        result.add(Constants.MIL_AM9);
        result.add(Constants.MIL_AM10);
        result.add(Constants.MIL_AM11);
        result.add(Constants.MIL_PM12);
        result.add(Constants.MIL_PM1);
        result.add(Constants.MIL_PM2);
        result.add(Constants.MIL_PM3);
        result.add(Constants.MIL_PM4);
        result.add(Constants.MIL_PM5);
        result.add(Constants.MIL_PM6);
        result.add(Constants.MIL_PM7);
        result.add(Constants.MIL_PM8);
        result.add(Constants.MIL_PM9);
        result.add(Constants.MIL_PM10);
        result.add(Constants.MIL_PM11);
        
        return result;
    }
    
    // Build list of months for select options
    public static List<SelectOption> buildListOfMonths()
    {
        List<SelectOption> result = new List<SelectOption>();
        result.add(new SelectOption(Constants.JAN, Constants.LABEL_JANURARY));
        result.add(new SelectOption(Constants.FEB, Constants.LABEL_FEBRUARY));
        result.add(new SelectOption(Constants.MAR, Constants.LABEL_MARCH));
        result.add(new SelectOption(Constants.APR, Constants.LABEL_APRIL));
        result.add(new SelectOption(Constants.MAY, Constants.LABEL_MAY));
        result.add(new SelectOption(Constants.JUN, Constants.LABEL_JUNE));
        result.add(new SelectOption(Constants.JUL, Constants.LABEL_JULY));
        result.add(new SelectOption(Constants.AUG, Constants.LABEL_AUGUST));
        result.add(new SelectOption(Constants.SEP, Constants.LABEL_SEPTEMBER));
        result.add(new SelectOption(Constants.OCT, Constants.LABEL_OCTOBER));
        result.add(new SelectOption(Constants.NOV, Constants.LABEL_NOVEMBER));
        result.add(new SelectOption(Constants.DEC, Constants.LABEL_DECEMBER));
        
        return result;
    }
    
    // Build a set of months
    public static Set<String> buildSetOfMonths()
    {
        Set<String> result = new Set<String>();
        result.add(Constants.JAN);
        result.add(Constants.FEB);
        result.add(Constants.MAR);
        result.add(Constants.APR);
        result.add(Constants.MAY);
        result.add(Constants.JUN);
        result.add(Constants.JUL);
        result.add(Constants.AUG);
        result.add(Constants.SEP);
        result.add(Constants.OCT);
        result.add(Constants.NOV);
        result.add(Constants.DEC);
    
        return result;
    }
    
    // -------- Internal Classes --------
    // None
}
HI ,

I am getting the below Error when trying to upsert a User record linked to a Contact:

Unable to create/update fields: ContactId. Please check the security settings of this field and verify that it is read/write for your profile or permission set.

I am able to push the User for the first time when it gets created but when any other field is modified and the record is getting updated it gives the above error even when I am not updating/modifying "ContactId" field.

Any help will be appreciated.

Thanks,
Darpesh

 
Hello Guys,
I am working on Countdown timer, On clicking Save, I am fetching the time from Time__c field and on clicking save the timer will start counting down and once it becomes 0, a pop up will come. If I enter 10 in Time__c field then countdown should start from 10.
<apex:page standardController="Timer_Alert__c">
 <apex:form >
   <apex:pageblock >
      <apex:pageMessages id="showmsg"></apex:pageMessages>
         <apex:panelGrid columns="2">
           Timer_Alert__c Time: <apex:inputText value="{!Timer_Alert__c.Time__c}"/>
           <apex:commandButton value="Save" action="{!save}" oncomplete="timer()" style="width:90px" rerender="showmsg"/>
         </apex:panelGrid>
                     <div align="center" draggable="false" >
         <script>
    function startTimer(duration, display) {
        var start = Date.now(),
            diff,
            minutes,
            seconds;
        function timer() {
            diff = duration - (((Date.now() - start) / 1000) | 0);
            
            minutes = (diff / 60) | 0;
            seconds = (diff % 60) | 0;
            
            minutes = minutes < 10 ? "0" + minutes : minutes;
            seconds = seconds < 10 ? "0" + seconds : seconds;
            
            display.textContent = minutes + ":" + seconds; 
            
            if (diff <= 0) {
                start = Date.now() + 1000;
            }
            if(diff==0){
                alert('STOP!!!');
                clearInterval(interval);
            }
        };
        timer();
        var interval = setInterval(timer, 1000);
    }
    
    window.onload = function () {
        var fiveMinutes = 60 * {!Timer_Alert__c.Time__c},
            display = document.querySelector('#time');
        startTimer(fiveMinutes, display);
    };
    </script>
    <style>
        h1 {
        font-size: 40px;
        text-align: center;
        background-color: orange;
        }
    </style>
    
    <style>
        h1 {
            font-size: 40px;
            text-align: center;
            background-color: orange;
        }
    </style>

            </div>
    </apex:pageblock>
 </apex:form>
</apex:page>


I have created the following VF Page but its not working, can anyone help me with the same.
How to create a custom field where i can populate the call centre information on the # of calls recived  within 15 min period over a 24 hour time period.??
 
Hi,
What is the best practice to generate JSON string for HTTP callouts? The options I know are:
1) Using String variables and methods
2) Use JSON.serialize function after defining a class
3) Use JSONGenerator
Using the above 3 methods, if we need to change the request, we have to change the code. Is there any other good solution so that the code need not be chaged even if the JSON request needs to be changed?
What is the best practice in generating JSON request?
Thanks.