• Behzad Bahadori 18
  • NEWBIE
  • 155 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 51
    Questions
  • 67
    Replies
when i am sending a post salesforce doesnt accept these. the rest of the fields are supposed to be currancy even tho they are parsfloat, salesforce still fails to submits it. when I hard core the values ex email "sdf@gmail.com" or for currency ones I do parsFloat('11') it succesfully submits. I dont know what I am donig wrong in my jquery formatting for the object
<apex:outputLabel value="Email" /> <input id="contactEmail" required="true"/> <apex:outputLabel value="Voice_MRC__c" /> <input id="Voice_MRC__c" /> <apex:outputLabel value="Bandwidth_MRC__c" /> <input id="Bandwidth_MRC__c" /> <apex:outputLabel value="Hardware_MRC__c" /> <input id="Hardware_MRC__c" /> "email": $('[id*="contactEmail"]').val() "Voice_MRC__c": parseFloat($('[id*="Voice_MRC__c"]').val()), "Bandwidth_MRC__c": parseFloat($('[id*="Bandwidth_MRC__c"]').val()), "Hardware_MRC__c": parseFloat($('[id*="Hardware_MRC__c"]').val()),

 
I am trying to create New Account, Then Contact and Opportunity that is assigned to that account . but use Post method, so have them all in one page. I dont wanna create any class, I know I can do Account using method as it follows, however I am not sure if I can do the samething to create new contact and opportunity since I need account ID. Ill put fields on the page to ask user to enter new information
function createSobjectRecord() {
var accountInfo = {
    "Name": "Testing Jquery with Rest"
};
var accountInfoJson = JSON.stringify(accountInfo);
$j.ajax({
    type: "POST",
    url: "/services/data/v35.0/sobjects/Account",
    headers: {
        'Authorization': "OAuth " + sessionId,
        'Content-Type': 'application/json'
    },
    crossDomain: true,
    data: JSON.stringify(accountInfo),
    dataType: 'json',
    success: function(responseData, status, xhr) {
        console.log(responseData);
    },
    error: function(request, status, error) {
        console.log(request.responseText);
    }
});

​

 
I have this method
 
public PageReference selectBandwidth() {

    if (!BandwidthQualified
        || prequalToSave == null
        || servicesToAdd == null
        || (prequalToSave != null && prequalToSave.IsComplete__c && servicesToAdd.size() == 0))
    {
        return Page.PBXOrderingQuotePdf;
    }


    Decimal bandServicesSel = 0;

    if (servicesToAdd != null)
    {
        for (Service__c service : servicesToAdd)
        {
            if (service.IsSelected__c)
                bandServicesSel += 1;
        }
    }

        showPageMessage = false;
        pageMessage = '';

    if (!String.isBlank(qotId)) { 
        qot = [select Id, Pricebook2Id, Name from Quote where Id = :qotId];

    }
    else if (!isVoiceBeingAdded)
    {
        if (qot.Name == null)
            qot.Name = 'No Name';
        qot.BillingCity = city;
        qot.BillingState = state ;
        qot.BillingPostalCode = zip ;

        qot.BillingStreet = addressLine1 + ' ' + unitType + ' ' + unitValue ;
        qot.ShippingCity =  account.ShippingCity; 
        qot.ShippingCountry = account.ShippingCountry;
        qot.ShippingStreet = account.ShippingStreet;
        qot.ShippingState = account.ShippingState;
        qot.ShippingPostalCode = account.ShippingPostalCode;


        insert qot;
        url = '/apex/QuotePDF?id=' + qot.Id;
    }

    List<PricebookEntry> products = [Select Id, ProductCode , IsActive, Product2Id, UnitPrice, Name from PricebookEntry where Pricebook2Id =: qot.Pricebook2Id];

    if (servicesToAdd != null)
    {
        System.debug('I am inside the Service and service has been added 1');
        for (Service__c service : servicesToAdd)
        {
             System.debug('I am inside the Service and service has been added 2' + servicesToAdd );
            if (service.IsSelected__c)
            {
                 System.debug('I am inside the Service and service has been added 3 service.IsSelected__c' );

                for (PricebookEntry entry : products)
                {
                    System.debug('entry.ProductCode Counter' + entry.ProductCode);
                    if (entry.ProductCode == 'internetAccessWizard')

                    {



                        QuoteLineItem quoteLineItem = new QuoteLineItem();
                        quoteLineItem.QuoteId = qot.Id;
                        quoteLineItem.PricebookEntryId = entry.Id;
                        quoteLineItem.Product2Id = entry.Product2Id;
                        quoteLineItem.Quantity = 1;
                        quoteLineItem.UnitPrice = service.Price__c;
                                                   quoteLineItem.Enter_Activation__c = service.SetupPrice__c;
                        quoteLineItem.Activation_Fee_CheckBox__c = true;
                        quoteLineItem.Term_Area__c = service.ContractLength__c;
                        System.debug(' Contract Term ' +  quoteLineItem.Term_Area__c );



                        if(service.SubType__c.contains('test')){
                            quoteLineItem.Internet_Service_Fee__c = 2.88;
                            quoteLineItem.Internet_Service_Fee_CheckBox__c = true;
                        }
                        else{

                            quoteLineItem.It_HAS_FSLS_checkBox__c = true;


                        }



                        insert quoteLineItem;

                    }
                }



                bandServicesSel += 1;
            }
        }
    }


   return Page.PBXOrderingQuotePdf;
}
Unit Test
 
static testmethod void selectBandwidth_Test(){
     OpportunityController controller = new OpportunityController();
     controller.BandwidthQualified = false;

    Product2 prod = new Product2();
    prod.Name = 'Laptop X200'; 
    prod.IsActive = true;
    prod.ProductCode  = 'Feature';

    insert prod;

        id customPB = Test.getStandardPricebookId();

    Opportunity opp = new Opportunity();
    opp.Name = 'Test';
    opp.StageName='Quote Sent';
    opp.CloseDate = system.today();
    opp.Pricebook2Id = customPB;
    insert opp;

    Quote quote = new Quote();
    quote.Name='test';
    quote.Opportunityid = opp.id;     
    quote.ExpirationDate = date.today()+30;        
    quote.Pricebook2Id = customPB;

    //insert quote;

    controller.isVoiceBeingAdded = false;






    PricebookEntry customPrice = new PricebookEntry(
        Pricebook2Id = customPB, Product2Id = prod.Id,
        UnitPrice = 12000, IsActive = true);

    insert customPrice;

    controller.qot = quote;
     controller.selectBandwidth();
 }


I am not sure what else to add
I have a javascript object that looks like this
this will be used in an ajax called in javascript  data: JSON.stringify(address) and submitted
var address = { location: { 
                                    phoneNumber: "", 
                                    address: {
                                    line1: $( "line1" ).val(),
                                    city: $( "city" ).val(), 
                                    state: $( "state" ).val(), 
                                    postalCode: $( "postalCode" ).val(),
                                    country: "US", 

                                            }
                                  }, 
                        networks: ["1", "2","3","4","5"],  
                        company: "Salesforce"
                      };

what I need to do is samething but in apex code with custom object but not sure how I can format it same way

qualRequest = new prequalAPI.QualificationRequest();   
qualRequest.CustomerId = 0;
            qualRequest.PhoneNumber = 'STANDALONE';
            qualRequest.AddressLine1 = addressLine1;

            if (unitType != null)
            {
                qualRequest.UnitType = unitType;
            }

            if (unitValue != null)
            {
                qualRequest.UnitValue = unitValue;
            }

            qualRequest.City = city;
            qualRequest.State = state;
            qualRequest.ZipCode = zip;
            qualRequest.Country = country;
            qualRequest.UnitType = unitType;
            qualRequest.RequestedNetworkNames = new List<String>();
            qualRequest.RequestedNetworkNames.add('1');
            qualRequest.RequestedNetworkNames.add('2');
            qualRequest.RequestedNetworkNames.add('3');
            qualRequest.RequestedNetworkNames.add('4');
            qualRequest.RequestedNetworkNames.add('5');

JSON.serialize(qualRequest);
my request status fails right now because json is not same format. 
Hi, I am adding a new drop down field to Contacts object. The drop down is Defaulted to Yes. I need to have all the old records in contact to be updated to Yes value as well. do i write a trigger? if so how do I write it?
Currently I am trying to block certain profiles from changing UnitPrice within Quote. I used validation rules under customize> QuoteLineItem and worked perfectly fine. However those validation rules only work when the product has been already added. The Issue I have right now; is when the user adds a product inside quote by clicking on "Add Line Item" they are prompted to a page where they can enter quantity. There is also a UnitPrice there as well. They are still allowed to change the price. I am not sure how i can access that page and how I can disable that field within the page. I thought the below trigger could do it, but I am not sure how to add certain profile or even where do i add that trigger to for this page.
User-added image
how do I add profile to this, and also this didnt work 
 
OR( 
AND(ISNEW(), NOT(ISNULL(UnitPrice)), 
AND(NOT(ISNEW()), ISCHANGED(UnitPrice))) 
)


 
Once a user creates a quote, they may add product by clicking on Add Line Item.  Once they click on that button the will be prompted to go to next page where they can select different product/s. After they have selected the products,  user then can enter in the quantity or change the price of the product right there. How can I access those fields in that page and write validation ruels in that page?
Hi is there anyway that I can make the SalesPrice field on Quote Line Item, read only so nobody can override it besides Syestem Administrator. I cant make the field read only by going to the Layout . Maybe  a trigger?
I don't konw whether there are some error in my code, so does anyone have experiences about use jquery.ajax in Visualforce or how to post a request to an external service in Visualforce?
When this code execute, I receieve the response with error method: textStatus : error XMLHttpRequest.readyState : 0 XMLHttpRequest.status : 0
 
$.ajax({
     type: "POST",
     url: 'https://www.me.com/qualification', // outside Domain
     headers: {"Accept" : "application/json",
                "Content-Type": "application/json" },
     data: JSON.stringify(address),
     crossDomain : true,
     dataType: 'json',
     success: function (responseData) {
        console.log(responseData);
    getAddresses();

    },
    error: function (request, status, error) {
        console.log(request.responseText);
        console.log(status);
        console.log(error);
        var result = $("#selections").append("Sorry, Something in the system has gone wrong , Please try again Later");
        console.log("Sorry, Something in the system has gone wrong , Please try again Later");
    }

});

 
I have the following ajax call that I am sending to an outside domain. but it straights goes to error function is there something that I am missing . I have added the url into remote setting
 
$.ajax({
             type: "POST",
             url: 'https://xxx.xxx.xxx/qualification',
             headers: {"Accept" : "application/json",
                        "Content-Type": "application/json" },
             data: JSON.stringify(address),
             crossDomain : true,
             dataType: 'json',
             success: function (responseData) {
                console.log(responseData);
            getAddresses();

            },
            error: function (request, status, error) {
                console.log(request.responseText);
                console.log(status);
                console.log(error);
                var result = $("#selections").append("Sorry, Something in the system has gone wrong , Please try again Later");
                console.log("Sorry, Something in the system has gone wrong , Please try again Later");
            }

        });
the error "Sorry, Something in the system has gone wrong , Please try again Later" but in console I also get this. I am not sure if there anything script cdn i need to include or if the format is wrong. any hint is really appriciated 

<message collected>
error
 <message collected>
How can I have the apex page make a http request within salesfroce for a salesforce feild using the   OAuth and bearer of the user that have loggedin  . 
Hi how do I write a Unit test for the following Method
public String Account{get;set;}
public List<Account> AccountId{get;set;}
public Account a{get;set;}

  public PageReference step2()
    {
        
         if (Account != Null ){

    
        sandAccountId = [select Id  from Account where Name = : Account];

        for (Account a : AccountId){
        account.ParentId = a.Id;
       
            }

        }   
        qot = new Quote();
           qot.ExpirationDate = date.today() + 30;
        return Page.newOpptyStep2;
    }
Hi I get the following error for pageblockSectionItem. I need to make this fields visible only for certain profiles  I have few more selectOptin that I need to add
Error " Error: <apex:pageBlockSectionItem> may have no more than 2 child components"
<apex:pageBlockSectionItem rendered="{!IF($UserRole.Name =='User' || $UserRole.Name =='Salesforce Administrator'  , true , false)}">
      <td class="labelCol" style="border-bottom:0px;">
                  <apex:outputLabel value="Expiration Date (Mo/Yr)"/>
                </td>
                <td class="data2Col" style="border-bottom:0px;">
                <apex:selectList id="sandler"  value="{!sandlerAccount}" size="1">
                    <apex:selectOption itemValue="" itemLabel="-- None --"/>
                    <apex:selectOption itemValue="test" itemLabel="tt/>
                    <apex:selectOption itemValue="test2" itemLabel="tt"/>     
        
                </apex:selectList>

        </td>

 
I have the following drop down, and I want to send the value of the selected file to my controller .. so if the user selects parent account1 my controller should get that value or if they select parent account2 samething 
<label>Select the Region</label>
                </td>
                <td class="data2Col" style="border-bottom:0px;">
                    <select id="sandler" class="sandler" value="{!regionAccount}">
            <option value=""></option>
            <option value='ParentAccount1'>asdf--zz</option>
            <option value='ParentAccount2'>ggggg</option>
        
        </select>
        </td>
// Recieve the Region Value from Visual Force Page.. 
   public String regionAccount{get;set;}
    public Account regionAccountId{get;set;}
// if regional is not empty 
if (regionAccount != Null ){


      // get the value of region and find the accountId
        regionAccountId = [select Id  from Account where Name = : regionAccount];
        account.ParentId =regionAccountId.Id;
    
 
        }
        else{
        for (Contact parents : parentAccount)
        {
            System.debug('Now I get to here part 2');
            account.ParentId = parents.AccountId;
        }
    }


 
I created work flows with Formulas and validation . however it still gets triggered even tho I am saying those ownerId shouldnt be part of it

OR ( 
Owner.Id <> "00516000006OnYB" , 
Owner.Id <> "005G0000002YHAe" , 
Owner.Id <> "005G0000005Foy2" , 
Owner.Id <> "00516000006Tdoh" , 
Owner.Id <> "005G0000004qehs" ) && 
Order_Paperwork_Complete__c = TRUE

so even tho it shouldnt be != and not get trigged  but any of those guys submit and it will get triggered still  
When I am searching for a parent account ,there is usually a magnifier glass that allows the users to search for the parent. for some reason my VF page doesn't show the magnifier glass. the code works . If I enter a wrong parent name it will not let me submit and it tells me that its wrong name but the magnifier glass which is suppose to help me search for the parent account name, doesn't display on my page
 
​<apex:pageBlockSectionItem rendered="{!IF($Profile.Name =='test', false , true)}"> <apex:outputLabel value="Parent Account" for="acctparent" /> 
<apex:inputField id="acctparent" value="{!account.ParentId}" /> </apex:pageBlockSectionItem>

 
I need to Query the Last notes and attachments that was added in a Quote, into a PDF, I dont now how to query that , any suggestions?
if you go to  Opportunity, Select an opportunity, click on the quote at the end of the page there is a quote line Item section , if you click on edit by any Items in that area it will take you to a page with few different options, I need to modify and remove some of those fields. I am not sure how to access the area. its not any of those mini layout thing , i tried those in quote Line item page layout edit
How do I write a unit test for 
QuoteDocument qd = new QuoteDocument();
        qd = [SELECT CreatedById, CreatedDate, IsDeleted, Discount, GrandTotal, LastModifiedById, LastModifiedDate, Name, Document, QuoteId, Id, SystemModstamp 
              FROM QuoteDocument 
              WHERE QuoteId =: urlId
        Limit 1];
     
         blst.add(EncodingUtil.base64Encode(qd.Document));
         System.debug('the size of the file' + qd.Document.size());


           
        
         String formatJSON = JSON.serializePretty(blst);

record = new Document( FolderId = UserInfo.getUserId() ,AuthorId=UserInfo.getUserId(), Name = Name +'_' + datetime.now() +'.pdf', Body = b  ,ContentType='application/pdf;charset=UTF-8');

        
        System.debug('Record' + record);
        insert record;

 
I have a list and list should Contain a certain document that has an ID 


    List<String> blst = new List<String>();
    

      System.debug('inside the empty folder to set up the proposal');
                c = [SELECT Id, Name, Body
                         from Document
                        Where Id =: FoId];  
                        System.debug('Adding one file to the PDF ');
                blst.add(EncodingUtil.base64Encode(c.Body)); 
        

my unit test its keep telling me the id is empty even tho I make sure FoID is assign

Unit test FoId= '123456';

how can I test that 
I have a javascript object that looks like this
this will be used in an ajax called in javascript  data: JSON.stringify(address) and submitted
var address = { location: { 
                                    phoneNumber: "", 
                                    address: {
                                    line1: $( "line1" ).val(),
                                    city: $( "city" ).val(), 
                                    state: $( "state" ).val(), 
                                    postalCode: $( "postalCode" ).val(),
                                    country: "US", 

                                            }
                                  }, 
                        networks: ["1", "2","3","4","5"],  
                        company: "Salesforce"
                      };

what I need to do is samething but in apex code with custom object but not sure how I can format it same way

qualRequest = new prequalAPI.QualificationRequest();   
qualRequest.CustomerId = 0;
            qualRequest.PhoneNumber = 'STANDALONE';
            qualRequest.AddressLine1 = addressLine1;

            if (unitType != null)
            {
                qualRequest.UnitType = unitType;
            }

            if (unitValue != null)
            {
                qualRequest.UnitValue = unitValue;
            }

            qualRequest.City = city;
            qualRequest.State = state;
            qualRequest.ZipCode = zip;
            qualRequest.Country = country;
            qualRequest.UnitType = unitType;
            qualRequest.RequestedNetworkNames = new List<String>();
            qualRequest.RequestedNetworkNames.add('1');
            qualRequest.RequestedNetworkNames.add('2');
            qualRequest.RequestedNetworkNames.add('3');
            qualRequest.RequestedNetworkNames.add('4');
            qualRequest.RequestedNetworkNames.add('5');

JSON.serialize(qualRequest);
my request status fails right now because json is not same format. 
Currently I am trying to block certain profiles from changing UnitPrice within Quote. I used validation rules under customize> QuoteLineItem and worked perfectly fine. However those validation rules only work when the product has been already added. The Issue I have right now; is when the user adds a product inside quote by clicking on "Add Line Item" they are prompted to a page where they can enter quantity. There is also a UnitPrice there as well. They are still allowed to change the price. I am not sure how i can access that page and how I can disable that field within the page. I thought the below trigger could do it, but I am not sure how to add certain profile or even where do i add that trigger to for this page.
User-added image
how do I add profile to this, and also this didnt work 
 
OR( 
AND(ISNEW(), NOT(ISNULL(UnitPrice)), 
AND(NOT(ISNEW()), ISCHANGED(UnitPrice))) 
)


 
I have the following ajax call that I am sending to an outside domain. but it straights goes to error function is there something that I am missing . I have added the url into remote setting
 
$.ajax({
             type: "POST",
             url: 'https://xxx.xxx.xxx/qualification',
             headers: {"Accept" : "application/json",
                        "Content-Type": "application/json" },
             data: JSON.stringify(address),
             crossDomain : true,
             dataType: 'json',
             success: function (responseData) {
                console.log(responseData);
            getAddresses();

            },
            error: function (request, status, error) {
                console.log(request.responseText);
                console.log(status);
                console.log(error);
                var result = $("#selections").append("Sorry, Something in the system has gone wrong , Please try again Later");
                console.log("Sorry, Something in the system has gone wrong , Please try again Later");
            }

        });
the error "Sorry, Something in the system has gone wrong , Please try again Later" but in console I also get this. I am not sure if there anything script cdn i need to include or if the format is wrong. any hint is really appriciated 

<message collected>
error
 <message collected>
I have the following drop down, and I want to send the value of the selected file to my controller .. so if the user selects parent account1 my controller should get that value or if they select parent account2 samething 
<label>Select the Region</label>
                </td>
                <td class="data2Col" style="border-bottom:0px;">
                    <select id="sandler" class="sandler" value="{!regionAccount}">
            <option value=""></option>
            <option value='ParentAccount1'>asdf--zz</option>
            <option value='ParentAccount2'>ggggg</option>
        
        </select>
        </td>
// Recieve the Region Value from Visual Force Page.. 
   public String regionAccount{get;set;}
    public Account regionAccountId{get;set;}
// if regional is not empty 
if (regionAccount != Null ){


      // get the value of region and find the accountId
        regionAccountId = [select Id  from Account where Name = : regionAccount];
        account.ParentId =regionAccountId.Id;
    
 
        }
        else{
        for (Contact parents : parentAccount)
        {
            System.debug('Now I get to here part 2');
            account.ParentId = parents.AccountId;
        }
    }


 
I need to Query the Last notes and attachments that was added in a Quote, into a PDF, I dont now how to query that , any suggestions?
How do I write a unit test for 
QuoteDocument qd = new QuoteDocument();
        qd = [SELECT CreatedById, CreatedDate, IsDeleted, Discount, GrandTotal, LastModifiedById, LastModifiedDate, Name, Document, QuoteId, Id, SystemModstamp 
              FROM QuoteDocument 
              WHERE QuoteId =: urlId
        Limit 1];
     
         blst.add(EncodingUtil.base64Encode(qd.Document));
         System.debug('the size of the file' + qd.Document.size());


           
        
         String formatJSON = JSON.serializePretty(blst);

record = new Document( FolderId = UserInfo.getUserId() ,AuthorId=UserInfo.getUserId(), Name = Name +'_' + datetime.now() +'.pdf', Body = b  ,ContentType='application/pdf;charset=UTF-8');

        
        System.debug('Record' + record);
        insert record;

 
I have a list and list should Contain a certain document that has an ID 


    List<String> blst = new List<String>();
    

      System.debug('inside the empty folder to set up the proposal');
                c = [SELECT Id, Name, Body
                         from Document
                        Where Id =: FoId];  
                        System.debug('Adding one file to the PDF ');
                blst.add(EncodingUtil.base64Encode(c.Body)); 
        

my unit test its keep telling me the id is empty even tho I make sure FoID is assign

Unit test FoId= '123456';

how can I test that 
How Do I make a test case for this 
public String ourl {get;set;}
	public String url {get;set;} 
	Blob content;
	public NewPdfQuote() {

		url = ApexPages.currentPage().getParameters().get('qotId');
		generateNewQuotePDF();

	}

	     public  QuoteDocument generateNewQuotePDF(){
          
        ourl = '/apex/QuotePDF?id=' + url ;

        System.debug('ourl   ' + ourl);

        PageReference pr = Page.QuotePDF;
        pr.getParameters().put('id', url);

        System.debug('saveQuote() Quote: ' + url);

        if (!Test.isRunningTest())
            content = pr.getContentAsPDF();
        else
            content = Blob.valueOf('Unit Test Attachment Body');

       
         //emailURL = '/_ui/core/email/author/EmailAuthor?p3_lkid=' + urlId + '&doc_id=' + record.Id + '&retURL=%2F' + urlId ;
        return NULL;
  
    }

    	 public PageReference sendQuote()
   			 {
				     QuoteDocument doc1 = new QuoteDocument(Document = content, QuoteId = url);

				       // Database.SaveResult insertResult = Database.Insert(doc, false);
				        insert doc1;
				        return NULL;
		}

 
Hi , I have created Custom pdf with a wizard that we use , but now I need to create custom button inside Quote which gets the Quoteline Item , or the Quote ID and pas it to my PDF, I dont knwo how I can make button that will get atleast Quote ID . if I get the Quote ID I might be able to to just pass that to my PDF Apex and create new one

Is there any way to get the profile name of logged in user without querying the user object.

 

I know the following solution:

 

String usrProfileName = [select u.Profile.Name from User u where u.id = :Userinfo.getUserId()].Profile.Name;

 

Instead of this I want to save 1 query so if there is any method to get the profile name in apex without firing the query please let me know.

 

Thanks,