You need to sign in to do that
Don't have an account?
Kerry Proksel
Populate custom lookup field from custom URL button with a visualforce page
I created a custom button on the opportunity that goes to a visualforce page. That visualforce page creates a specifc case type and allows attachments. My goal is to populate the "Opportunity__c" lookup field on the Case with the opportunity Id. I have tried editing the button so the URL is this:
/apex/InfoSecCase?00N0v000002BPBH={!Opportunity.Id}
When clicking the button, I can see the parameter is passed through:
But when I click Save, the field isn't populated. Could someone please help point me in the right direction?
Thank you,
/apex/InfoSecCase?00N0v000002BPBH={!Opportunity.Id}
When clicking the button, I can see the parameter is passed through:
But when I click Save, the field isn't populated. Could someone please help point me in the right direction?
Thank you,
public class CaseAttachment {
public case objcase{get;set;}
public Attachment myAttachment{get;set;}
public string fileName{get;set;}
public Blob fileBody{get;set;}
Opportunity opp;
public CaseAttachment(Apexpages.standardcontroller controller)
{
String optyID = ApexPages.currentPage().getParameters().get('OptyId');
objcase = new case();
objcase.Opportunity__c = optyID;
myAttachment =new Attachment();
}
public pagereference save()
{
insert objcase;
System.debug('@@@@@fileBody'+fileBody);
myAttachment = new Attachment();
Integer i=0;
myAttachment .clear();
myAttachment.Body = fileBody;
myAttachment.Name = fileName;
myAttachment.ParentId = objcase.id;
insert myAttachment;
pagereference pr = new pagereference('/'+objcase.id);
return pr;
}
}
Please change URl as below.
/apex/InfoSecCase?OptyId={!Opportunity.Id}
All Answers
Controller Extension:
Visualforce Page:
I tried to initially do this by adding this to the controller:
But I had issues setting the variable as the Opportunity__c field in the visualforce page.
Thank you!
public class CaseAttachment {
public case objcase{get;set;}
public Attachment myAttachment{get;set;}
public string fileName{get;set;}
public Blob fileBody{get;set;}
Opportunity opp;
public CaseAttachment(Apexpages.standardcontroller controller)
{
String optyID = ApexPages.currentPage().getParameters().get('OptyId');
objcase = new case();
objcase.Opportunity__c = optyID;
myAttachment =new Attachment();
}
public pagereference save()
{
insert objcase;
System.debug('@@@@@fileBody'+fileBody);
myAttachment = new Attachment();
Integer i=0;
myAttachment .clear();
myAttachment.Body = fileBody;
myAttachment.Name = fileName;
myAttachment.ParentId = objcase.id;
insert myAttachment;
pagereference pr = new pagereference('/'+objcase.id);
return pr;
}
}
Please change URl as below.
/apex/InfoSecCase?OptyId={!Opportunity.Id}