• Semira@gmail.com
  • NEWBIE
  • 215 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 2
    Likes Given
  • 59
    Questions
  • 58
    Replies
Hi, 

I have a String variable in my controller call ChildQuery. I want to pass a value to the string variable from Visualforce page without any javascript or button. How can that be possible? This value needs to be hidden and auto assign as soon as the visualforce page is opened.  

//set the value of Childquery to "write some string value here like ABCD"  without calling <script></script>
// maybe using these tags below? 

<!-- apex:inputHidden  / -->
<!-- apex:param  / -->
<!-- apex:variable / -->

This is what my class would look like. I'm writing a generic class which would be used by many many different visualforce page. So cannot set the value of the variavle in the controller. It has to pass through the visualforce page so I can throw any page and just call this controller class. 
Class sObject {

public string ChildQuery {get; set;}

    public sObjectController(ApexPages.StandardController controller){
      
        system.debug('THIS IS THE VALUE I'M GETTING:' + ChildQuery);

    }

}



 
Hi all, 

This is kind of urgent. I'm using a Aura component and trying to pass an ID to a apex code. However, without using the aura, in classic, my code works like a charm. When I try to pass the value via aura, it does not. 

Below is my Aura Controller which is setting the URL. 
myAction : function(component, event, helper) {
        debugger;
		var action = component.get("c.getOpportunity");
        action.setParams({"OppId": component.get("v.recordId")});
        action.setCallback(this, function(response){
            var state = response.getState();
            if(component.isValid() && state == "SUCCESS"){
                var elem = response.getReturnValue();
                var redirectURL = "/apex/SubmitForApproval?id=" + elem.id;
                redirectURL += "&lock=0";
                
                var urlEvent = $A.get("e.force:navigateToURL");
                urlEvent.setParams({
                  "url": redirectURL
                });
                urlEvent.fire();
            } else {
                component.set("v.hasErrors", true);
                
            }
        });
        $A.enqueueAction(action);
	},

Below is my existing Apex code trying to modify:
public without sharing class SubmitForApprovalExtension {
    public Id objId { get; set; }
    public String doLock { get; set; }
    public SubmitForApprovalExtension(){

//below line is where I'm getting the error for objId
        objId = ApexPages.currentPage().getParameters().get('id');
        doLock = Apexpages.currentPage().getParameters().get('lock');
    }
    
-
-
-
-
-

//enabling the Aura controller

@AuraEnabled
    public static Opportunity getOpportunity(String OppId){
        Opportunity opp = [select Id from opportunity where Id =: OppId limit 1];
        return opp;
    }
}

I'm getting error message saying System.StringException: Invalid id: undefined. I have no idea what it means Undefined. When I put in the actualy Id of the record, it works fine.. Just the ApexPages.currentPage() will not work. Please help!!! 
 
Hello, 

I was asked to take a stab at implementing another system with Salesforce which will pull information from Salesforce Opportunity object into their mobile app. Since this is my very first time working with API's, I'm extremely lost on where to start. 

I read bunch of articles and the developer guide to understand the different API's and their use. However, my confusing is on what the first step is, I should be taking.

Problems or task at hand: We are looking at a mobile Timecard application, where users will use the app to login and pull up a Opportunity record (I'm guessing this is just the name of opportunity) and stamp their time to clock in and out of a job. I was provided with their TimeCard SOAP API documentation to take a look at the api's and the library. 

Questions
1. What is the first step should I be doing? (If I'm not wrong, I believe we will also be updating few fields on Opportunity after they have entered their time to clock in or out. If not Oppostunity record, then related object to Opportunity) 
2. What questions should I be asking them (the developer from Timecard app)? 
3. Do I write a webservice, generate Apex WSDL and give it to them? (Assuming data needs to go from Salesforce to their system)
4. I don't have any experience in .NET, do I need to? 
5. Why do I need to look at their API documentation? Are they assuming that I will be writing code on their end? Again, going back what should I be asking them? How does this usually work?
6. What do I do with the WSDL file when they give me their, if they do (steps by steps)? 

As you can tell I have never worked with webservices and api's but I think this is a very good opportunity for me to learn hands on and work with it. Even though it is very short amount of time to soak everything up, I am hoping someone will guide me to the right direction. Also, I do not have any mentor or go to person to ask since I'm the solo Salesforce person working here. SO, I will be needing lots of help. Any guidance will be truly appreciated! 

Thank you. 
Hi all, 

I have two save method, one just redirects to edit page and the other one save and close and returns to newly created record. However, problem is when I clone the record, the url has Clone = 1  https://atirestoration--fullcopy--c.cs13.visual.force.com/apex/BudgetSheet?clone=1  <--- This one

How do I redirect the record to erase that clone and take the user to edit page. Also, when I do that, Save and close or when I Cancel, page does not return to the main page and shows me a blank page. Please help me out. I'm so lost in this. I'm assuming it is not assigning the controller Id to redirect to the newly created record. How do I solve this? 

Here are my two methods:
public PageReference quickSaveBudget(){   
        
        PageReference pv;
        ID OldBudgetID = ExtCon.getID();
        
        ExtCon.save();
        
        try{
                   
            // Check if it is Save or Clone.
            // If CLone the execute clone line item
           // Then redirect to new budget ID.  
            
            if(OldBudgetID != ExtCon.getID()){
            
                cloneLineItem(ExtCon.getID(), OldBudgetID);     
                
                pv = new Pagereference('/'+ExtCon.getID());
                pv.setRedirect(true);

            }
            Else{
              saveLineItem(ExtCon.getID());
              getBudgetLineItem();
              pv = null;
            }

            system.debug('What is the pv returning? '+ pv);
            
            
        }catch(Exception e){
            ApexPages.Message emsg = new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage());    
            ApexPages.addMessage(emsg);
        }        
        
        return pv;
    }
    
    public pageReference saveBudget(){
     
        PageReference pv;
        
        ID OldBudgetID = ExtCon.getID();
        ExtCon.save();
        
        try{
                   
            // Check if it is Save or Clone.
            // If CLone the execute clone line item
           // Then redirect to new budget ID.  
            
            if(OldBudgetID != ExtCon.getID()){
            
                cloneLineItem(ExtCon.getID(), OldBudgetID);
                      
            }                
            else
                saveLineItem(ExtCon.getID());
                
            system.debug('What is the pv returning? '+ pv);
            
        } catch(exception e){
            ApexPages.Message ErrorMsg = new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage());
            ApexPages.addMessage(ErrorMsg);
        }
        
         //pv = ExtCon.view();
        pv = new Pagereference('/'+ExtCon.getID());
        pv.setRedirect(true);
       
        return pv;
    }

 
Hi I have a pageblocktable which displays a row of input fields, which could also consist of text and formula fields. My issue is that, I have a button call Save (quicksave), which saves the displayed record and their child record (rows displayed) without having to refresh the entire page. 

How do I refresh the value or get the value to populate when I click Save? It is calculating all the rollup summery fields but not the formula fields inside the pageblocktable.
 User-added image

The value only shows up if I hit Save and Close (redirects to the actual master record), then hit edit button again. 
<apex:page standardController="Budget__c"  extensions="BudgetController" standardStylesheets="true" >

    <apex:sectionHeader subtitle="{!Budget__c.Name}" title="Budget Form"/>

    <apex:form id="BudgetForm">
        <apex:pageMessages id="messages"/>
        <apex:pageBlock title="Budget Edit" mode="edit" id="BudgetpageBlock">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!quickSaveBudget}" rerender="messages,BudgetForm, LineItem, test" />
                <apex:commandButton value="Save & Close" action="{!saveBudget}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
 <apex:actionRegion immediate="true">                  
                <apex:pageBlockSection title="Budget Line Item" >
                   
                    <apex:pageBlockTable value="{!wrapBudget}" var="wrap" id="LineItem">
                        <apex:column >
                            <apex:commandButton value="Delete" action="{!deleteLineItem}" reRender="LineItem">
                                <apex:param name="wrpIndxParam" value="{!wrap.indx}" assignTo="{!count}"/>
                            </apex:commandbutton>
                        </apex:column>
                        <apex:column headerValue="Trade">
                            <apex:inputField value="{!wrap.budget.Trade__c}"/>
                        </apex:column>
                        <apex:column headerValue="Revenue">
                            <apex:inputField value="{!wrap.budget.Revenue__c}"/>
                        </apex:column>
                        <apex:column headerValue="Allocations">
                        <apex:inputField value="{!wrap.budget.Allocations__c}"/>
                    </apex:column>

</apex:pageBlockTable>
</apex:pageBlockSection>
 </apex:actionRegion>

......................................................................

 </apex:pageBlock>
    </apex:form>
</apex:page>

Here is a snippet of what the visualforce looks like. Please let me know if this can be achievable. 

Thank you. 
Hi friends, 

Once again I'm asking for help because I can't seem to figure out where the bug is. 

I have a contact field on opportunity and when there is an active campaign assigned to that contact, I want to take that id and update the primary campaign source field on opportunity. So that Campaign Influence will populate. 

However, even setting CampaignID on opportunity does not set primary campaign source. 

This is the  AFTER trigger calling the apex class:
else if (Trigger.IsInsert)
            {
    
            	for(Opportunity opp : trigger.new)
            	{
            		OppId.add(opp.id);
            	}
            	
            	CampaignAssignmentToJob.CampaignAssignmentToJob(OppId);
            }
            // otherwise it is update
            else
            {
            	for(Opportunity opp : trigger.new)
            	{
            		OppId.add(opp.id);
            	}
            	
            	CampaignAssignmentToJob.CampaignAssignmentToJob(OppID);
            }

Here's the class: 
public with sharing class CampaignAssignmentToJob {
	
	@future
	public static void CampaignAssignmentToJob (list<ID> Opty)
	{ 
		List<Opportunity> opps = [select id from Opportunity where id IN: Opty];
		
		
		Set<ID> ContactID = new Set<ID>();

		
		for(Opportunity opp: Opps)
		{
			if(opp.Contact__c != null)
			{
				ContactID.add(opp.Contact__c);

			}
		}
		
		System.debug('This is the ContactID:::::::::::::::::::::::::::::::::::::::::::::::::::' + ContactID);
		

		list <CampaignMember> CampMember = new list<CampaignMember>();
		
		if(!ContactID.isempty())
		{
			CampMember = new list<CampaignMember>([Select Id, contactid, CampaignID From CampaignMember where contactid IN: ContactID order by CreatedDate ASC]);
			
		}
		
		map<Id, List<CampaignMember>> cmMap = new map<Id, List<CampaignMember>>();
		
		//map <String, String> CampaignMap = new map<String, String>();
		
		for(CampaignMember member: CampMember)
		{
			List<CampaignMember> workList = cmMap.containsKey(member.ContactId) ? cmMap.get(member.ContactId) : new List<CampaignMember>();
			workList.add(member);
			cmMap.put(member.contactId,workList);

		}
		
		System.debug('This is the CampMember:::::::::::::::::::::::::::::::::::::::::::::::::::' + CampMember);

		list<Opportunity> OppList = new list<Opportunity>();
		
		for(Opportunity opp: Opps)
		{
			if (cmMap.containsKey(opp.contact__c))
			{
				for (CampaignMember cm: cmMap.get(opp.contact__c))
				{
					opp.CampaignID = cm.CampaignID;
					OppList.add(opp);
				}
			}
		}
		

		
		if(!OppList.isEmpty())
		{
			update OppList;	
		}
		
	
	}

}

Is there any other way I can set the primary campaign source?  I'm not getting any error, just the field isn't up dating. 
Hi friends, 

I'm recieving this error message and don't know why it is an invalid field. Can someone please help me? 
//fetch ContactID from opportunity in a set<ID> ContactID

if(!ContactID.isempty())
		{
			CampMember = new list<CampaignMember>([Select Id, CampaignID From CampaignMember where contactid IN: ContactID]);
		}

CampaignMember CM = new CampaignMember();


if(opportunity.contact__c != null)
{
   CM = (CampaignMember)CampMember[0].get(opportunity.contact__c);
}

The last line CM assignment is giving me the error. Why is this an invalid field? 
 
Hi all, 

I'm having trouble writing unit test to cover my Conditional statement. Especially checking the map. 
 
Set<id> office = new set<id>();

for(Opportunity opp: OppMap.values())
		{
			if(opp.Office2__c == null)
			{
				continue;
			}
            else
            {
                OfficeID.add(opp.Office2__c);
            }
		}
I'm having trouble for checking the Office__c == null statement and the setID. 

Also, 
Opportunity opp = OppMap.get(suv.Opportunity__c);
         	if(opp == null)
         	{
         		continue; 
         	}
         	else
            {
            	 //field update from Opportunity to Customer Survey
		         
            	//check if the id is found
                office__c off = offices.get(OppMap.get(suvey.Opportunity__c).Office2__c);

                if(off == null)
                {
                    continue;
                }
                else 
                {
                    //field update from Office__c to Customer Survey. 
                }

My unit test is not going through the conditional statement. 
 
public static TestMethod void TestforNullOFfice()
    {
        Office__c office = addOffice();  
                
        Opportunity opp = AddOpportunity(office);
        
        Customer_Survey__c survey = runTestOnCustomerSurvey(opp);
        
        
        List<Customer_Survey__c> surveys = new List<Customer_Survey__c>();
        surveys.add(survey);
        
       //calls the main class to run the rest. 
        CustomerSurveyFieldUpdate.CustomerSurveyFieldUpdate(surveys);
    }
public static Customer_Survey__c runTestOnCustomerSurvey(opp)
{
        //created the customer survey with opp.
}

public static Opportunity AddOpportunity(office)
{
    Opportunity opp = new opportunity();
    opp.office2__c = office;
    
   insert opp;
   
  return opp;
}

public static Office__c addOffice() 
{
    Office__c office = new Office__c();

    //assigns roles
     office.branch_manager = 'some user.id'; 
    
   insert office;
   
  return office;
}

What exactly am I missing? Please any pointer would help. I'm not sure how exactly go around checking the map. Also, for future reference, is there a way to check the if and else condition to write better unit test, please kindly share your tips. 

Thank you. 



 
Hi all, 

I'm not sure who used process builder yet. But I'm trying to populate a field call branch manager on opportunity if a field Office is populated. The process updates my branch manager and populates it on creation. However, when I close a record and save it, regardless of office was changed or not and regardless of branch manager is populated with previous value or not, process builder does not update the record. 

Is there a way to fix it or does it only work on creation and on edit? 

I spoke to support and they said to use formula critera and add

OR(
ISCHANGED( [Opportunity].Office2__c ),
ISCHANGED( [Opportunity].Division__c ),

AND(
ISNEW(),
OR(
NOT(ISBLANK( [Opportunity].Office2__c )),
NOT(ISBLANK( [Opportunity].Division__c )))
))


I have added those and re-tested. Still does not seem to work. 
Hi I wrote an apex extension class to auto assign the record type looking at a parent record. However I'm getting Null value on assertion. Can someone please help me? I have been wrecking my brain and can't figure it out. 
 
//I'm inserting the parent - testJobObj
insert testJobObj; 
       
       ID jobId = testJobObj.Id;
       //System.currentPageReference().getParameters().put('retURL', jobId);
        
        Work_order__c order = new Work_Order__c(Job_Number__c = testJobObj.id);
       
       insert order;
       
       ApexPages.StandardController sc = new ApexPages.standardController(order);
       WorkOrderRedirectExtension test = new WorkOrderRedirectExtension(sc);
       System.currentPageReference().getParameters().put('retURL','/'+ jobId);
       pageReference pr = test.redirect();

       System.assertEquals(system.currentPageReference().getParameters().get('RecordType'), '012Q00000000kxB' );

    }


}
Then here's my apex extension method: 
 
public PageReference redirect(){
        
        Id parentId = ApexPages.currentPage().getParameters().get('retURL').substring(1,16);
        system.debug('This is the parent Id Im recieving' + parentId);
        String param = '';
		List<job__c> job = [select id, division__c from Job__c where id =: ParentId limit 10];
        for(job__c j: job){
            if(j.Division__c == 'Contents'){
                param = getParameters()+'&RecordType=012Q00000000kxB';
                System.debug('This is the job division' + j.Division__c);
            }
            else if(j.Division__c == 'Structure'){
                param = getParameters()+'&RecordType=012Q00000000l42';
                System.debug('This is the job division' + j.Division__c);
            }
            else
                param = getParameters()+'&RecordType=012Q00000000kxG';
        }
        
        system.debug('RecordType' + param);
        String prefix = Work_Order__c.SObjectType.getDescribe().getKeyPrefix();
        Pagereference page = new PageReference('/'+prefix+'/e?nooverride=1&'+param); 
        Page.setRedirect(true);
        return page;
    }



 
Hi, I have this piece of code running. I'm trying to set the record type of a child object by using condition to look at a field value of parent.

Eg. Job division = content, Recordtype of work order = restoration.
       job division = other, Recordtype of work order = environmenta.

I have this in my pagereference but the parameter does not run correctly. I'm not sure how else should I be defining the parameters. 
 
public PageReference redirect(){
        
        String prefix = Work_Order__c.SObjectType.getDescribe().getKeyPrefix();
        String param = getParameters()+'&RecordType={!IF(Ispickval(Job_Number__c.Division__c,content),012Q00000000kxB,012Q00000000kxG)}';
        return new PageReference('/'+prefix+'/e?nooverride=1&'+param); 
    }

This is the error I'm getting:

Unable to Access Page
The value of the "id" parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information. 

 
Hi folks, 

I have a quick request. How would I go about chaning a record type of a child object depending on what the value of a picklist field on a parent object. 

This should be done by Visualforce page because I'm trying to overwrite the New button on the child object. So that users won't have to sleect the record type. 

Please help, this is a little urgent. 
Hi I have written a trigger to update a field "Approved By" on a custom object. However, due to record locked by Approval process, the trigger had to be before trigger. Is there a way I can fetch the ID of the user who actually approved the process? 

processinstance[0].WorkItems[0].ActorId will return the first or the last userid depending on the index. I cannot figure out how to fetch who is actual approver. 

Also ActorID only returns an ID of a queue if the process assigns it to a queue. Not the userID. How can I get the the user ID.. PLEASEE PLEASEEE HELP!! 

I need to release this code within 2-3 days so I'm in dier need of help right now!
Hi I have written a trigger that will update a field on Account when the child record is created or the first child records (on Account) will get updated. However, my test class is failing on the de-refence a null object and I'm getting 91% coverage. how? 

Error Message:

System.DmlException: Upsert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, NewJobTimeStampOnAccount: execution of AfterInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.NewJobTimeStampOnAccount: line 22, column 1: []

Trigger:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
trigger NewJobTimeStampOnAccount on Job__c (after insert, after update) {

  Map<ID, Account> parentAcct = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();
 
if(trigger.isInsert || trigger.isUpdate){
  for (Job__c childObj : Trigger.new){
    listIds.add(childObj.Account__c);
  }
}
  //Populate the map. Also make sure you select the field you want to update, amount
  //The child relationship is more likely called jobs__r (not job__r) but check
  //You only need to select the child jobs if you are going to do something for example checking whether the job in the trigger is the latest
  parentAcct = new Map<Id, Account>([SELECT id, New_Job_Start_Date__c, (SELECT ID, Date_Time_Taken__c FROM Jobs__r) FROM Account WHERE ID IN :listIds]);
 
  List<Job__c> i = [select id from Job__c where Account__c in :listIds order by Date_Time_Taken__c ASC limit 5];

  for (Job__c job: Trigger.new){
     if(i[0].id == job.id)
     {
        Account myParentAcct = parentAcct.get(job.Account__c);
        myParentAcct.New_Job_Start_Date__c = job.Date_Time_Taken__c;
       
     }
  }
  update parentAcct.values();

}

Test class:

@isTest
private class NewJobTimeStampOnAccount_Test {

    static testmethod void test_trigger(){
     
        Job__c job = new Job__c(Job_Name__c = 'Roy,Semira tes', Date_Time_Taken__c = datetime.now(), contact__c = '003S000000m4qD5', Account__c = '001S000000gq5Dp', Project_manager__c = '00570000002rgiK', name = '6##-##-02206', Stage__c = 'Qualification', Status__c = 'Opportunity', Office__c = 'Chicago', Lead_Source__c = 'Agent', Job_class__c = 'Apartment', County__c = 'Orange', City_of_LA__c = 'No');
      
        upsert job;
      
    }
}